← Back to team overview

netplan-developers team mailing list archive

How can I ignore the default gateway for some DHCP configured devices?

 

I have a machine (Ubuntu 18.04, netplan 1.10.1-5build1) with an ethernet port (enp1s0f0) and two wifi adapters, PCI (wlp2s0) and USB (wlx485d601f9b83). One use of the machine is to connect an ethernet-only device to a local wifi network via masquerading on wlx485d601f9b83. The other wifi adapter is for general purpose.
So my /etc/netplan/01-netcfg.yaml looks like:

network:
 version: 2
 renderer: networkd
 ethernets:
   enp1s0f0:
     addresses:
       - 10.0.0.1/24
 wifis:
   wlx485d601f9b83:
     optional: true
     dhcp4: yes
     access-points:
       [...]
   wlp2s0:
     optional: true
     dhcp4: yes
     access-points:
       [...]

There's also some iptables NAT rules to do the not-actually-bridging, and DHCP serving on 10.0.0.1 to configure the other machine.
It's much easier for me if I can still use DHCP on wlx485d601f9b83 so I 
don't have to statically configure it. Unfortunately this means I now 
get two sets of routes added, including the default:
$ ip route show
default via 192.168.1.1 dev wlx485d601f9b83 proto dhcp src 192.168.1.3 metric 600 default via 192.168.1.1 dev wlp2s0 proto dhcp src 192.168.1.100 metric 600 192.168.1.0/24 dev wlx485d601f9b83 proto kernel scope link src 192.168.1.3
192.168.1.0/24 dev wlp2s0 proto kernel scope link src 192.168.1.100
192.168.1.1 dev wlx485d601f9b83 proto dhcp scope link src 192.168.1.3 metric 600 192.168.1.1 dev wlp2s0 proto dhcp scope link src 192.168.1.100 metric 600
Since all routes have the same metric, connections just randomly switch 
between the two interfaces. This is counter to what I want (general 
traffic over wlp2s0) and it also seems to mess with certain services 
(like Avahi). Ideally I'd like to prevent wlx485d601f9b83 becoming the 
default gateway at all (ie. ignore that part of the DHCP config) and 
perhaps suppress the 192.168.1.0/24 entry as well.
But my reading of the manual[1] is that I can't even change the route 
metric, let alone ignore default DHCP routes, without doing full manual 
routing on both interfaces.
I've read a couple of questions on AskUbuntu about this, one of which 
is unanswered[2] and the other[3] suggests some networkd overrides 
which didn't achieve anything (I used "systemctl edit" rather than 
copying control files around, and I suspect their advice was actually 
to override netplan's renderer output altogether and drop netplan). 
However this Launchpad bug[4] suggests that something has changed 
recently that might facilitate what I need, I just can't figure out 
what.
Is what I'm asking possible? Or do I need to bypass Netplan and 
configure networkd manually?
Please CC me on replies, I can't subscribe to this list because I'm not 
a member of the team on Launchpad.
Thanks,
Jason

[1] https://netplan.io/reference#routing
[2] https://askubuntu.com/questions/1008825/how-do-i-stop-netplan-from-binding-a-default-gateway-on-every-interface [3] https://askubuntu.com/questions/1042582/how-to-set-default-route-with-netplan-ubuntu-18-04-server-2-nic/1043546
[4] https://bugs.launchpad.net/netplan/+bug/1724666



Follow ups