Network configuration using systemd-networkd
Starting with systemd version 238, net naming schemes were added. As a result, when predictable network interface names are in use, an interface can end up with a different name depending on which systemd version was booted.
The good news is that with systemd-networkd you can identify network cards by their MAC addresses rather than depending on interface names at all.
In our Installimage and our automated installations, we generally aim to keep whatever network configuration method a distribution ships with by default. However, because tools such as ifupdown and network-scripts expect interface names to be spelled out, we currently also rely on systemd-networkd to configure CentOS and Debian systems that use predictable network interface names.
.network configuration file syntax
Details about the .network files that systemd-networkd uses are available here: https://www.freedesktop.org/software/systemd/man/systemd.network.html.
Main IP addresses
Dedicated root servers
The main IP of a dedicated root server is typically drawn from a larger subnet, but to block IP address spoofing, a system is only permitted to communicate with its gateway.
In practice this means that if you set the real subnet mask of an IPv4 address — say /27 — the other systems sharing that subnet would become unreachable.
To keep those systems within your subnet reachable, configure your main IPv4 address as a /32 address instead. Because that puts the gateway outside the IP’s own network, you then have to tell the system how to get to the gateway.
IPv4
In the example below, the main IP 1.2.3.4 and the gateway 4.3.2.1 are configured for the network interface whose MAC address is 12:34:56:78:9a:bc.
The main IP is set up as a /32 address in its own [Address] section, and Peer=<Gateway> informs the system that the gateway is reachable through the interface that address belongs to. For the reasoning behind using this setup on dedicated root servers, see the Dedicated root servers section.
# Config file /etc/systemd/network/10-mainif.network
[Match]
MACAddress=12:34:56:78:9a:bc # Main network interface MAC
[Network]
Gateway=4.3.2.1
[Address]
Address=1.2.3.4 # Main IP, /32 suffix is optional
Peer=4.3.2.1/32 # Gateway
IPv6
To configure IPv6, simply provide the IP address and the gateway.
# Config file /etc/systemd/network/10-mainif.network
[Match]
MACAddress=12:34:56:78:9a:bc # Main network interface MAC
[Network]
Address=1:2:3:4::5/64
Gateway=fe80::1
IPv4 and IPv6
The dualstack configuration below is essentially the IPv4 and IPv6 configurations shown above merged together.
For the reasoning behind configuring a dedicated server’s main IPv4 as a /32 address, and behind needing the Peer setup to communicate with subnet neighbors, refer to the Dedicated root servers and IPv4 sections.
# Config file /etc/systemd/network/10-mainif.network
[Match]
MACAddress=12:34:56:78:9a:bc # Main network interface MAC
[Network]
Address=1:2:3:4::5/64
Gateway=4.3.2.1
Gateway=fe80::1
[Address]
Address=1.2.3.4 # Main IP, /32 suffix is optional
Peer=4.3.2.1/32 # Gateway