views:

289

answers:

3

I would like to send data between two ethernet interfaces that are connected with a crossover cable in Linux. The two ethernet interfaces are on the same box. I defined the ethernet interfaces to have different static ip addresses (1.2.3.4 and 5.6.7.8) and have been using sockets to send bytes from one IP address to the other. I want to emphasize that I want the data to leave the box one interface of the box and get received on the other interface of the same box. One consequence of this is that unplugging the cable would prevent communication between the client and server on the same box.

The kernel is smarter than me I guess and decides it doesn't need to send information out on the wire and routes the data directly between the sockets internally, thus negating the test. I have tried to use SO_BINDTODEVICE to force the client to send data out of a particular interface, but the server never sees it. I am really stuck and this doesn't seem like it should be this difficult.

There are two entries in the route -n table

Dest       Gateway    Genmask        flags  metric  use  interface
1.2.3.0    0.0.0.0    255.255.255.0    U       0     0   eth0
5.6.7.0    0.0.0.0    255.255.255.0    U       0     0   eth1
A: 

Do you use the same netmask on this interfaces? Check routing table(route -n) for conflicts with another network interfaces

shuvalov
yes I am using the same netmask. Edited the question with the route -n output.
messenger
+1  A: 

Try using the following two IP addresses:

  • 192.168.64.1
  • 192.168.64.2

I'm not sure this is the problem, but 1.2.3.4 and 5.6.7.8 aren't on the same subnet. (Because when you apply the mask to each one, you don't get the same network address, as the Dest column is showing you.)

Jon-Eric
Tried using those IP addresses and there was no change.
messenger
+1  A: 

You can not communicate using IP between 1.2.3.4/24 to 5.6.7.8/24 without going though a router. The problem is that IP can only talk to other computers in the same network segment. To calulate the network address you need to do a logic AND between both the interface address and the subnet mask. This will give you the network addresses. If the two network addresses are different then a router will be required. In your example you will have network address 1.2.3.0 and 5.6.7.0. Because these are different it will will to send data.

More importantly most network stacks are smart enough to see that if both interfaces are on the same computer it will not send the data all the way to the phyical interface. It will probably only send the message though the IP stack. But again it would need to be vaild address for it to work.

You should even be able to test a similar setup using just loopback network devices. (virtual network cards.)

Matthew Whited
The point is that I want the data to go out on the physical interface
messenger
Again... the IP stack on the computer may not send data between the physical interfaces. It should resolve internally that it has both address on it's own system and not even get the IP Packet to the network interface cards.
Matthew Whited
Learn about the OSI model http://en.wikipedia.org/wiki/OSI_model
Matthew Whited
IP Stack ... http://en.wikipedia.org/wiki/TCP/IP_stack
Matthew Whited
And TCP/IP ... http://en.wikipedia.org/wiki/TCP/IP_model
Matthew Whited
I am accepting this as I am pretty well convinced that you can't make a box go through the physical interface without changing some fundamental pieces of the system. Guess I just didn't realize how standardized this OSI model stuff is :)
messenger