Ubuntu Server cannot add permanent static route

by Tommy   Last Updated April 26, 2018 16:02 PM

I'm running Ubuntu Server 16.04.4
After a lot of struggling I managed to configure both ethernet and wireless connections.

The content of /etc/network/interfaces file is this:

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# Ethernet network interface
allow-hotplug enp9s0
iface enp9s0 inet static
    address 192.168.1.150
    netmask 255.255.255.0
    gateway 192.168.1.1

# Wireless network interface
allow-hotplug wlp5s0b1
iface wlp5s0b1 inet static
    address 192.168.1.151
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

up route add default gw 192.168.1.1 dev wlp5s0b1

and in /etc/wpa_supplicant/wpa_supplicant.conf there is the output of:

wpa_passphrase "MY SSID" MY_PASSWORD | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf

which is:

network={
    ssid="MY SSID"
    #psk="MY_PASSWORD_IN_CLEAR"
    psk=LONG_HEX_STRING
}

Now, ifconfig shows that:

enp9s0    Link encap:Ethernet  IndirizzoHW 00:24:54:ad:ac:b4  
          indirizzo inet:192.168.1.150  Bcast:192.168.1.255  Maschera:255.255.255.0
          indirizzo inet6: fe80::224:54ff:fead:acb4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:435 errors:0 dropped:0 overruns:0 frame:0
          TX packets:195 errors:0 dropped:0 overruns:0 carrier:0
          collisioni:0 txqueuelen:1000 
          Byte RX:54426 (54.4 KB)  Byte TX:26620 (26.6 KB)
          Interrupt:18 

lo        Link encap:Loopback locale  
          indirizzo inet:127.0.0.1  Maschera:255.0.0.0
          indirizzo inet6: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:14256 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14256 errors:0 dropped:0 overruns:0 carrier:0
          collisioni:0 txqueuelen:1 
          Byte RX:1055216 (1.0 MB)  Byte TX:1055216 (1.0 MB)

wlp5s0b1  Link encap:Ethernet  IndirizzoHW 00:1b:b1:48:12:86  
          indirizzo inet:192.168.1.151  Bcast:192.168.1.255  Maschera:255.255.255.0
          indirizzo inet6: fe80::21b:b1ff:fe48:1286/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:695 errors:0 dropped:0 overruns:0 frame:0
          TX packets:30 errors:0 dropped:0 overruns:0 carrier:0
          collisioni:0 txqueuelen:1000 
          Byte RX:125974 (125.9 KB)  Byte TX:3316 (3.3 KB)

and the routing table is this:

[email protected]:~$ route -n
Tabella di routing IP del kernel
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 enp9s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 enp9s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlp5s0b1

If I ping with the ethernet cable connected, all works good.
But if I remove the ethernet cable and ping 8.8.8.8 it's not working.

Now my guess is that in the routing table is missing a line like this:

0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 wlp5s0b1

In fact, if I run:

sudo route add default gw 192.168.1.1 wlp5s0b1

then the routing table is:

[email protected]:~$ route -n
Tabella di routing IP del kernel
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 wlp5s0b1
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 enp9s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 enp9s0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 wlp5s0b1

and ping 8.8.8.8 without the ethernet cable work just fine.

So my question is this: is there a way of keep permanent the route that I added?

I've already tried to write the command in the last line of the /etc/network/interfaces file, as you can see above, in many different ways:

  • up route add default gw 192.168.1.1
  • up route add default gw 192.168.1.1 wlp5s0b1
  • up route add default gw 192.168.1.1 dev wlp5s0b1
  • as above but with up ip route ...
  • as above but with post-up instead of up

but it's not working.
Am I missing the correct syntax or is there any other solution?
Thanks for your help!



Related Questions


Ubuntu Server Wifi and Ethernet

Updated April 17, 2017 10:02 AM



Ubuntu 17.04 Server not found (just installed)

Updated August 29, 2017 19:02 PM