I have a tricky case:

+---+                      +----+
|D1 +->eth0---------<-eth0-+D2  |
|   |                      |    |
|   +->eth1---------<-eth1-+    |
+---+                      +----+

On D2 eth0 and eth1 have IP addresses from the same subnet: eth0, eth1 Interfaces on D1 don't have addresses assigned and it acts like a switch.

Now, I want D2 to be able send the traffic to via eth0, so the packet path has to be: D2(eth0)--D1(eth0)--D1(eth1)--D2(eth1).

At the moment when I ping from D2 it sends packets locally, i.e. D1 doesn't get any. What should I change on D2 to achieve the desired behaviour?


  • So you're wanting it to basically go between the two NIC's? Then you need to set up round robin bonding. – Bratchley Jan 8 '15 at 20:09
  • @Bratchley I am not familiar with bonding but it makes (in this case) two physical interfaces one logical interface, doesn't it? I think you should explain that in more detail. – Hauke Laging Jan 8 '15 at 20:31
  • I think I may have misunderstood the question now that I re-read it. – Bratchley Jan 8 '15 at 20:32
  • @Bratchley, no I don't need bonding. Basically I want to "trick" the IP stack on D2, and have it send traffic with destination of eth1 interface (on D2) via eth0. – Mark Jan 8 '15 at 20:46
  • 1
    Not sure if this helps, but this read similar: unix.stackexchange.com/a/275888/130303 – Jakob Lenfers Apr 16 '16 at 9:41

What you want is not possible with Linux. At least not within the routing layer. If a target address belongs to a local interface then the packet always goes through the loopback interface from where it cannot (by RfC) routed to the outside.

I thought it might be possible to use iptables and DNAT to change the target to an unused address in the subnet and use ip neigh to set the MAC address statically to the one of the other NIC but not even the DNAT rule is matched for packets to local addresses.

It may be possible with a virtual machine or with network namespaces so that the kernel does not see on eth0. But you would need proxy ARP and DNAT for moving the incoming packets from the physical to the virtual interface.

If it's worth that effort?

  • thanks for response. It looks it is not worth the efforts spent :) I'd better off find another machine, since all I need is to test throughput of D1 packet forwarding, so I can run netserver and netperf on physically different hosts. – Mark Jan 8 '15 at 21:38

Network namespaces may be an option. They are essentially independent instances of the network stack so they should at least in theory be able to separate two interfaces.

Last time I tried playing with them though I couldn't get thing to work properly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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