In the Linux world, the use of SYSTEMD has been the subject of intense debate, and the fighting between its supporters and opponents is still burning. Today, most mainstream Linux distributions have adopted SYSTEMD as the default initialization init system.
As the authors say, as a "never finished, the system, which has never been perfected, but has followed technological progress, is not just an initialization process, it is designed as a broader system and service management platform, a SYSTEMD ecosystem that contains growing core system processes, libraries, and tools.
Part of the SYSTEMD is SYSTEMD-NETWORKD, which is responsible for the network configuration of the SYSTEMD ecosystem. With SYSTEMD-NETWORKD, you can configure the dhcp/static IP network based on the network device. It can also configure virtual network features, such as bridges, tunnels, and VLANs. SYSTEMD-NETWORKD currently does not have direct support for wireless networks, but you can use the Wpa_supplicant service to configure your wireless adapter and then connect it to SYSTEMD-NETWORKD.
In many Linux distributions, NetworkManager is still the default network Configuration Manager. Compared with NetworkManager, SYSTEMD-NETWORKD is still in a positive development state and lacks some features. For example, it doesn't have the ability to keep your computer connected at any time through multiple interfaces, as NetworkManager does. It has not yet provided a ifup/ifdown hook function for a higher level of scripting programming. However, SYSTEMD-NETWORKD and other SYSTEMD components (such as the resolved for domain resolution, the TIMESYNCD of NTP, UDEVD for naming) are very well combined. Over time, SYSTEMD-NETWORKD will only play an increasingly important role in the SYSTEMD environment.
If you are happy with the progress of SYSTEMD-NETWORKD, switching from NetworkManager to SYSTEMD-NETWORKD is something you should consider. If you are strongly opposed to systemd, it is good to be satisfied with NetworkManager or basic Web services.
But for those who want to try Systemd-networkd, you can continue to look at this tutorial on how to switch from NetworkManager to SYSTEMD-NETWORKD in Linux.
Demand
SYSTEMD 210 and its newer version provides SYSTEMD-NETWORKD. So for example, Debian 8 "Jessie" (Systemd 215), Fedora (SYSTEMD 217), Ubuntu 15.04 (SYSTEMD 219), or later Linux distributions and Systemd-networ KD compatible.
For other distributions, check your SYSTEMD version before you start the next step.
Switch from NetworkManager to SYSTEMD-NETWORKD
Switching from NetworkManager to SYSTEMD-NETWORKD is actually very simple (and vice versa).
First, deactivate the NetworkManager service as follows, and then enable SYSTEMD-NETWORKD.
$ sudo systemctl disable NetworkManager
$ sudo systemctl enable SYSTEMD-NETWORKD
You also have to enable the Systemd-resolved service, SYSTEMD-NETWORKD use it for domain resolution. The service also implements a caching-type DNS server.
$ sudo systemctl enable systemd-resolved
$ sudo systemctl start systemd-resolved
When it starts, Systemd-resolved creates its own resolv.conf in the/RUN/SYSTEMD directory somewhere. However, it is more common to store DNS parsing information in/etc/resolv.conf, and many applications will rely on/etc/resolv.conf. So for compatibility, create a symbolic link to/etc/resolv.conf in the following way.
$ sudo rm/etc/resolv.conf
$ sudo ln-s/run/systemd/resolve/resolv.conf/etc/resolv.conf
Configuring Network Connections with SYSTEMD-NETWORKD
To configure network services with SYSTEMD-NETWORKD, you must specify a configuration information text file with the. network extension. These network configuration files are saved to/etc/systemd/network and loaded from here. When there are multiple files, SYSTEMD-NETWORKD is loaded and processed in alphabetical order.
First create the/etc/systemd/network directory.
$ sudo mkdir/etc/systemd/network
DHCP Network
First, configure the DHCP network. For this, you first create the following configuration file. The file name can be arbitrary, but remember that the file is processed in alphabetical order.
$ sudo vi/etc/systemd/network/20-dhcp.network
[Match]
name=enp3*
[Network]
Dhcp=yes
As you can see above, each network profile includes one or more "sections", each of which starts with [XXX]. Each section includes one or more key-value pairs. The [Match] section determines which (some) network devices are configured for this configuration file. For example, this file matches all network devices (such as ENP3S0, ENP3S1, ENP3S2, and so on) that start with ENS3 and then enables the DHCP network configuration specified in the [Network] section.
Static IP Network
If you want to assign a static IP address to a network device, create the following configuration file.
$ sudo vi/etc/systemd/network/10-static-enp3s0.network
[Match]
Name=enp3s0
[Network]
Address=192.168.10.50/24
gateway=192.168.10.1
dns=8.8.8.8
As you can guess, the Enp3s0 interface address is specified as 192.168.10.50/24, the default gateway is 192.168.10.1, and the DNS server is 8.8.8.8. The subtle point here is that the interface name Enp3s0 in fact matches the schema rules defined in the previous DHCP configuration. However, according to the lexical order, the file "10-static-enp3s0.network" is processed before "20-dhcp.network", and the static configuration for the Enp3s0 interface has a higher priority than the DHCP configuration.
Once you have finished creating the configuration file, restart the SYSTEMD-NETWORKD service or reboot the machine.
$ sudo systemctl restart SYSTEMD-NETWORKD
Run the following command to check the service status:
$ SYSTEMCTL Status Systemd-networkd
$ SYSTEMCTL Status systemd-resolved
Configuring virtual network devices with SYSTEMD-NETWORKD
SYSTEMD-NETWORKD also allows you to configure virtual network devices, such as bridges, VLANs, tunnels, Vxlan, bindings, and so on. You must configure these virtual devices in a file with the. Netdev as the extension.
Here I show how to configure a bridging interface.
Linux Network Bridge
If you want to create a Linux bridge (BR0) and add the physical interface (ETH1) to the bridge, you can build a new configuration below.
$ sudo vi/etc/systemd/network/bridge-br0.netdev
[Netdev]
Name=br0
Kind=bridge
Then configure the bridge interface Br0 and the eth1 from the interface by using the. network file as follows.
$ sudo vi/etc/systemd/network/bridge-br0-slave.network
[Match]
Name=eth1
[Network]
Bridge=br0
$ sudo vi/etc/systemd/network/bridge-br0.network
[Match]
Name=br0
[Network]
Address=192.168.10.100/24
gateway=192.168.10.1
dns=8.8.8.8
Finally, restart the SYSTEMD-NETWORKD.
$ sudo systemctl restart SYSTEMD-NETWORKD
You can use the Brctl tool to verify that the Network Bridge BR0 is created.
Summarize
When Systemd vows to become a Linux system Manager, it is not surprising that there are things like SYSTEMD-NETWORKD to manage the network configuration. But at this stage, SYSTEMD-NETWORKD looks better suited to the server environment where the network configuration is relatively stable. For desktop/notebook environments, they have a variety of temporary wired/wireless interfaces, and NetworkManager is still a better choice.
For those who want to learn more about SYSTEMD-NETWORKD, you can refer to the Official Man Handbook for a complete list of support and key points.