Published on: April 30, 2009 by George K.
To redirect to external IP and port, issue these three iptables rules. I am giving an example where we had to redirect port 80 of one server’s IP to port 9001 (dotnetpanel port) of another machine. 126.96.36.199 is the IP from which are redirecting the port 80 to the destination IP, 188.8.131.52 and it’s port 9001.
iptables -t nat -A PREROUTING –dst 184.108.40.206 -p tcp –dport 80 -j DNAT –to-destination 220.127.116.11:9001
iptables -t nat -A POSTROUTING -p tcp –dst 18.104.22.168 –dport 9001 -j SNAT –to-source 22.214.171.124
iptables -t nat -A OUTPUT –dst 126.96.36.199 -p tcp –dport 80 -j DNAT –to-destination 188.8.131.52:9001
Isn’t this similar to a tcp based proxy ?
But a simpler solution, but not flexible one, is to use rinetd. Internet redirection server. Refer http://www.boutell.com/rinetd/
Rinetd is very simple and I could achieve what I wanted in less than 3 mins, than making the nat rule work. But it had a limitation which I forgot 🙁
Category : General, Howtos, Linux, Snippets