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    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.


If I understand you correctly you need policy based routing, particularly, source based routing. Here is a simple howto to do just that.

The idea is that traditional routing makes its routing choice by looking at the destination address field in the IP header and comparing it to its routing table. Policy based routing can look at other fields, or even other items such as TCP ports. In the case of source based routing, it looks at the source address field in the IP header.

  • Kyle, the link looks interesting. Thanks for that. – Aditya Sehgal May 26 '10 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.