How to set default route to wlan0 for Internet access while automounting a NAS storage via eth0 over a network switch?

I have a NAS with a static IP address and Ubuntu machine also with a static IP address over eth0. They are connected to a network switch via Ethernet, and the network switch is not connected to a router (does not have Internet acccess).

Here is /etc/network/interfaces on the Ubuntu machine:

auto eth0
iface eth0 inet static
address 192.168.11.100
netmask 255.255.255.0
gateway 192.168.11.1

/etc/default/networking has CONFIGURE_INTERFACES set to 'no'.

And I have the following row in /etc/fstab for mounting the NAS device to /mnt/lspro:

//192.168.11.150/shared /mnt/lspro    cifs   username=admin,password=pass,uid=1000    0 0

On startup, this doesn't mount. I need to mount -a manually (looking for suggestions to solve this as well).

So this is mostly fine. Now, I use nmcli to connect over wlan0 to a network for Internet access. I'm able to successfully connect to the network, but when I ping 8.8.8.8 it defaults to eth0. And route -n confirms this:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 eth0
0.0.0.0         192.168.86.1    0.0.0.0         UG    600    0        0 wlan0
0.0.0.0         192.168.55.100  0.0.0.0         UG    32766  0        0 l4tbr0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.55.0    0.0.0.0         255.255.255.0   U     0      0        0 l4tbr0
192.168.86.0    0.0.0.0         255.255.255.0   U     600    0        0 wlan0

If I run $ ip route del default dev eth0 or instead $ ifmetric eth0 700, I can ping 8.8.8.8 as we are now using wlan0 and our software can connect to our servers.

At this point, the state of the device is good; I have the NAS mounted and I have Internet access over WiFi. However, on reboot the default device will switch to eth0. So I cannot figure out how to get into this state on startup so that the Ubuntu machine defaults to using wlan0 for Internet and automounts the NAS to /mnt/lspro.

Edit -

Changing /etc/dhcpd.conf to

interface wlan0
metric 0

interface eth0
metric 100

Does not work. Also adding metric 100 to /etc/network/interfaces does not work (possible error, cannot see eth0 in route -n after adding this line)

Edit2 -

Really oddly, I see that metric for wlan0 changes from 20600 to 600 about 10 seconds into boot. I believe something is changing these late. If I try toifmetric eth0 100 in /etc/rc.local, eth0 does not appear in route -n - Something really strange is happening? It appears I can only change the metric really late after boot.


You should just omit

gateway 192.168.11.1

for eth0.

You don't need it for connection within a broadcast domain (switch). Neither should you "make thing up" (the network switch is not connected to a router (does not have Internet acccess)).