Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to do a simple redirect with IP tables. Basically what I want to do is make it so when I try to wget or curl something from the IP address of 192.100.1.105:80 it will redirect me to 192.100.1.64:8080.

We recently switched around the IP address in our infrastructure so that they are all sequential but some of our server admins are having trouble remembering to type the new IP.

share|improve this question
2  
DNS is the way forward. –  Iain May 15 '11 at 23:07
add comment

1 Answer

up vote 0 down vote accepted

As Iain points out this looks like a job for DNS.

The iptables solution will probably be something like this, if you want to stick to it:

iptables -t nat -I PREROUTING -d 192.100.1.105 -p tcp --dport 80 -j DNAT --to 192.100.1.64:8080
iptables -t nat -I POSTROUTING -d 192.100.1.64 -j SNAT --to 192.100.1.105

The first rule does the actual redirect, the second one masks the source IP address so 192.100.1.64 returns the packets to 192.168.1.105 and the connection thus actually works. Do note that all packets will go through 192.168.1.105 at all times - it's a low level (TCP) redirect.

A nicer way to do this would be to set up a web server on 192.100.1.105 to force an HTTP redirect to 192.100.1.64:8080. This is probably much better because it doesn't mask the redirect and the users may become (probably slowly) aware of it. Also, you only have to process the initial connection on 192.100.1.105 - the rest goes directly to 192.100.1.64.

About the IPs - you aren't using 192.100.1.0/24 as a private network, right? It isn't private.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.