Blog

How do I redirect a given port on a given IP address to a different port on a different host or network

Tags: iptablesnatredirection

Published on: April 30, 2009 by George K.

How do I redirect a given port on a given IP address to a different port on a different host or network

Scenario:

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. 64.192.34.215 is the IP from which are redirecting the port 80 to the destination IP, 208.24.210.233 and it’s port 9001.

iptables -t nat -A PREROUTING –dst 64.192.34.215 -p tcp –dport 80  -j DNAT –to-destination 208.24.210.233:9001
iptables -t nat -A POSTROUTING -p tcp –dst 208.24.210.233 –dport 9001 -j SNAT  –to-source 64.192.34.215
iptables -t nat -A OUTPUT –dst 64.192.34.215 -p tcp –dport 80 -j DNAT –to-destination 208.24.210.233: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

George K.

George K.

George started his career in web hosting and Linux technical support in the year 2004 and is with SupportSages since 2009. He has keen interest in server optimizations, custom security solutions, hacked server recovery, cyber forensic and high availability fail over system design and implementation. George loves long drives and is passionate about art and literature.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Categories

Your Cart

Cart is empty.

Subtotal
₹0.00
APPLY
0
Send this to a friend