the networking features in Linux are really amazing , in this post I want to show you how you can setup a general IP proxy on a specific port.
in order to write the required script open a new file named proxy :
copy and paste the following script into the file :
YourIP=X.X.X.X TargetIP=Y.Y.Y.Y Port=Z iptables -t nat -A PREROUTING -p tcp --dport $Port -d $YourIP -j DNAT --to $TargetIP iptables -t nat -A POSTROUTING -p tcp --dport $Port -d $TargetIP -j SNAT --to $YourIP
Change X.X.X.X to your nic IP.
Change Y.Y.Y.Y to target IP.
and Change Z to the port which needs to be proxied.
save and close the file.
make it executable and run it :
chmod +x proxy ./proxy
enable IPv4 forwarding in sysctl.conf :
and make sure you have the following line uncommented :
and apply the changes :
now we are all set 🙂