2

I have an embedded linux system compiled with Yocto, using systemd. I have a network configuration file at /etc/systemd/network/20-wired.network. The contents of that file are:

[Match]
Name=eth0

[Network]
Address=192.168.5.40/24
Gateway=192.168.5.1
DNS=192.168.5.1

However, when I reboot my machine, the eth0 interface is successfully configured using DHCP instead of assigning the static IP address. The ip a command shows:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether f8:dc:7a:3c:27:82 brd ff:ff:ff:ff:ff:ff
    inet 10.1.1.223/16 brd 10.1.255.255 scope global dynamic noprefixroute eth0
       valid_lft 85898sec preferred_lft 85898sec
    inet6 fe80::43ec:fd39:e1c0:3c05/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

However, if I then wait 5 seconds or so after boot, and do a systemctl restart systemd-networkd the system will usually be configured correctly like so:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether f8:dc:7a:3c:27:82 brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.40/24 brd 192.168.5.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::43ec:fd39:e1c0:3c05/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

Lastly, with the right timing on the restart of the network service, I can seemingly even get this result (both the intended static address and the unwanted DHCP address):

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether f8:dc:7a:3c:27:82 brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.40/24 brd 192.168.5.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.1.1.223/16 brd 10.1.255.255 scope global dynamic noprefixroute eth0
       valid_lft 86246sec preferred_lft 86246sec
    inet6 fe80::43ec:fd39:e1c0:3c05/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

Does anyone know what is going on here or how to debug this? Is there something obvious wrong with my configuration?

systemctl status systemd-networkd shows the following immediately after boot (specifically after network-online.target):

* systemd-networkd.service - Network Service
     Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
     Active: activating (start) since Tue 2021-07-20 12:58:52 UTC; 65ms ago
TriggeredBy: * systemd-networkd.socket
       Docs: man:systemd-networkd.service(8)
   Main PID: 282 ((networkd))
      Tasks: 1 (limit: 3576)
     Memory: 416.0K
     CGroup: /system.slice/systemd-networkd.service
             `-282 (networkd)

Some number of seconds later it looks like this:

* systemd-networkd.service - Network Service
     Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-07-20 12:58:52 UTC; 3min 20s ago
TriggeredBy: * systemd-networkd.socket
       Docs: man:systemd-networkd.service(8)
   Main PID: 282 (systemd-network)
     Status: "Processing requests..."
      Tasks: 1 (limit: 3576)
     Memory: 2.0M
     CGroup: /system.slice/systemd-networkd.service
             `-282 /lib/systemd/systemd-networkd

So it looks like the service is still "activating" when the network-online.target services run. I'm not sure what that means, though, or if it's a problem.

5
  • IS DHCP is setting a 10.1.1.x address? Are you sure you have the correct gateway? Is your 198.x.x.x. address request valid for your network? Jul 20 at 2:53
  • What does systemctl status systemd-networkd return right after reboot (before your restart)?
    – nobody
    Jul 20 at 5:46
  • @StephenBoston Yes, the 10.1.1.0/16 address is being set by the DHCP server. It's valid settings for my network. The 192.168.5.0/24 static address I'm trying to set is "valid" only in so far that I have a computer connected at 192.168.5.2/24. Gateway doesn't matter at all. I shouldn't have to have a gateway present to configure the interface.
    – Dave
    Jul 20 at 12:22
  • @nobody I added status output to the bottom of the post. The one thing I noticed is that when services which target network-online run, the systemd-networkd service is still "activating". A few seconds later, that service shows as "active".
    – Dave
    Jul 20 at 13:06
  • I just noticed that it seems NetworkManager made it on to the most recent build. It was running alongside systemd-networkd. Is that normal? I disabled the service and I'm now correctly configuring the interface.
    – Dave
    Jul 20 at 13:18
2

I just noticed that both systemd-networkd and NetworkManager were running. That is not normal, right? Usually you'd want one or the other? systemctl disable /lib/systemd/system/NetworkManager.service && reboot seems to have fixed the problem.

Edit: This is not the answer, or at least the whole answer. Just had it happen again even with NetworkManager disabled.

0

You don't need to disable NetworkManager. Just append this line to your configuration file:

NM_CONTROLLED=no

Hope that will help.

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.