Netplan – Troubleshooting DHCP Configured Network with No Internet

dhcpdhcp-serverisc-dhcpnetplannetworking

I am trying to configure my Ubuntu Server 20.04 LTS to use DHCP in its network configuration.

Many tutorials on the internet recommend that I create the following file with the following settings…

root@sinj:/home/brlight# cat /etc/netplan/99_config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: true

… and run the following commands…

root@sinj:/home/brlight# netplan --debug generate
root@sinj:/home/brlight# netplan apply

PROBLEM: The server is obtaining its settings via DHCP, but is unable to access the internet.


PLUS:

Unlike other servers on the same network, it appears that the server is unable to obtain the gateway settings.

No problem server…

[root@ssh_brl ~]# ip route show
default via 10.0.0.1 dev eth0 proto dhcp metric 100 
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.6 metric 100 
10.2.0.0/24 via 10.0.0.7 dev eth0 proto dhcp metric 100

Server with problem …

root@sinj:/home/brlight# ip route show
10.0.0.0/24 dev ens3 proto kernel scope link src 10.0.0.17 
10.2.0.0/24 via 10.0.0.7 dev ens3 proto dhcp src 10.0.0.17 metric 100 

OTHER INFORMATION:

I

root@sinj:/home/brlight# ip route show
10.0.0.0/24 dev ens3 proto kernel scope link src 10.0.0.17 
10.2.0.0/24 via 10.0.0.7 dev ens3 proto dhcp src 10.0.0.17 metric 100 

II

root@sinj:/home/brlight# lshw -C network
  *-network                 
       description: Ethernet controller
       product: Virtio network device
       vendor: Red Hat, Inc.
       physical id: 3
       bus info: pci@0000:00:03.0
       version: 00
       width: 32 bits
       clock: 33MHz
       capabilities: msix bus_master cap_list rom
       configuration: driver=virtio-pci latency=0
       resources: irq:11 ioport:c060(size=32) memory:fc056000-fc056fff memory:fc000000-fc03ffff
     *-virtio0
          description: Ethernet interface
          physical id: 0
          bus info: virtio@0
          logical name: ens3
          serial: 52:54:00:6c:ec:1f
          capabilities: ethernet physical
          configuration: autonegotiation=off broadcast=yes driver=virtio_net driverversion=1.0.0 ip=10.0.0.17 link=yes multicast=yes

III

root@sinj:/home/brlight# networkctl status ens3
● 2: ens3                                                              
             Link File: /usr/lib/systemd/network/99-default.link       
          Network File: /run/systemd/network/10-netplan-ens3.network   
                  Type: ether                                          
                 State: routable (configured)
                  Path: pci-0000:00:03.0                               
                Driver: virtio_net                                     
                Vendor: Red Hat, Inc.                                  
                 Model: Virtio network device                          
            HW Address: 52:54:00:6c:ec:1f                              
                   MTU: 1500 (min: 68, max: 65535)                     
  Queue Length (Tx/Rx): 1/1                                            
      Auto negotiation: no                                             
                 Speed: n/a                                            
               Address: 10.0.0.17 (DHCP4)                              
                        fe80::5054:ff:fe6c:ec1f                        
                   DNS: 10.0.0.1                                       

Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: IPv6 successfully enabled
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: Link UP
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: Gained carrier
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: DHCPv4 address 10.0.0.17/24 via 10.0.0.1
Mar 06 01:47:13 sinj systemd-networkd[641]: ens3: Gained IPv6LL

IV

root@sinj:/home/brlight# dig www.google.com

; <<>> DiG 9.16.1-Ubuntu <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10647
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;www.google.com.                        IN      A

;; ANSWER SECTION:
www.google.com.         41      IN      A       172.217.30.36

;; Query time: 48 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sat Mar 06 04:37:04 UTC 2021
;; MSG SIZE  rcvd: 59

V

root@sinj:/home/brlight# dhclient -v ens3
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/ens3/52:54:00:6c:ec:1f
Sending on   LPF/ens3/52:54:00:6c:ec:1f
Sending on   Socket/fallback
DHCPREQUEST for 10.0.0.17 on ens3 to 255.255.255.255 port 67 (xid=0x601d9dc1)
DHCPACK of 10.0.0.17 from 10.0.0.5 (xid=0xc19d1d60)
RTNETLINK answers: File exists
bound to 10.0.0.17 -- renewal in 933 seconds.

