This example shows you how to create a port forward with iptables.
It is basically three iptables rules.

/sbin/iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE
/sbin/iptables -A PREROUTING -t nat -p tcp -i eth0 -s 1.1.1.1 -d 2.2.2.2 --dport 2222 -j DNAT --to 3.3.3.3:22
/sbin/iptables -A FORWARD -p tcp -i eth0 -s 1.1.1.1 -d 3.3.3.3 --dport 22 -j ACCEPT

Now when you connect from 1.1.1.1 to 2.2.2.2:2222 with ssh, your connection will be forwarded to 3.3.3.3:22.

Advertisements