systemd-networkd configuration

Systemd is used in all major Linux distributions. One of the components, systemd-networkd, provides a unified way to manage network interfaces and related settings (like routes, MTU) in a inifile-like way. This is quite awesome because it enables system administrators to use the same configuration style on all their operating systems.

Simple layer 2 IP assignment

Here is a very simple configuration to assign an IPv4 and IPv6 address to one interface

[Match]
Name=uplink

[Address]
Address=192.168.1.2/32
Peer=192.168.1.1/32

[Address]
Address=2a01:4f8:181:1157::3/128

[Route]
Gateway=192.168.1.1
GatewayOnLink=yes
PreferredSource=192.168.1.2
InitialCongestionWindow=10
InitialAdvertisedReceiveWindow=10

[Route]
Gateway=fe80::506e:45ff:fef1:ba4d
GatewayOnLink=yes
PreferredSource=2a01:4f8:181:1157::3
InitialCongestionWindow=10
InitialAdvertisedReceiveWindow=10

This can be saved in /etc/systemd/network/ with a .network suffix. I recommend to use the interface name in the file: /etc/systemd/network/uplink.network. This example assumes that the system is in 192.168.1.2/24. But configured is the address as /32. That means it has no layer 2 peers. It has an onlink connection to the router, 192.168.1.1. This is an important detail, especially for larger environments. The configuration does no ARP traffic. And there won’t be much ARP on the switches as well. The same happens with IPv6 and NDP.

Rename an interface

You might ask yourself, why is the interface named uplink? You can rename interfaces with systemd-network too! And I like to name them by their purpose. Throw the following into a .link file (the MAC address is used as an identifier, many other options are available as well):

# /etc/systemd/network/10-uplink.link
[Match]
Driver=virtio_net
MACAddress=52:54:00:78:63:9c

[Link]
Description=Uplink interface
Name=uplink
This entry was posted in General, Linux, Virtualization. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.