VI

root@sinj:/home/brlight# cat /var/lib/dhcp/dhclient.leases
lease {
  interface "ens3";
  fixed-address 10.0.0.17;
  option subnet-mask 255.255.255.0;
  option dhcp-lease-time 4000;
  option routers 10.0.0.1;
  option dhcp-message-type 5;
  option dhcp-server-identifier 10.0.0.5;
  option domain-name-servers 10.0.0.1;
  option dhcp-renewal-time 1000;
  option rfc3442-classless-static-routes 24,10,2,0,10,0,0,7;
  option dhcp-rebinding-time 2000;
  option host-name "sinj";
  renew 6 2021/03/06 05:20:33;
  rebind 6 2021/03/06 05:38:40;
  expire 6 2021/03/06 06:12:00;
}
lease {
  interface "ens3";
  fixed-address 10.0.0.17;
  option subnet-mask 255.255.255.0;
  option dhcp-lease-time 4000;
  option routers 10.0.0.1;
  option dhcp-message-type 5;
  option dhcp-server-identifier 10.0.0.5;
  option domain-name-servers 10.0.0.1;
  option dhcp-renewal-time 1000;
  option rfc3442-classless-static-routes 24,10,2,0,10,0,0,7;
  option dhcp-rebinding-time 2000;
  option host-name "sinj";
  renew 6 2021/03/06 18:50:24;
  rebind 6 2021/03/06 19:10:57;
  expire 6 2021/03/06 19:44:17;
}

VII

root@sinj:/home/brlight# ip route
10.0.0.0/24 dev ens3 proto kernel scope link src 10.0.0.17 
10.2.0.0/24 via 10.0.0.7 dev ens3 
10.2.0.0/24 via 10.0.0.7 dev ens3 proto dhcp src 10.0.0.17 metric 100

[Refs.: https://ubuntu.com/server/docs/network-configuration ,
http://manpages.ubuntu.com/manpages/cosmic/man5/netplan.5.html , https://www.krizna.com/ubuntu/setup-network-ubuntu-18-04/ ,
https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/ ,
https://www.linuxtechi.com/assign-static-ip-address-ubuntu-20-04-lts/ ]

Best Answer

Sorry this is 8 months later than you posted - but I've encountered the same issue and was googling to see if others had solved it.

A few months ago I was experimenting with wireguard and set up a private VPN between two houses - all was well and so I modified my DHCP Server configuration to push the static route (to the other house) out via isc-dhcp-server

This works fine except none of the Ubuntu 18.04 and 20.04 VMs will set the default route now.

If you comment out any option rfc3442-classless-static-routes option ms-classless-static-routes from your DHCP Server conf and restart, then netplan apply - you should find the default route comes back.

Repeat with them back in - the default route disappears.

netplan ip leases ens18 - does show it knows the default route - it just never configures it.

RFC3442 says:

Many clients may not implement the Classless Static Routes option. DHCP server administrators should therefore configure their DHCP
servers to send both a Router option and a Classless Static Routes
option, and should specify the default router(s) both in the Router
option and in the Classless Static Routes option.

because previously it says:

If the DHCP server returns both a Classless Static Routes option and a Router option, the DHCP client MUST ignore the Router option.

So DHCP Client is doing the right thing and not setting a default route - because you are using option rfc3442-classless-static-routes

The solution is to prefix the default route with (in your case) 0, 10, 0, 0, 1,

On my network it is:

option rfc3442-classless-static-routes 0, 172, 16, 0, 1, 22, 172, 16, 4, 172, 16, 0, 250;

which means default route is 172.16.0.1 and the 172.16.4/22 network can be reached via 172.16.0.250

On a client after a netplan apply:

# ip route show
default via 172.16.0.1 dev ens18 proto dhcp src 172.16.0.220 metric 100
172.16.0.0/22 dev ens18 proto kernel scope link src 172.16.0.220
172.16.4.0/22 via 172.16.0.250 dev ens18 proto dhcp src 172.16.0.220 metric 100

Hope this helps others who've been searching and might come across this answer.

Related Topic