4

I have a dual port ethernet NIC and let's say I have connected 2 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 port to another 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 finding 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?

elleciel
  • 2,297
  • 3
  • 17
  • 19
  • 4
    The files you're referring to are part of Linux kernel source tree. See https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel for tips on how to obtain the Ubuntu patched sources and so on. –  Mar 29 '14 at 07:11
  • Maybe you should check for ip forwarding parameter and disable it? Check `sysctl -a | grep forward` output. – Alexander Dzyoba Mar 31 '14 at 08:41

2 Answers2

5

You can use network namespaces for this purpose.

As ip-netns's manpage says:

A network namespace is logically another copy of the network stack,
with its own routes, firewall rules, and network devices.

Following is just a copy of this 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
Roman Kovtuh
  • 561
  • 8
  • 14
1

you can try configuring route table, by running "ip" command:

ip route add to unicast 192.168.3.1 dev eth2
ip route add to unicast 192.168.2.1 dev eth3

new route would be added into route table, and it should be able to take effect before egress routing lookup hit the host-local route between "192.168.3.1" and "192.168.2.1", therefore, the traffic should be sent through physical interface "eth2" and "eth3", instead of loopback "lo"

Never tried myself, but should work.

xzhao28
  • 406
  • 2
  • 3