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:
/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):
/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:
/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
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
Users may encounter a situation where the built-in systemd-networkd-wait-online service may try to confirm network connectivity for all links it is aware of and which are managed by systemd-networkd, but there aren't any configured by the system administrator. This will result in the default two-minute timeout to occur, preventing any depending service from accessing the network. The following examples of problems may follow:
The list of affected services can be obtained via
root #
systemctl list-dependencies systemd-networkd-wait-online.service --all --reverse
The system administrator can use several approaches to fix any such problem.
If a specific network interface is known to be required for network connectivity (e.g., eth0
), run
root #
systemctl disable systemd-networkd-wait-online.service
root #
systemctl enable systemd-networkd-wait-online@eth0.service
Alternatively, create an override for the service via
root #
systemctl edit systemd-networkd-wait-online.service
and add the lines
/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
/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
/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.