Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a linux machine used as gateway for a Win XP machine. Both are in Virtual machine for testing purpose. Now I want to trick the Win XP user (me) with the forwarding of an IP address: I want to change the destination IP address.

For example I want to go to but linux gateway change it to So if I'm expecting the web page of, I'll get the changed one, the one of For example I want to go to Facebook and I'm forced to Google home page.

How can I do it? With prerouting? Because I've done lot of tries, but no one working :(

share|improve this question

That is not going to reliably work with iptables alone, because HTTP requests send along a Host: header. And it is unlikely that Google would know how to serve a page for Install a proper proxy software, such as squid.

share|improve this answer
And if I don't do http traffic, but other kind of traffic? – Possa Apr 28 '11 at 12:32

Basically, what you must do is:

  1. Configure the Linux box to act as a router

  2. Change the Default Gateway of the Windows box to point to the IP of the Linux box

  3. Do a DNAT, e.g. :

    iptables -t nat -A PREROUTING -i $INCOMING_INTERFACE -d $DEST_IP -j DNAT --to $NEW_DEST_IP
  4. Also do a SNAT, e.g.

  5. Make sure that no iptables rule/policy drops your traffic

share|improve this answer
It doesn't work for me :( The prerouting appearently goes well, but the postrouting doesn't work. I did a tcpdump and the linux gateway convert the DEST_IP to NEW_DEST_IP, but when NEW_DEST_IP send the packet back, the XP system send a Reset packet. – Possa May 2 '11 at 15:01
@Possa did the Source Address of the packet gets converted from the original XP's address to the Linux box's address? – pepoluan May 3 '11 at 2:46

Your Answer


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.