This is much easier with static IPs than with dhcp, because all you need to do is declare the route metrics for each interface and when the ethernet has no carrier, networkd will not bring the routes up. E.g.:
network:
version: 2
renderer: networkd
ethernets:
enp2s0:
addresses: [192.168.15.2/24]
routes:
- to: 0.0.0.0/0
via: 192.168.15.1
metric: 100
nameservers:
search: [mydomain, otherdomain]
addresses: [192.168.15.1]
wifis:
wlx0013eff10948:
access-points:
"the-network":
password: "the-password"
addresses: [192.168.15.2/24]
routes:
- to: 0.0.0.0/0
via: 192.168.15.1
metric: 200
nameservers:
search: [mydomain, otherdomain]
addresses: [192.168.15.1]
After running netplan apply
, networkctl
should then show output like:
$ networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 enp0s31f6 ether no-carrier configuring
3 wlp82s0 wlan routable configured
3 links listed.