How to set what route would be added when bringing interface up

networkingroute

I have one two interfaces on one machine, one is the Internet connection that get its IP from a DHCP, no problem.

The other interface (eth1) is to local machines, and it has the gateway 192.168.3.1 is set in its configuration file (Ubuntu based distro).

The problem is, that when i am bring the eth1 interface up, it automatically add a default (0.0.0.0) route to the route table (as it should do), and i can't connect to the Internet, since it try to send the packets to the local network.
Until now i have had to do it manually by deleting the default route with the 192.168.3.1 gateway.

Is there a way to set that it wouldn't add a default route once i bring up the interface ? I am still need the gateway 192.168.3.1 to stay in the configuration file since i have to have some specific route to the 3.x network.

Here is my route table:

192.168.3.0     *               255.255.255.0   U     0      0        0 eth1
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
default         192.168.3.1     0.0.0.0         UG    100    0        0 eth1
default         DD-WRT          0.0.0.0         UG    100    0        0 eth0

Best Answer

Don't declare 192.168.3.1 as a gateway. Gateway pretty much means “default route”. If the address of the interface is within the 192.168.3.1/24 network, then netmask 255.255.255.0 is all you need.

If that's not the case, add whatever route you need as part of the interface setup script. On Debian/Ubuntu, put an up clause in /etc/network/interfaces, or add a script in /etc/network/if-up.d. The command to run is route add 192.168.3.1 eth1 && route add -net 192.168.3.0/24 gw 192.168.3.1

Related Question