Overview
This topic describes the impacts of using the traditional network-scripts service versus the systemd-networkd service on Alibaba Cloud Linux 2 instances and explains how to switch between them.
Details
Before you begin:
When performing high-risk operations, such as modifying an instance or its data, ensure data security by using disaster recovery and fault tolerance measures.
Before you modify configurations or data for an instance (including but not limited to ECS and RDS), create a snapshot or enable features like RDS log backup.
If you have provided credentials or other sensitive information on the Alibaba Cloud platform, change them immediately.
Network services on Alibaba Cloud Linux 2 instances
For Alibaba Cloud Linux 2 instances created from the following images, the default network service is changed from systemd-networkd to network-scripts to improve compatibility and align with common user practices. This change is not automatically applied to existing instances, which continue to use systemd-networkd. If you want to switch the network service on an existing instance to network-scripts, see Switch from systemd-networkd to network-scripts.
Base image: aliyun_2_1903_x64_20G_alibase_20210208.vhd
AMD image: aliyun_2_1903_x64_20G_uefi_alibase_20210218.vhd
Local image: aliyun_2_1903_x64_20G_nocloud_alibase_20210218.vhd
Trusted image: aliyun_2_1903_x64_20G_secured_alibase_20210218.vhd
Quick start image: aliyun_2_1903_x64_20G_qboot_alibase_20210218.vhd
MLPS 2.0 Level 3 compliant image: aliyun_2_1903_x64_20G_dengbao_alibase_20210218.vhd
Switch from systemd-networkd to network-scripts
Impacts of switching the network service
Impact on existing instances
If you purchase new instances, their network configuration mode will be different from your existing instances. We recommend that you switch the network service on your existing instances from
systemd-networkdtonetwork-scriptsfor consistency.Change in startup speed
The traditional
network-scriptsnetwork service uses shell scripts for network configuration, which is less efficient. With no special configurations, an instance usingnetwork-scriptstakes 2 to 4 seconds longer to start and become accessible over SSH than one using thesystemd-networkdnetwork service.If the slower startup speed is unacceptable and you do not require
network-scriptscompatibility, you can switch from network-scripts to systemd-networkd. For troubleshooting, see Common systemd-networkd issues and solutions.
Change in network configuration file path
The original network configuration file path is
/etc/systemd/network. After the switch, the path changes to the traditional/etc/sysconfig/network-scripts/directory. To learn about the differences between the configuration files, see Parameter differences between network-scripts and systemd-networkd.Change in network service restart command
For the
systemd-networkdnetwork service, run the following command to restart the network service:sudo systemctl restart systemd-networkdAfter you switch to the
network-scriptsnetwork service, run the following command to restart the network service:sudo systemctl restart network
Switch existing instances to network-scripts
Before you proceed, make sure you understand the impacts of switching the network service.
Important: This operation involves network configuration and may cause network connectivity loss if performed incorrectly. To prevent data loss or network risks from misconfiguration, create a snapshot for the system disk of your Linux instance. For instructions, see Create a snapshot for a disk.
The steps you take depend on whether you want to keep the old
resolv.conffile:If you want to keep the old
resolv.conffile, follow these steps:Run the following command to back up the
resolv.confsoft link:mv /etc/resolv.conf /etc/resolv.conf.bakRun the following command to create a new
resolv.conffile from the backup content:cat /etc/resolv.conf.bak > /etc/resolv.confRun the following command to lock the
resolv.conffile and prevent it from being modified:chattr +i /etc/resolv.conf
If you do not need to keep the old
resolv.conffile, run the following command to delete it:rm /etc/resolv.confNoteNote:
After starting the
network.serviceservice, the system automatically generates a newresolv.conffile.For more information about the
systemd-resolvedservice, see systemd-resolved DNS service.
Run the following commands in sequence to switch the network service:
systemctl enable network systemctl disable systemd-networkd systemctl disable systemd-resolvedRun the following command to restart the instance:
rebootRun the following command to confirm that the
network-scriptsservice has started successfully:systemctl status network
Switch from network-scripts to systemd-networkd
If system startup speed is a priority for you, and you are aware of the known issues and risks associated with systemd-networkd, you can follow these steps to switch your network service from network-scripts to systemd-networkd.
Important: This operation involves network configuration and may cause network connectivity loss if performed incorrectly. To prevent data loss or network risks from misconfiguration, create a snapshot for the system disk of your Linux instance. For instructions, see Create a snapshot for a disk.
The steps you take depend on whether you want to keep the old
resolv.conffile:If you want to keep the old
resolv.conffile, follow these steps:Run the following command to back up the
resolv.conffile:cp /etc/resolv.conf /etc/resolv.conf.bakRun the following command to lock the
resolv.conffile and prevent it from being modified:chattr +i /etc/resolv.conf
If you do not need to keep the old
resolv.conffile, follow these steps:Run the following command to delete the old
resolv.conffile:rm /etc/resolv.confRun the following command to create a soft link for the
resolv.conffile:ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
Run the following command to confirm that the network interface configuration file exists and is valid:
cat /etc/systemd/network/10-eth0.networkThe system displays output similar to the following:
[Match] Name=eth0 [Network] DHCP=yes [DHCP] UseDNS=yesRun the following commands in sequence to switch the network service:
systemctl disable network.service systemctl enable systemd-networkd systemctl enable systemd-resolvedRun the following command to restart the instance:
rebootRun the following command to confirm that the
systemd-networkdservice has started successfully:systemctl status systemd-networkd
Common systemd-networkd issues and solutions
The following sections describe common issues when using the systemd-networkd network service and provide solutions.
Default routes for multiple network interfaces
Description | Solution |
If you use a wildcard match in the | To prevent the system from automatically adding a default route for specific network interfaces, configure each network interface individually. For instructions, see Configure an elastic network interface. |
systemd-resolved occupies port 5355
Description | Solution |
By default, the | To free up port 5355, change the Note Note:
|
Intermittent DNS resolution timeouts
Description | Cause | Solution |
|
|
|
IP forwarding configuration failure
Description | Cause | Solution |
Even when the system's default network forwarding setting in sysconfig is | The | To enable IP forwarding:
|
Parameter differences between network-scripts and systemd-networkd
Parameter | network-scripts | systemd-networkd | Notes |
IP | Configuration file: | Configuration file: |
|
Gateway | Configuration file: | Configuration file: | N/A |
DNS | Configuration file: | Configuration file: Note Note: This file is a soft link to | To modify the DNS configuration, see How to customize DNS configurations in an Alibaba Cloud Linux 2 instance by modifying the /etc/resolv.conf file. |
Applies to
ECS