Systemd/systemd-networkd

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.
Not to be confused with systemd.
Not to be confused with systemd/systemd-resolved.


systemd-networkd provides simple configuration of wired network interfaces. It is disabled by default on Gentoo systems, but can be quickly enabled as necessary enable connectivity.

Configuration

To configure systemd-networkd, create a .network file under the /etc/systemd/network directory. Files are written in INI style syntax. See the systemd.network(5) man page for reference.

DHCP

A simple DHCP configuration is given below:

FILE /etc/systemd/network/50-dhcp.network
[Match]
Name=en*
 
[Network]
DHCP=yes

Static IP address

Wired connection with static IP address (uses CIDR notation for subnetting):

FILE /etc/systemd/network/50-static.network
[Match]
Name=enp1s0
 
[Network]
Address=192.168.1.10/24
Gateway=192.168.1.1
DNS=192.168.1.1

Wireless card

A simple DHCP configuration for the wireless card wlan0 is given below:

FILE /etc/systemd/network/50-wireless.network
[Match]
Name=wlan0
 
[Network]
DHCP=yes
IgnoreCarrierLoss=3s

Connecting to a wireless access point can be achieved using Iwd or Wpa supplicant.

DNS (systemd-resolved)

Note that systemd-networkd does not update the resolv.conf file or provide DNS service by default. See the systemd/systemd-resolved article for details on how to setup address name resolution (DNS) on systemd systems.

Usage

Service

To enable and start the service now:

root #systemctl enable --now systemd-networkd.service

networkctl

A networkctl user space utility exists to query and control the networking subsystem for systems running systemd-networkd.

user $networkctl --help

Troubleshooting

Hangs

If a cifs filesystem is placed in fstab to automount a samba share with the option x-systemd.after=network-online.target, and multiple network interfaces are present but only one is connected, systemd-networkd-wait-online.service may try to confirm network connectivity on all interfaces, resulting in the default two-minute timeout causing a file manager like Dolphin to not open initially after boot until two minutes have elapsed. To fix this, run

root #systemctl edit systemd-networkd-wait-online.service

and add the lines

FILE /etc/systemd/system/systemd-networkd-wait-online.service.d/override.conf
[Match]
[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --interface=eth0

where the first ExecStart= clears any existing entries, and eth0 should be replaced with name of the interface that is primary/relevant for the behavior that is desired. One could also write

FILE /etc/systemd/system/systemd-networkd-wait-online.service.d/override.conf
[Match]
[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --interface=any

to accept connectivity with any interface, or

FILE /etc/systemd/system/systemd-networkd-wait-online.service.d/override.conf
[Match]
[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --ignore=eth0

to ignore a particular one.[1]

See also

  • systemd/systemd-resolved — a address name resolution (DNS) daemon which can be used in conjunction with systemd-networkd.
  • systemd — a modern SysV-style init and rc replacement for Linux systems.
  • Network management — describes possibilities for managing the network stack.

External resources

References