Creating Routes using the second NIC in the box
- by Aditya Sehgal
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.