Tag Archives: networking

Getting traffic for some networks out of one interface and all other traffic out of another

In this config (I’m using ubuntu 10.04), there are two NICs; eth0 (ip 10.100.160.6) and eth1 (ip 10.120.160.6).  Traffic for the networks 10.100.0.0/16, 10.9.0.0/16 and 192.168.150.0/24 is routed out of eth0, and all other traffic is routed out of eth1.

File: /etc/network/interfaces

## config for eth0
auto eth0
iface eth0 inet static
address 10.100.160.6
netmask 255.255.0.0
network 10.100.0.0
broadcast 10.100.255.255
# routes
post-up route add -net 10.9.0.0 netmask 255.255.0.0 gw 10.100.220.1 dev eth0
post-up route add -net 192.168.150.0 netmask 255.255.255.0 gw 10.100.220.1 dev eth0
post-up route add -net 10.100.0.0 netmask 255.255.0.0 gw 10.100.220.1 dev eth0
pre-down route del -net 10.9.0.0 netmask 255.255.0.0 gw 10.100.220.1 dev eth0
pre-down route del -net 192.168.150.0 netmask 255.255.255.0 gw 10.100.220.1 dev eth0
pre-down route del -net 10.100.0.0 netmask 255.255.0.0 gw 10.100.220.1 dev eth0

# config for eth1
auto eth1
iface eth1 inet static
address 10.120.160.6
gateway 10.120.220.1
netmask 255.255.0.0
network 10.120.0.0
broadcast 10.120.255.255

Then restart the machine (just doing /etc/init.d/networking restart didn’t work for me) and check the routing table using “route”.