I want to forward port 2222 on an Ubuntu 12.04 server to remote host 184.108.40.206 port 22, using iptables.
After reading many web pages on port-forwarding, I issue
$ sysctl net.ipv4.conf.eth0.forwarding net.ipv4.conf.eth0.forwarding = 1 $ sudo iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 2222 -j DNAT --to-destination 220.127.116.11:22
Which forwards traffic as I desired. But ssh does not work. Turns out I needed to also supply
$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
And now it's good. I understand the above commands; what I don't understand is the plethora of sites giving the first command and none giving the second. Under what conditions would the first command suffice?
Note: Example site giving only the DNAT commmand.