Send traffic to self over physical network on Ubuntu

ethernetipnat;networkingrouting

I have a dual port ethernet NIC and let's say I have connected both ports in a loop and assigned the following IPs to the 2 ethernet interfaces:

  • eth2 -> 192.168.2.1
  • eth3 -> 192.168.3.1

I want to send traffic from 1 of the ports to the other over the physical network, e.g. ping 192.168.3.1 from 192.168.2.1. However, the TCP/IP stack in the Linux kernel recognizes that these two addresses are local and instead sends the traffic to the loopback adapter, so the traffic never hits the physical network.

The closest I have to a solution is Anastasov's send-to-self patch, which unfortunately, has been discontinued since kernel 3.6 so it won't work on Ubuntu 13.10 (kernel 3.11) for me. I've tried rewriting the patch for 3.11, but I can't seem to locate these in the Ubuntu distro:

  • include/linux/inetdevice.h
  • net/ipv4/devinet.c
  • net/ipv4/fib_frontend.c
  • net/ipv4/route.c
  • Documentation/networking/ip-sysctl.txt

Is there a way I can get the send-to-self patch to work, or an alternative solution?

Best Answer

Create a network namespace and move one of interfaces into it:

ip netns add test
ip link set eth1 netns test

Start a shell in the new namespace:

ip netns exec test bash

Then proceed as if you had two machines. When finished exit the shell and delete the namespace:

ip netns del test
Related Question