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 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 1.1.1.1 but linux gateway change it to 2.2.2.2 So if I'm expecting the web page of 1.1.1.1, I'll get the changed one, the one of 2.2.2.2 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
add comment

2 Answers 2

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 Host:facebook.com. 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
add comment

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.

    iptables -t nat -A POSTROUTING -o $OUTGOING_INTERFACE -j SNAT --to $OUTGOING_IP_ADDRESS_OF_ROUTER
    
  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
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.