Use specific interface for outbound connections (Ubuntu 9.04)

You should only have one default gateway. If you remove the gateway line from eth1, it'll all just work (after networking is restarted).


Remove gateway from eth1 in /etc/network/interfaces and add it as a static route:

route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1

With this, 10.0.0.1 will be your default gateway and eth1 will be used only to connect to 192.168.2.0 network


Modifing the routing table with route as suggested will fix this temporarily, but it will revert to it's current state on the next boot.

It would be possible to set route rules in /etc/rc.local or some kind of other init script, but in this case the simplest option is just to remove the gateway from eth1 in the interfaces file.

By removing that gateway that system will still automatically use eth1 as the route 192.168.2/24, but will route all other traffic through eth0.