Creating Routes using the second NIC in the box

Posted by Aditya Sehgal on Server Fault See other posts from Server Fault or by Aditya Sehgal
Published on 2010-05-26T10:30:41Z Indexed on 2010/05/26 10:41 UTC
Read the original article Hit count: 309

Filed under:
|
|
|
|

OS: Linux

I need some advice on how to set up the routing table. I have a box with two physical NIC cards eth0 & eth1 with two associated IPs IP1 & IP2 (both of the same subnet). I need to setup a route which will force all messages from IP1 towards IP3 (of the same subnet) to go via IP2. I have a raw socket capture program listening on IP2 (This is not for malicious use).

I have set up the routing table as

Destination  Gateway       Genmask        Flags  Metric  Ref  Use  Iface   
   IP3         IP2      255.255.255.255    UGH    0       0    0    eth1

If I try to specify eth0 while adding the above rule, I get an error "SIOCADDRT: Network is unreachable". I understand from the manpage of route that if the GW specified is a local interface, then that would be use as the outgoing interface.

After setting up this rule, if i do a traceroute (-i eth0), the packet goes first to the default gateway and then to IP3.

How do I force the packet originating from eth0 towards IP3 to first come to IP2. I cannot make changes to the routing table of the gateway.

Please suggest.

© Server Fault or respective owner

Related posts about linux

Related posts about iptables