OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

5.1.3. On the Command Line with systemd-networkd


While ifupdown is the historical tool used by Debian, and while it is still the default for server or other minimal installations, there is a newer tool worth considering: systemd-networkd. Its inte- gration with the systemd init system makes it a very attractive choice. It is not specific to Debian- based distributions (contrary to ifupdown) and has been designed to be very small, efficient, and relatively easy to configure if you understand the syntax of systemd unit files. This is an especially attractive choice if you consider NetworkManager bloated and hard to configure.

You configure systemd-networkd by placing .network files into the /etc/systemd/network/ di- rectory. Alternatively, you can use /lib/systemd/network/ for packaged files or /run/systemd/ network/ for files generated at run-time. The format of those files is documented in systemd. network(5). The Match section indicates the network interfaces the configuration applies to. You can specify the interface in many ways, including by media access control (MAC) address or device type. The Network section defines the network configuration.


Example 5.1 DHCP-based Configuration in /etc/systemd/network/80-dhcp.network


[Match] Name=en*


[Network] DHCP=yes

[Match] Name=en*


[Network] DHCP=yes

Example 5.2 Static Configuration in /etc/systemd/network/50-static.network


[Match] Name=enp2s0


[Network] Address=192.168.0.15/24 Gateway=192.168.0.1 DNS=8.8.8.8

[Match] Name=enp2s0


[Network] Address=192.168.0.15/24 Gateway=192.168.0.1 DNS=8.8.8.8


Note that system-networkd is disabled by default, so if you want to use it, you should enable it. It also depends on systemd-resolved for proper integration of DNS resolution, which in turn requires you to replace /etc/resolv.conf with a symlink to /run/systemd/resolve/resolv. conf, which is managed by systemd-resolved.


# systemctl enable systemd-networkd

# systemctl enable systemd-resolved

# systemctl start systemd-networkd

# systemctl start systemd-resolved

# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

# systemctl enable systemd-networkd

# systemctl enable systemd-resolved

# systemctl start systemd-networkd

# systemctl start systemd-resolved

# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf


Although systemd-networkd suffers from some limitations, like the lack of integrated support for wireless networks, you can rely on a pre-existing external wpa_supplicant configuration for wireless support. However, it is particularly useful in containers and virtual machines and was originally developed for environments in which a container’s network configuration depended on its host’s network configuration. In this scenario, systemd-networkd makes it easier to manage both sides in a consistent manner while still supporting all sorts of virtual network devices that you might need in this type of scenario (see systemd.netdev(5)).


Top OS Cloud Computing at OnWorks: