LinkLocalAddressing=no and ensuring the network file correctly identifies the interface as an Ethernet port, you can bypass unnecessary IPv6 probes and force immediate DHCP negotiation. This approach resolves the timeout without relying on non-existent directives, ensuring your server connects within seconds just like your other interfaces.
Understanding the Root Cause of the Delay
When systemd-networkd starts, it attempts to bring up all managed interfaces according to their respective.network files. For many modern Linux distributions, including Ubuntu 24.04 LTS, the default behavior includes attempting to configure a link-local IPv6 address (FE80::/10) even if you only intend to use IPv4. This process involves sending Neighbor Discovery Protocol (NDP) packets and waiting for a response or a timeout period. If your network environment does not support IPv6 or if the switch port is slow to respond to these probes, the network service will hang until the IPv6 timeout expires before finally falling back to or proceeding with DHCPv4.
Another common cause is the detection of "carrier" status. Some network drivers or virtualized environments may report that the physical link is up before the actual data path is ready, or vice versa. If systemd-networkd believes the link is down initially, it may wait for a state change event that never arrives promptly, delaying the start of the DHCP client. Additionally, if the interface is misidentified as a wireless or mobile broadband connection rather than a wired Ethernet port, systemd-networkd might apply different default policies that include additional roaming or stability checks, further increasing latency.
Configuring the Network File Correctly
To resolve this, you must edit the specific network configuration file forenp4s0. These files are located in /etc/systemd/network/. You should look for a file that matches the interface, often named something like 10-enp4s0.network or eth0.network depending on how udev rules have mapped the hardware. Open this file with a text editor such as nano or vim.
Inside the file, ensure the [Match] section explicitly targets the correct interface name. It is crucial to use Name=enp4s0 rather than wildcards unless you intend to apply the settings to multiple interfaces. Below the match section, the [Network] block must contain the directive to request an IP address via DHCP. The standard directive is DHCP=ipv4. Using DHCP=yes is also valid but less explicit; specifying ipv4 tells the daemon to only attempt IPv4 address acquisition, which can sometimes speed up the process by skipping IPv6-related logic entirely.
```ini
[Match]
Name=enp4s0
[Network]
DHCP=ipv4
LinkLocalAddressing=no
```
The addition of LinkLocalAddressing=no is critical. This directive explicitly instructs systemd-networkd not to assign a link-local address to the interface. By disabling this step, you remove the need for the system to perform NDP exchanges, which are often the primary culprit behind multi-second delays during boot or network restarts. Without this setting, the system waits for the IPv6 link-local timeout, which can take several seconds on busy or misconfigured networks.
Restarting the Network Service
After saving your changes to the.network file, you must reload the systemd-networkd configuration for the changes to take effect. You do not need to reboot the entire server. Instead, run the following command in the terminal:
sudo systemctl restart systemd-networkd
This command stops the network management daemon and starts it again, causing it to re-read all configuration files in /etc/systemd/network/. Once restarted, check the status of the service to ensure there are no errors:
systemctl status systemd-networkd
You can also monitor the journal logs in real-time to see what happens when the interface comes up. Use the following command to watch for messages related to enp4s0:
journalctl -u systemd-networkd -f
Look for lines indicating that the DHCP client has started and received an offer from the server. With LinkLocalAddressing=no set, you should observe a significant reduction in the time between the interface being marked as "ready" and having an IP address assigned. If the interface still takes too long, verify that the physical cable is securely connected and that the switch port is configured correctly. In virtualized environments, ensure that the virtual network adapter is attached to a bridge or VLAN that properly forwards DHCP broadcasts.
For users experiencing similar connectivity issues on older Ubuntu versions or virtual machines, reviewing past solutions for KVM networking may provide additional context on virtual switch configurations. See our guide on [Ubuntu 22.04 VM Internet Connection Issues](/news/1206445/ubuntu-22-04-vm-internet-connection-issue) for insights into virtual bridge setups.
Verifying the Configuration
Once the service has restarted, verify thatenp4s0 has obtained an IP address using the ip addr show enp4s0 command. Ensure that the address is present and that the state is UP. You can also test connectivity by pinging your gateway or an external DNS server. If the delay persists, consider checking the kernel ring buffer for any driver-level errors using dmesg | grep enp4s0. Driver issues can sometimes manifest as delayed link detection, which is distinct from the systemd-networkd configuration delays discussed here.
It is also worth noting that if you are using a static IP address instead of DHCP, the same principles apply regarding link-local addressing. Disabling link-local addressing can still improve boot times for static configurations by preventing unnecessary neighbor discovery probes. However, for dynamic addresses, ensuring the DHCP client starts immediately is paramount.
If you encounter issues where network tools fail to display addresses correctly after making these changes, remember that some legacy commands may behave differently in modern Linux environments. For more information on interpreting network output, refer to our article on [ifconfig and IPv4 Addresses](/news/1145977/ifconfig-and-ipv4-addresses).
Frequently Asked Questions
Why does my server take so long to get an IP on boot?
The delay is usually caused by systemd-networkd waiting for link-local IPv6 configuration or carrier detection timeouts. Disabling LinkLocalAddressing forces the system to skip these steps and proceed directly to DHCP negotiation.
Can I use DHCPv6 instead of DHCPv4?
Yes, you can change the directive to DHCP=ipv6 or DHCP=yes to allow both protocols. However, if IPv6 is not supported by your network, enabling it may introduce similar delays due to probe timeouts.
What if the interface name changes?
Interface names can change if hardware is moved or added. To avoid this, use MAC=xx:xx:xx:xx:xx:xx in the [Match] section instead of Name=. This ensures the configuration applies to the specific physical device regardless of its kernel-assigned name.
How do I debug network startup issues?
Use journalctl -u systemd-networkd -f to watch logs in real-time. Look for errors related to DHCP requests, link state changes, or configuration parsing failures to identify the exact point where the process stalls.
Does this fix apply to Ubuntu 22.04?
Yes, the LinkLocalAddressing directive is available in systemd-networkd across recent Ubuntu versions. The configuration syntax remains consistent, though package updates may slightly alter default behaviors.