0

In my netplan config I have two interfaces:

network:
  version: 2
  renderer: networkd
  ethernets:
    ethusb1:
      dhcp4: yes
      dhcp6: yes
  wifis:
    wlp3s0:
      dhcp4: yes
      dhcp6: yes
      access-points:
        "x":
         password: "x"

Both interfaces are alive in that I responses for both

 ping -I ethusb1 ubuntu.com
 ping -I wlp3s0  ubuntu.com 

Okay. My question is this: the routing table shows default routes through both interfaces. How can this be so? How do I know which route is used by default by system?

default via 192.168.1.254 dev ethusb1 proto dhcp src 192.168.1.71 metric 100 
default via 192.168.1.254 dev wlp3s0 proto dhcp src 192.168.1.120 metric 600 
192.168.1.0/24 dev ethusb1 proto kernel scope link src 192.168.1.71 
192.168.1.0/24 dev wlp3s0 proto kernel scope link src 192.168.1.120 
192.168.1.254 dev ethusb1 proto dhcp scope link src 192.168.1.71 metric 100 
192.168.1.254 dev wlp3s0 proto dhcp scope link src 192.168.1.120 metric 600 

2 Answers2

2

If you put a different number in the metrics entry of the cards, the network connection would default to the connection with the lower number.

As an example, if you put metrics of 100 in the wired network connection, and metrics of 600 in the wireless connection, the system would default to the wired connection.

Here is a sample netplan.yaml setting the metric manually.

network:
  version: 2
  ethernets:
    ethusb1:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 100
    wlp3s0:
      dhcp4: yes
      dhcp4-overrides:
        route-metric: 600
0

As Pilot6 points out, the system preference for route is determined by the metric of the routing. In the output given in the question the metric for the ethernet device is lower than the wifi device, so the system will prefer it.

The lower metric for ethernet seems to be default netplan behavior so I am not sure that Thomas Alchinger's solution is necessary.

slangasek in netplan: ethernet preferred if available, otherwise wifi, but with same static IP address provides a netplan configuration using static IPs. I've tested this on my 19.10 system and it works as posted (with actual IPs of course).