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
I tried the ip route ... table local method above. Either it doesn't work or I am doing something wrong.
The trick is to use a set of dummy IP addresses to force the kernel into routing it through the wire, and NAT to change it back to the real IP address.
Let eth0 and eth1 be the two ethernet cards; IP0 and IP1 its IP address; MAC0 and MAC1 its MAC address respectively. We will be using two dummy IP addresses: IP00 and IP11.
Use the dummy IP addresses IP00 and IP11 instead of the real one.
You should be able to write a program that does that using packet sockets (protocol family
PF_PACKET
), but you'll have to handle the headers for the IP and higher layers yourself.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.