Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
Kyle, the link looks interesting. Thanks for that. – Aditya Sehgal May 26 '10 at 11:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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