linux: disable using loopback and send data via wire between 2 eth cards of one comp

osgx picture osgx · Apr 29, 2010 · Viewed 17.6k times · Source

I have a comp with 2 eth cards, connected with patch-cord (direct eth. cable from 1st to 2nd).

The linux is installed, I want to send data from 1st network card to 2nd. And I want to force the packet to pass via cable. I can set up any ip on cards.

With ping I get counters on cards constant.

Is it possible with tcp/ip sockets?

PS. I need to write a program. which will send packets via eth, so stackoverflow-related question. There can be some OS-dependent way, they will help me too

Answer

PoltoS picture PoltoS · Dec 20, 2010

Have a look in local routing table. With iproute2 tools installed do ip route show table local. As you can see, all packets destinated to your local IPs would never go thru NICs since they are marked as local.

To force packets go via ethernet card remove the appropriate route (i.e. ip route delete 192.168.122.1 dev eth0 table local). To restore this route just set the interface down and up: the kernel would do the work to insert these routes.