Strange routing issue, solvedStrange routing issue, solved

September 29, 2010

I just encountered this problem: I have an Ubuntu box, on which ran this downloading service. Because some complaints from the Internet provider, I decided to use another network (from another provider) for this downloading service. Everything else needed to remain the same.

So I installed a new network card on the system, and it became eth1. The first one, eth0, was connected to network Now, I connected eth1 to network Both networks provides DHCP.

The first issue was when I configured both NICs with DHCP. No outside access was available on the box because there were two default gateways. So I configured eth1 as static, and didn’t specify any default gateway for it. But this rendered the internet connection through eth1 useless, because all the traffic (for the outside world) was routed through eth0 now. So when the downloading service was bound to eth1, it couldn’t connect anywhere outside the network.

After some searching effort on the Internet, I found this solution:


# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

# The secondary network interface
auto eth1
iface eth1 inet static

up /etc/network/



#Set up the first subnet's routing table (we'll name it 70)
ip route flush table 70
ip route add table 70 to dev eth0
ip route add table 70 to default via dev eth0

#Set up the second subnet's routing table (we'll call it 80)
ip route flush table 80
ip route add table 80 to dev eth1
ip route add table 80 to default via dev eth1

#Create the rules to choose what table to use. Choose based on source IP
#We need to give the rules different priorities; for convenience name priority
#after the table
ip rule add from table 70 priority 70
ip rule add from table 80 priority 80

#Flush the cache to make effective
ip route flush cache

So now all the traffic goes by default through eth0, but all applications bound to eth1 are routed through the correct gateway of network.

I found this hack here:

Hope this helps anybody.

Be Sociable, Share!

Leave a Reply