How do I stop netplan from binding a default gateway on every interface

9,140

Netplan v0.90 introduces a new set of options: dhcp4-overrides (pull request).

So, if your version of the netplan.io package is new enough (see available versions here), you can use this:

    eno1:
      dhcp4: yes
      dhcp4-overrides:
        use-routes: false
Share:
9,140

Related videos on Youtube

Aaron Murray
Author by

Aaron Murray

Computer technician by day, closet php developer by night.

Updated on September 18, 2022

Comments

  • Aaron Murray
    Aaron Murray over 1 year

    I have a fresh install of ubuntu server 17.10, however the problem may affect previous versions, but this is the first time I have encountered this situation.

    The server is running 2 separate network cards, one for internal local network communications (trusted), the other is a public (untrusted) connection to the internet with the ISP.

    In the past, I have always configured the internal connection as static, and without a default gateway, as the external card would be provided via DHCP from my ISP (static lease).

    /etc/netplan/00-netcfg.yaml

    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          dhcp6: no
          addresses: [192.168.1.xx/24]
          nameservers:
            addresses: [8.8.8.8,8.8.4.4]
        eth1:
          dhcp4: yes
          dhcp6: no
    

    Now this worked fine as I did not provide a gateway4 line in the eth0 configuration so it bound the default gateway from the ISP and worked fine.

    I have since decided I wanted to use static leases for the server(s) in my homelab, and have configured as such on the internal router. But when I set up the netplan config as dhcp for both devices, it adds the default gateway for both interfaces (which makes sense because both DHCP servers are providing a gateway).

    > route -n
    
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eth0
    0.0.0.0         173.xxx.xxx.1   0.0.0.0         UG    100    0        0 eth1
    173.xxx.xxx.0   0.0.0.0         255.255.255.0   U     0      0        0 eth1
    173.xxx.xxx.1   0.0.0.0         255.255.255.255 UH    100    0        0 eth1
    192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
    192.168.1.1     0.0.0.0         255.255.255.255 UH    100    0        0 eth0
    

    How can I setup netplan so the eth0 adapter (internal) to disregard the default gateway provided by the DHCP server (without removing the gateway on the DHCP server itself as other machines still need a default gateway).

    • Mathieu Trudel-Lapierre
      Mathieu Trudel-Lapierre about 6 years
      Great question! This is a shortcoming in netplan, it's indeed missing a way to skip setting a default gateway for DHCP. Please file a bug here: bugs.launchpad.net/netplan/+filebug
    • Don Faulkner
      Don Faulkner about 6 years
      I went to file a bug today, but I found Bug #1724666 that is very similar at its core, so I filed affects-me-too and added a comment. :)
    • Aaron Murray
      Aaron Murray about 6 years
      Thank you both for your suggestions and actions with this. I had reverted to changing my infrastructure to use only one dhcp (static lease) which is required by my current ISP, along with static IP addresses that I can control internally without default gateways (as described above). While it is not the optimum (preferred) method, it works for now. The downside is when addresses change on the internal network (which happens rarely), they are not centrally managed. Very disappointed with Ubuntu's decision to change to netplan with this very basic problem (among other reasons).
    • detly
      detly almost 6 years
      That bug says it's fixed, so is there an answer now?
    • detly
      detly almost 6 years
      Meant to ping @DonFaulkner in that last comment.