Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a linux system with two network interfaces (eth0 in x.x.x.0 and eth1 in x.x.y.0). Is there any posibility to add some route policy to send all the traffic to network x.x.y.0. I would like even the traffic from eth0 to be send to eth1's network.

I cannot delete the direct connected networks from the routing table so all the traffic from x.x.x.0 network is send to eth0. I would like to send all traffic to eth1.

share|improve this question
Your question seems to be based on some kind of misunderstanding. What do you think it means to send traffic to a network? If a packet is destined to x.x.x.5, what would it even mean to send that traffic to the x.x.y.0 network? Networks are used to reach hosts. –  David Schwartz Sep 18 '12 at 20:23
When I said to send traffic to a network, I mean to send traffic to any host that belongs to that network. If a packet is destined to x.x.x.5 I would like to send this packet through eth1(that belongs to x.x.y.0). The network x.x.x.0 can be reached from x.x.y.0. I want to use the network from eth1 because it's faster. –  Dragos Sep 18 '12 at 20:30
In other words I would like to send all the traffic to a default gateway even if it could be send to an direct connected link. –  Dragos Sep 18 '12 at 20:49
Then what purpose is the other interface supposed to serve? Is it for inbound traffic only? –  David Schwartz Sep 18 '12 at 21:00
Yes inbound traffic. Maybe there are some hosts which will send on this interface. –  Dragos Sep 18 '12 at 21:02

1 Answer 1

You need to set up an alternate routing table that only contains your default route, mark packets that you want to go out your default route, and then divert marked packets to the alternate routing table.

1) Create an alternate routing table:

 echo '1     DEFGW' >> /etc/iproute2/rt_tables
 ip route add default via dev eth1 table DEFGW

This creates an routing tabled called DEFGW which contains only a default route. Adjust the IP and interface as appropriate for your configuration.

2) Arrange for marked packets to take the alternate table:

ip rule add fwmark 1 table DEFGW

3) Mark packets that should be subject to our rule.

iptables -t mangle -A PREROUTING -d x.x.x.0/ -j MARK --set-mark 1

This takes packets bound for x.x.x.0/24 addresses and puts mark 1 on them, the mark that diverts them to the DEFGW table. Adjust the IP as appropriate for your configuration. We mark the packets before routing them so that the routing engine will know to use the alternate table.

share|improve this answer

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.