I've seen a lot of this question, with no clear and ideal answer, so I am asking it myself.
Ever since Ubuntu 18.04.3 (I think it was .3 that started it) through at least 20.04.1, I've been seeing a 2-minute delay on startup, waiting for the network to come up. IPv6 is not configured on our network, and the DHCP servers are Windows-based, with 2 replicated servers, and IP helpers on the VLANs - although my Ubuntu servers are on the same VLAN as the DHCP servers (all my VMs are on the same VLAN).
The netplan tends to get ignored, as dhcp insists on using the GUID as an identifier, even though the interface.yaml in /etc/netplan/ says to use the MAC. Further, DHCP doesn't even try to get an address until 10-15 minutes after startup, unless I mark the interface as optional. However, invoking dhclient works perfectly and immediately.
From what I've read, this delay seems to be an IPv6 addressing problem. So, I have disabled ipv6 in grub. I marked the interface as optional, and dhcp6 to false, in the netplan yaml file, and that solves the 2-minute start-up delay, but the dhcp server returns an unexpected IP, because the dhcp-identifier line from the netplan is being ignored. Instead of presenting the MAC address, Ubuntu presents the GUID.
Here is my 01-netcfg.yaml:
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: true
dhcp6: false
dhcp-identifier: mac
optional: true
link-local: [ ]
As soon as I generate and apply the netplan, I get disconnected, and get the wrong IP address. If I manually invoke sudo dhclient -r; sudo dhclient, I get the expected IPv4 address immediately.
Ergo, the only way I've been able to make the server get the correct address without delay, is to set the interface as as stated, then run a script on startup to manually run dhclient.
This seems like a rather klugey way to do things, because it seems to be going around the problem(s) rather than fixing it/them.
Can someone please tell me what is happening, and more importantly, how to fix it?
Thanks in advance!
EDIT with new information: If I let the VM just sit, it finally picks up an IP about 8.5 minutes after the login prompt. I'm guessing that is 10 minutes after the interface comes up.
Also, I read in another thread about a similar issue, that having multiple DHCP servers on the segment caused the problem for another user. We do have 2 Windows 2019 DHCP servers on this segment, doing load balancing (scope replication).
EDIT sudo netplan --debug generate outputs the following:
** (generate:3137): DEBUG: 14:26:01.499: Processing input file /etc/netplan/00-installer-config.yaml
..
** (generate:3137): DEBUG: 14:26:01.501: starting new processing pass
** (generate:3137): DEBUG: 14:26:01.501: We have some netdefs, pass them through a final round of validation
** (generate:3137): DEBUG: 14:26:01.503: ens160: setting default backend to 1
** (generate:3137): DEBUG: 14:26:01.504: Configuration is valid
** (generate:3137): DEBUG: 14:26:01.505: Generating output files..
** (generate:3137): DEBUG: 14:26:01.505: openvswitch: definition ens160 is not for us(backend 1)
** (generate:3137): DEBUG: 14:26:01.506: NetworkManager: definition ens160 is not for us(backend 1)
(generate:3137): GLib-DEBUG: 14:26:01.507: posix_spawn avoided (fd close requested)
(generate:3137): GLib-DEBUG: 14:26:01.511: posix_spawn avoided (fd close requested)
Here is the output of sudo journalctl | grep ens160
Nov 08 08:45:30 graylog systemd-networkd[846]: ens160: DHCP lease lost
Nov 08 08:45:44 graylog kernel: vmxnet3 0000:03:00.0 ens160: renamed from eth0
Nov 08 08:45:52 graylog kernel: vmxnet3 0000:03:00.0 ens160: intr type 3, mode 0, 5 vectors allocated
Nov 08 08:45:52 graylog kernel: vmxnet3 0000:03:00.0 ens160: NIC Link is Up 10000 Mbps
Nov 08 08:45:52 graylog systemd-networkd[843]: ens160: Link UP
Nov 08 08:45:52 graylog systemd-networkd[843]: ens160: Gained carrier
Nov 08 08:45:53 graylog cloud-init[851]: ci-info: | ens160 | True | . | . | . | 00:50:56:96:c6:b7 |
Nov 08 08:45:53 graylog cloud-init[851]: ci-info: | 2 | multicast | :: | ens160 | U |
Nov 08 08:54:29 graylog systemd-networkd[843]: ens160: DHCPv4 address 10.83.1.5/24 via 10.83.1.1