Redirecting port traffic to another IP

This is helpful for those who are having problems directly connecting to an ip due to local network restrictions or simply need to temporarily redirect services.

on the server that you can reach, you want to redirect the incoming traffic to another ip. in my case I wanted to redirect back to itself.


sudo iptables -t nat -A PREROUTING -s 10.0.0.1 -p tcp --dport 22 -j DNAT --to-destination 10.0.0.1:22
sudo iptables -t nat -A POSTROUTING -j MASQUERADE

view the changes


sudo iptables -t nat -L