Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to change the network manager from NetworkManager to systemd-network in Linux

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to switch the network manager from NetworkManager to systemd-network in Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to switch the network manager from NetworkManager to systemd-network in Linux.

In the Linux world, the adoption of systemd has been the subject of heated debate, and the war between its supporters and opponents is still burning. Today, most major Linux distributions have adopted systemd as the default initialization init system.

As its author puts it, as a system that is "never completed, never perfected, but has always followed technological progress", systemd is no longer just an initialization process, it is designed as a broader system and service management platform, this platform is an ecosystem of growing core system processes, libraries, and tools.

Part of the systemd is systemd-networkd, which is responsible for network configuration in the systemd ecology. With systemd-networkd, you can configure a basic DHCP/ static IP network for network devices. It can also configure virtual network features such as bridges, tunnels, and VLAN. Systemd-networkd currently does not support wireless networks directly, but you can configure a wireless adapter using wpa_supplicant services and then associate it with systemd-networkd.

In many Linux distributions, NetworkManager remains the default network configuration manager. Compared with NetworkManager, systemd-networkd is still in an active development state and lacks some features. For example, it doesn't allow your computer to stay connected through multiple interfaces at any time like NetworkManager. It does not yet provide ifup/ifdown hook functions for higher-level scripting. However, systemd-networkd combines very well with other systemd components (such as resolved for domain name resolution, timesyncd for NTP, and udevd for naming). Over time, systemd-networkd will only play an increasingly important role in the systemd environment.

If you are happy with the progress made by systemd-networkd, switching from NetworkManager to systemd-networkd is something worth considering. If you are strongly against systemd and are satisfied with NetworkManager or basic network services, that's good.

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

Demand

Systemd-networkd is available in systemd 210and later. 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 distributions, check your systemd version before proceeding to the next step.

The code is as follows:

$systemctl-version

Switch from NetworkManager to Systemd-networkd

Switching from NetworkManager to systemd-networkd is actually very simple (and vice versa).

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

The code is as follows:

$sudo systemctl disable NetworkManager

$sudo systemctl enable systemd-networkd

You also need to enable the systemd-resolved service, which systemd-networkd uses for domain name resolution. The service also implements a cached DNS server.

The code is as follows:

$sudo systemctl enable systemd-resolved

$sudo systemctl start systemd-resolved

When started, systemd-resolved creates its own resolv.conf somewhere in the / run/systemd directory. However, it is more common to store DNS parsing information in / etc/resolv.conf, and many applications also rely on / etc/resolv.conf. So for compatibility, create a symbolic link to / etc/resolv.conf as follows.

The code is as follows:

$sudo rm / etc/resolv.conf

$sudo ln-s / run/systemd/resolve/resolv.conf / etc/resolv.conf

Configure the network connection 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 loads and processes them one by one alphabetically.

First create the / etc/systemd/network directory.

The code is as follows:

$sudo mkdir / etc/systemd/network

DHCP network

Let's first configure the DHCP network. For this, first create the following configuration file. You can have any file name, but remember that the files are processed in alphabetical order.

The code is as follows:

$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", and each "section" starts with [XXX]. Each section includes one or more key-value pairs. The [Match] section determines which network devices are configured for this profile. For example, this file matches all network devices whose names begin with ens3 (such as enp3s0, enp3s1, enp3s2, and so on) for matching interfaces, 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 a new configuration file below.

The code is as follows:

$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 guessed, the enp3s0 interface address will be specified as 192.168.10.50 enp3s0 24, the default gateway will be 192.168.10.1, and the DNS server will be 8.8.8.8. The subtle point here is that the interface name enp3s0 actually matches the pattern 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 of 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 restart the machine.

The code is as follows:

$sudo systemctl restart systemd-networkd

Run the following command to check the status of the service:

The code is as follows:

$systemctl status systemd-networkd

$systemctl status systemd-resolved

Configure Virtual Network Devices with systemd-networkd

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

Here I show how to configure a bridging interface.

Linux bridge

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

The code is as follows:

$sudo vi / etc/systemd/network/bridge-br0.netdev

[NetDev]

Name=br0

Kind=bridge

Then configure the bridge interface br0 and slave interface eth2 with the .network file as follows.

The code is as follows:

$sudo vi / etc/systemd/network/bridge-br0-slave.network

[Match]

Name=eth2

[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 systemd-networkd.

The code is as follows:

$sudo systemctl restart systemd-networkd

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

Thank you for reading, the above is the content of "how to switch the network manager from NetworkManager to systemd-network in Linux". After the study of this article, I believe you have a deeper understanding of how to switch the network manager from NetworkManager to systemd-network in Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report