25

I would like to use systemd-networkd to configure my networking on Ubuntu.

I added an /etc/systemd/network/host0.network file

[Match]
Name=host0

[Network]
Address=10.5.1.1/24
Gateway=10.5.1.254

to configure my host0:

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: host0@if14428: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether d6:fa:2e:69:dd:30 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 169.254.229.86/16 brd 169.254.255.255 scope link host0
       valid_lft forever preferred_lft forever
    inet6 fe80::d4fa:2eff:fe69:dd30/64 scope link
       valid_lft forever preferred_lft forever

But, as seen above it is not configured with 10.5.1.1 despite restarting systemd-networkd, enabling it, rebooting. Each time the address is from APIPA (as if there was no DHCP, which is not configured there).

In no other places is networking configured (notably in /etc/network/interfaces, which is empty)

WoJ
  • 2,804
  • 7
  • 48
  • 73
  • 1
    Did you look at the output of `networkctl` yet? What about `systemctl status systemd-networkd`? – Daniel B Jul 26 '17 at 11:08
  • This is years old by now, but just to point out that the `.network` file goes in `/etc/systemd/network/host0.network` (not the typo'ed `netwoek`) – Ralph Bolton Sep 22 '21 at 09:49
  • Thanks @RalphBolton - never too late to correct an error :) – WoJ Sep 22 '21 at 10:03

2 Answers2

44

From https://coreos.com/os/docs/latest/network-config-with-networkd.html :

Enable debugging manually

mkdir -p /etc/systemd/system/systemd-networkd.service.d/

Create Drop-In /etc/systemd/system/systemd-networkd.service.d/10-debug.conf with following content:

[Service]
Environment=SYSTEMD_LOG_LEVEL=debug

And restart systemd-networkd service:

systemctl daemon-reload
systemctl restart systemd-networkd
journalctl -b -u systemd-networkd
Anon
  • 1,299
  • 12
  • 15
  • 15
    `systemctl edit systemd-networkd` is slightly faster as it creates automatically the needed folder and doesn't need daemon-reload. – Max Oct 31 '19 at 13:35
  • For some reason I had to reboot before debugging was activated for systemd-networkd. Just mentioning it in case someone else struggles. (Yes, I tried reloading and restarting - multiple times.) Running systemd 243. – hansfn Dec 09 '19 at 10:10
  • Will I be able to open the log with a regular text editor? i.e. - what is the name and the location of this file? – Guy Avraham Jun 27 '23 at 09:02
  • 1
    @GuyAvraham the log goes to the (binary) journal so you will have to use the journalctl command stated to view it. – Anon Jun 28 '23 at 16:19
0

The previous answers are great to find out what is running and what isn't, and restarting the service.

I'd add (from How to enable if it's disabled):

systemctl enable <your.service.here>

e.g. systemd-networkd

Also, I'm not sure what Name=host0 matches. I guess something, since it shows up in 2: host0@if14428 under ip addr. But using and interface name, or MAC address, as it appears in ip link is a safer bet.

robinCTS
  • 4,327
  • 4
  • 20
  • 29
Lubo Diakov
  • 51
  • 1
  • 2