I replaced dhclient with systemd-networkd's DHCP client the following way:
1. Uninstall dhclient
sudo apt purge -y isc-dhcp-client
sudo apt purge -y isc-dhcp-common
2. Start systemd-networkd
sudo systemctl start systemd-networkd
sudo systemctl enable systemd-networkd
3. Make systemd-networkd manage network interfaces, using its own DHCP client
For every interface, create a *.network
config file in /etc/systemd/network
, for example 05-enp1s0.network
:
[Match]
Name=enp1s0
[Network]
DHCP=yes
After restarting Linux, or restarting systemd-networkd, or sudo networkctl reload
, these interfaces will be configured by the DHCP client of systemd-networkd. Renewing interface configurations is easy, for example:
sudo networkctl renew enp1s0
This is highly subjective, but my initial experience is that systemd-networkd's DHCP client is more trustworthy and reacts faster than dhclient. If I change network connections, which happens often in my use case, I get a nice plug'n'play experience.
4. [Optional] Add 8.8.8.8 as the primary DNS server
Turn on systemd-resolved:
sudo systemctl start systemd-resolved
sudo systemctl enable systemd-resolved
In /etc/systemd/resolved.conf
:
[Resolve]
DNS=8.8.8.8
In /etc/nsswitch.conf
, add resolve
at first place for hosts
:
...
hosts: resolve [!UNAVAIL=return] files dns
...
Now systemd-resolve
will work, but nslookup
will still use the DNS server that was written into /etc/resolv.conf
by the DHCP client. To solve this, convert /etc/resolv.conf
into a soft link to the resolv.conf file used by systemd-resolved:
cd /etc
sudo rm resolv.conf
sudo ln -s /run/systemd/resolve/stub-resolv.conf resolv.conf
After restarting systemd-resolved, this file contains 8.8.8.8 in the first line and below that the DNS servers collected by the DHCP client from the DHCP servers of connected networks, for example:
nameserver 8.8.8.8
nameserver 192.168.1.1
nameserver 192.168.42.129