Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Port forwarding based on iptables

Shulou Source: shulou.com Published: 2022-06-01 04:00:06 10月06日 Update

We all know that port forwarding can be realized with iptables under the linux server. Please take a look at the example below.

Iptables-t nat-I PREROUTING-d 10.12.34.56-p tcp-- dport 90-j DNAT-- to-destination 10.12.34.56purl 8080

In this way, port 90 that accesses the 10.12.34.56 server will be forwarded to port 8080.

Matters needing attention

You may need to turn on IP forwarding with the following command:

# echo 1 > / proc/sys/net/ipv4/ip_forward

During the experiment, if you want to reset the iptables, you need to clear the nat table first:

# iptables-F-t nat

Tags: Port server service item function command instance notice please see experiment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno MySQL Huawei Xiaomi