Port forwarding

In order to set up port forwarding on IPtables, you can use the following (for forwarding one tcp port to another):

iptables -t nat -A PREROUTING -p tcp --dport [port to forward] -j DNAT --to [destination ip]:[destination port]

For example, to forward from port 26 to port 25 (a fairly common practice) on 192.168.1.37 you'd use:

iptables -t nat -A PREROUTING -p tcp --dport 26 -j DNAT --to 192.168.1.37:25

Note that this rule will be added in the nat table, so won't show up on a standard iptables -L -v, and iptables -F won't clear it (you'll need to use iptables -t nat -L -v / iptables -t nat -F).

Submitted by jkelly on Fri, 2006-08-11 06:55. categories [ | ] login or register to post comments