Systemd/systemd-networkd
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:
[Match]
Name=en*
[Network]
DHCP=yes
Static IP address
Wired connection with static IP address (uses CIDR notation for subnetting):
[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:
[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
networkctl [OPTIONS...] COMMAND Query and control the networking subsystem. Commands: list [PATTERN...] List links status [PATTERN...] Show link status lldp [PATTERN...] Show LLDP neighbors label Show current address label entries in the kernel delete DEVICES... Delete virtual netdevs up DEVICES... Bring devices up down DEVICES... Bring devices down renew DEVICES... Renew dynamic configurations forcerenew DEVICES... Trigger DHCP reconfiguration of all connected clients reconfigure DEVICES... Reconfigure interfaces reload Reload .network and .netdev files Options: -h --help Show this help --version Show package version --no-pager Do not pipe output into a pager --no-legend Do not show the headers and footers -a --all Show status for all links -s --stats Show detailed link statistics -l --full Do not ellipsize output -n --lines=INTEGER Number of journal entries to show --json=pretty|short|off Generate JSON output See the networkctl(1) man page for details.
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
[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
[Match]
[Service]
ExecStart=
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online --interface=any
to accept connectivity with any interface, or
[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.