I have a machine with several interfaces that I can configure as I want, for instance:
- eth1: 192.168.1.1
- eth2: 192.168.2.2
I would like to forward all the traffic sent to one of these local addresses through the other interface. For instance, all requests to an iperf, ftp, http server at 192.168.1.1 should be not just routed internally, but forwarded through eth2 (and the external network will take care of re-routing the packet to eth1).
I tried and looked at several commands, like iptables, ip route, etc… but nothing worked.
The closest behavior I could get was done with:
ip route change to 192.168.1.1/24 dev eth2
which send all 192.168.1.x on eth2, except for 192.168.1.1 which is still routed internally.
May be I could then do NAT forwarding of all traffic directed to fake 192.168.1.2 on eth1, rerouted to 192.168.1.1 internally? I am actually struggling with iptables, but it is too tough for me.
The goal of this setup is to do interface driver testing without using two PCs.
I am using Linux, but if you know how to do that with Windows, I'll buy it!
Edit:
The external network is just a crossover cable between eth1 and eth2.
Let's say I have an http server on my machine.
Now I want to access this server from the same machine, but I want to force the TCP/IP traffic to go through this eth1/eth2 cable. How should I configure my interfaces for this?
Best Answer
I expanded on caladona's answer since I could not see response packets. For this example:
Local PC iptable routes are set to SNAT and DNAT outgoing traffic to the 'fake' IP.
The rules do the following:
To summarize, the local system now can talk to a 'virtual' machine with addresses 192.168.1.100 and 192.168.2.100.
Next you have to force your local PC to use the external router to reach your fake IP. You do this by creating a direct route to the IP's through via the router. You want to make sure that you force the packets onto the opposite of the destination subnet.
Finally to make this all work, the external router needs to know how to reach the faked IPs on your local PC. You can do thins by turning on proxy ARPs on for your system.
With this setup, you can now treat the fake IPs as a real system on your local PC. Sending data to .1 subnet will force packets out the .2 interface. Sending data to the .2 subnet will force packets out the .1 interface.