10

I have the appropriate network file with DHCP enabled.

$ cat /etc/systemd/network/20-dhcp.network 
[Match]
Name=enp3*

[Network]
DHCP=ipv4

[DHCP]
UseDomains=true

I have appropriate /etc/resolv.conf as well. I am not using systemd-resolvd daemon (and it may not have anything to do with it, because I did try using it, but did not help anyway). Any ideas why the DHCP client needs to be run manually to get it working?

3 Answers 3

11

Just in case people aren't aware - systemd-networkd now contains its own in-built DHCP client implementation so no external DHCP clients would be started unless they're configured elsewhere.

The configuration is controlled by a number of configuration files as described in the systemd-networkd man page. Since Ubuntu 18.04 the network configuration (/{lib,etc,run}/netplan/*.yaml) is now controlled by netplan which will generate configuration files for systemd-networkd (/{lib,etc,run}/systemd/network/).

Specifically the DHCP client operation is controlled in the systemd.network config file - it can be enabled in the [NETWORK] section of the config file using the DHCP directive (it defaults to "no") and configured the [DHCP] section. Note it is also possible to enable DHCPServer mode but that is generally mutually exclusive to DHCP client mode.

3
  • 1
    Welcome , could you explain the built-in dhcp in systemd-network , please.
    – GAD3R
    Nov 1, 2018 at 19:08
  • i did everything that was asked to be done, configuring a bridge (netdev) and a network-file with DHCPServer=yes and DHCP=ipv4, but it won't work! the guest has no DHCP and receives no IP/DNS information
    – Erdinc Ay
    Jan 1 at 21:23
  • I've updated the question to explain that enabling DHCPServer mode would probably result in DHCP client mode being disabled. If you want the DHCP client mode you only need to set the DHCP variable in the [NETWORK] config section.
    – Pierz
    Jan 4 at 11:57
6

From reading man systemd.network, it sounds like the .network files in /etc/systemd/network are controlled by systemd-networkd. If the files aren't being read, it could be that you aren't using this part of systemd.

For example, on a Ubuntu 16.04 desktop, I can see that systemd-networkd is not in use:

 systemctl status systemd-networkd

● systemd-networkd.service - Network Service Loaded: loaded (/lib/systemd/system/systemd-networkd.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:systemd-networkd.service(8)

Instead, the NetworkManager service is running. So, a DHCP client would be configured through NetworkManager in that case, or NetworkManager needs to be stopped and disabled, and systemd-networkd needs to be started and enabled.

2
  • 2
    Yes, systemd-netword is enabled and running. I had uninstalled NetworkManager before migrating to systemd-networkd
    – Salil
    Mar 11, 2017 at 20:30
  • I've now added some more info on configuration.
    – Pierz
    Nov 2, 2018 at 14:27
3

It turned out that I had two network files. I followed arch linux systemd-networkd documentation (https://wiki.archlinux.org/index.php/systemd-networkd#Wireless_adapter), and created one network file:

/etc/systemd/network/25-wireless.network
[Match]
Name=wlp2s0

[Network]
DHCP=ipv4

And it is working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.