How to switch from NetworkManager to systemd-network on Linux

Source: Internet
Author: User

How to switch from NetworkManager to systemd-network on Linux

In the Linux World, the adoption of systemd has been a subject of heated debate, and the war between its supporters and opponents is still burning. By now, most mainstream Linux distributions have adopted systemd as the default initialization (init) system.

As the author said, as a system that "has never been completed, has never been improved, but has been following technological advances", systemd is not just an initialization process, it is designed as a broader system and service management platform, which contains an ever-growing ecosystem of core system processes, libraries, and tools.

One part of systemd is systemd-networkd, which is responsible for network configuration in the systemd ecosystem. With systemd-networkd, you can configure the basic DHCP/static IP network for the network device. It can also configure virtual network functions, such as bridges, tunnels, and VLANs. Systemd-networkd currently does not support wireless networks directly, but you can use the wpa_supplicant service to configure a wireless adapter and associate it with systemd-networkd.

In many Linux distributions, NetworkManager is still the default Network Configuration Manager. Compared with NetworkManager, systemd-networkd is still in active development and lacks some features. For example, it cannot keep your computer connected at any time through multiple interfaces as NetworkManager does. It does not provide the ifup/ifdown hook function for higher-level scripting. However, systemd-networkd works well with other systemd components (such as resolved for domain name resolution and timesyncd for NTP. 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 worth your consideration. If you strongly oppose systemd and are satisfied with NetworkManager or basic network services, it is also good.

But for those who want to try systemd-networkd, you can continue to read it and learn how to switch from NetworkManager to systemd-networkd in Linux.

 

Requirement

Systemd 210 and later provide systemd-networkd. Therefore, Linux distributions such as Debian 8 "Jessie" (systemd 215), Fedora 21 (systemd 217), Ubuntu 15.04 (systemd 219), or later are compatible with systemd-networkd.

For other releases, check your systemd version before proceeding to the next step.

  1. $ systemctl--version

 

Switch from NetworkManager to Systemd-networkd

Switching from NetworkManager to systemd-networkd is actually a very simple answer (the opposite is true ).

First, stop the NetworkManager service as follows, and then enable systemd-networkd.

  1. $ sudosystemctl disable NetworkManager
  2. $ sudosystemctl enable systemd-networkd

You also need to enable the systemd-resolved service and use it for domain name resolution. The Service also implements a cache-type DNS server.

  1. $ sudosystemctl enable systemd-resolved
  2. $ sudosystemctl start systemd-resolved

After it is started, systemd-resolved will create its own resolv. conf somewhere in the/run/systemd directory. However, it is more common to store DNS resolution information in/etc/resolv. conf. Many applications also rely on/etc/resolv. conf. Therefore, to ensure compatibility, create a symbolic link to/etc/resolv. conf as follows.

  1. $ sudorm/etc/resolv.conf
  2. $ sudoln-s /run/systemd/resolve/resolv.conf /etc/resolv.conf

 

Use systemd-networkd to configure network connections

To use systemd-networkd to configure the network service, you must specify the configuration information text file with the. network extension. These network configuration files are saved to/etc/systemd/network and loaded from here. When multiple files exist, systemd-networkd loads and processes them one by one in alphabetical order.

First, create the/etc/systemd/network directory.

  1. $ sudomkdir/etc/systemd/network

 

DHCP Network

First, configure the DHCP network. First, create the following configuration file. The file name can be arbitrary, but remember that the file is processed alphabetically.

  1. $ sudovi/etc/systemd/network/20-dhcp.network
  1. [Match]
  2. Name=enp3*
  3. [Network]
  4. DHCP=yes

As you can see above, each network configuration file contains one or more "sections", and each "section" starts with [XXX. Each section contains one or more key-value pairs.[Match]Which (some) network device is configured in this configuration file. For example, this file matches all Network devices whose names start with ens3 (such as enp3s0, enp3s1, and enp3s2) for the matched interfaces, and then enables the DHCP Network configuration specified in [Network.

 

Static IP Network

If you want to assign a static IP address to the network device, create the following configuration file.

  1. $ sudovi/etc/systemd/network/10-static-enp3s0.network
  1. [Match]
  2. Name=enp3s0
  3. [Network]
  4. Address=192.168.10.50/24
  5. Gateway=192.168.10.1
  6. DNS=8.8.8.8

As you guessed, the enp3s0 interface address will be specified as 192.168.10.50/24, the default gateway is 192.168.10.1, And the DNS server is 8.8.8.8.8. The subtle point here is that the interface name enp3s0 actually matches the Pattern Rule defined in the previous DHCP configuration. However, according to the word order, the file "10-static-enp3s0.network" is processed before "20-dhcp.network". The static configuration of the enp3s0 interface has a higher priority than the DHCP configuration.

Once you have created the configuration file, restart the systemd-networkd service or restart the machine.

  1. $ sudosystemctl restart systemd-networkd

Run the following command to check the service status:

  1. $ systemctl status systemd-networkd
  2. $ systemctl status systemd-resolved

 

Use systemd-networkd to configure virtual network devices

Systemd-networkd also allows you to configure virtual network devices, such as bridges, VLANs, tunnels, VXLAN, and bindings. You must configure these virtual devices in a file with the. netdev extension.

Here I demonstrate how to configure a bridge interface.

 

Linux Bridge

If you want to create a Linux bridge (br0) and add the physical interface (eth1) to the bridge, you can create the following configuration.

  1. $ sudovi/etc/systemd/network/bridge-br0.netdev
  1. [NetDev]
  2. Name=br0
  3. Kind=bridge

Configure br0 and eth1.

  1. $ sudovi/etc/systemd/network/bridge-br0-slave.network
  1. [Match]
  2. Name=eth1
  3. [Network]
  4. Bridge=br0
  1. $ sudovi/etc/systemd/network/bridge-br0.network
  1. [Match]
  2. Name=br0
  3. [Network]
  4. Address=192.168.10.100/24
  5. Gateway=192.168.10.1
  6. DNS=8.8.8.8

Finally, restart systemd-networkd.

  1. $ sudosystemctl restart systemd-networkd

You can use the brctl tool to verify whether the bridge br0 has been created.

 

Summary

When systemd vowed to become a Linux system manager, it was not surprising that there were something similar to systemd-networkd to manage network configurations. However, at this stage, systemd-networkd seems to be more suitable for server environments with relatively stable network configurations. For desktop/notebook environments, they have a variety of temporary Wired/wireless interfaces, and NetworkManager is still a good choice.

For more information about systemd-networkd, see the official man manual for a complete list of support and key points.

Via: http://xmodulo.com/switch-from-networkmanager-to-systemd-networkd.html

Author: Dan Nanni Translator: ictlyh Proofreader: wxy

This article was originally compiled by LCTT and launched with the honor of Linux in China

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.