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 
  • 1
    This is OK. They have different metric. Ethernet has a priority. – Pilot6 Feb 1 at 17:15
  • @Pilot6 Does ethernet always get the priority or is this outcome a lucky chance? – Stephen Boston Feb 2 at 2:30
  • 1
    Frankly I have no idea, it seems that different Ubuntu releases have different default behavior. – Pilot6 Feb 2 at 7:53
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
  • What is the system default in the absence of a declared override? – Stephen Boston Feb 2 at 2:31
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.