Network Manager breaks manual routes

I have Ubuntu 13.10, Saucy Salamander x64 running as a guest in VirtualBox (with Windows 7 as a host).

I wrote this /etc/network/interfaces because I need to add a large number of permanent, manual static routes:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet dhcp
    up ip -force -b /etc/network/eth1-routes

eth1-routes contains several lines of the form:

route add 10.0.0.0/8 via 172.x.x.x dev eth1

where 172.x.x.x is the gateway that VBox NAT gives me.

By running netstat -nr it appears that all of my manual routes have been successfully added, including routes to get to two DNS servers via 172.x.x.x.

However, network manager says that both devices are "not managed". If I set /etc/NetworkManager/NetworkManager.conf managed=true, network manager works again but my routes are lost. So my current compromise is to set managed=false and comment out the eth0 lines in /etc/network/interfaces.

Is there a way to have a device be managed and still do manual routes as above?


Solution 1:

Network Manager manages its own static routes - open network manager and select "wired connection 1". Select edit. select IPv4 tab. At the bottom of this page is a button for "Routes". That is where you add them. When done NM writes to a file with root permissions in its /etc/NetworkManager/system-connections/ directory called "Wired connection 1"

Example follows

ls -l /etc/NetworkManager/system-connections/
total 4.0K
-rw------- 1 root root 216 Aug 26 10:38 Wired connection 1

sudo cat /etc/NetworkManager/system-connections/Wired\ connection\ 1

[802-3-ethernet]
mac-address=A:Real:Mac:Add:re:ss

[connection]
id=Wired connection 1
uuid=df4491fc-0981-4071-82ae-04c7b2d6d9fc
type=802-3-ethernet

[ipv6]
method=auto

[ipv4]
method=auto
route1=10.2.2.0/24,10.1.1.68,1

Where 10.2.2.0 is the destination network and 10.1.1.68 is the gateway.

Solution 2:

Network Manager does not recognize the statements you wrote in /etc/network/interfaces.

So your can add your script eth1-routes as a dispatcher script for Network Manager in /etc/network/if-up.d/. It will be run every time an interface goes up. Maybe you have to write in your script an "if clause" to only add the routes if eth1 comes up. Like this:

if [ "$IFACE" == "eth1" ]; then
  route add ...
  route add ...
fi

Solution 3:

If you want to add a route to Ubuntu that persists reboot and does not use the default interface as the gateway then you may want to add a route statement to the NetworkManager configuration file for the specific interface.

Add a route to the /etc/NetworkManager/system-connections/"connection name" configuration file by adding the route statement to the configuration file for (assuming IPv4). The route has four parts; "the first being the destination IPv4 network or address (network byte order), the second the destination network or address prefix (1 - 32), the third being the next-hop (network byte order) if any, and the fourth being the route metric".

[ipv4]
method=auto
route1=172.16.0.0/16,192.168.3.1,1

This is the equivalent of setting the route using the following route statement:

route add -net 172.16.0.0 netmask 255.255.0.0 gw 192.168.3.1

The route keyname is defined in Table 12 in the NetmorkManager developer documentation. Please see the following URL for more information: https://developer.gnome.org/NetworkManager/0.9/ref-settings.html