All Products
Search
Document Center

:Change network service on Alibaba Cloud Linux 2 instances

Last Updated:Aug 11, 2026

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

Note

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-networkd to network-scripts for consistency.

  • Change in startup speed

    • The traditional network-scripts network service uses shell scripts for network configuration, which is less efficient. With no special configurations, an instance using network-scripts takes 2 to 4 seconds longer to start and become accessible over SSH than one using the systemd-networkd network service.

    • If the slower startup speed is unacceptable and you do not require network-scripts compatibility, 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-networkd network service, run the following command to restart the network service:

      sudo systemctl restart systemd-networkd

    • After you switch to the network-scripts network 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.

Note

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.

  1. The steps you take depend on whether you want to keep the old resolv.conf file:

    • If you want to keep the old resolv.conf file, follow these steps:

      1. Run the following command to back up the resolv.conf soft link:

        mv /etc/resolv.conf /etc/resolv.conf.bak
      2. Run the following command to create a new resolv.conf file from the backup content:

        cat /etc/resolv.conf.bak > /etc/resolv.conf
      3. Run the following command to lock the resolv.conf file and prevent it from being modified:

        chattr +i /etc/resolv.conf
    • If you do not need to keep the old resolv.conf file, run the following command to delete it:

      rm /etc/resolv.conf
      Note

      Note:

      • After starting the network.service service, the system automatically generates a new resolv.conf file.

      • For more information about the systemd-resolved service, see systemd-resolved DNS service.

  2. Run the following commands in sequence to switch the network service:

    systemctl enable network
    systemctl disable systemd-networkd
    systemctl disable systemd-resolved
  3. Run the following command to restart the instance:

    reboot
  4. Run the following command to confirm that the network-scripts service 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.

Note

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.

  1. The steps you take depend on whether you want to keep the old resolv.conf file:

    • If you want to keep the old resolv.conf file, follow these steps:

      1. Run the following command to back up the resolv.conf file:

        cp /etc/resolv.conf /etc/resolv.conf.bak
      2. Run the following command to lock the resolv.conf file and prevent it from being modified:

        chattr +i /etc/resolv.conf
    • If you do not need to keep the old resolv.conf file, follow these steps:

      1. Run the following command to delete the old resolv.conf file:

        rm /etc/resolv.conf
      2. Run the following command to create a soft link for the resolv.conf file:

        ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
  2. Run the following command to confirm that the network interface configuration file exists and is valid:

    cat /etc/systemd/network/10-eth0.network

    The system displays output similar to the following:

    [Match]
    Name=eth0
    
    [Network]
    DHCP=yes
    
    [DHCP]
    UseDNS=yes
  3. Run the following commands in sequence to switch the network service:

    systemctl disable network.service
    systemctl enable systemd-networkd
    systemctl enable systemd-resolved
  4. Run the following command to restart the instance:

    reboot
  5. Run the following command to confirm that the systemd-networkd service 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 /etc/systemd/network/XX-ethN.network configuration file, as shown in the [Match] section of the example below, systemd-networkd automatically adds a default route for all matching network interfaces. This can override your custom route configurations and cause network connectivity issues.

[Match]
Name=eth*

[Network]
DHCP=yes

[DHCP]
UseDNS=yes

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 systemd-resolved service starts a DNS listener that uses UDP port 5355.

To free up port 5355, change the LLMNR=yes setting to LLMNR=no in the /etc/systemd/resolved.conf file.

[Resolve]
#DNS=
#FallbackDNS=XXXXX
LLMNR=yes
Note

Note:

  • If the LLMNR=yes line is commented out, remove the hash symbol (#) from the beginning of the line.

  • If the file does not contain the LLMNR=yes setting, add it under the [Resolve] section.

Intermittent DNS resolution timeouts

Description

Cause

Solution

  • Instances, such as those running Alibaba Cloud Linux 2 or CentOS, may experience intermittent DNS resolution timeouts. The system returns a Name or service not known error. This is a known issue. For the solution, see the How do I resolve CentOS DNS resolution timeouts section in Image FAQ.

  • On Alibaba Cloud Linux 2 instances that use the systemd-resolved service, adding the Alibaba Cloud options configuration options timeout:2 attempts:3 rotate single-request-reopen to the etc/resolv.conf file is not a persistent solution. This configuration is lost when the system or the systemd-resolved service restarts.

  • The systemd-networkd tool relies on systemd-resolved to manage DNS configurations, but systemd-resolved cannot automatically configure the options parameter. You must add this parameter to the /etc/resolv.conf file manually.

  • By default, the /etc/resolv.conf file is a soft link to the /run/systemd/resolve/resolv.conf file. You cannot use the chattr +i command to lock it. Any changes made to the /etc/resolv.conf file are lost when the system or network service restarts.

IP forwarding configuration failure

Description

Cause

Solution

Even when the system's default network forwarding setting in sysconfig is default.forwarding==1, the forwarding setting for a newly created network interface is automatically changed to 0. This prevents IP forwarding on the new network interface.

The systemd-networkd configuration is missing the IPForward=yes setting. This causes the forwarding=$default parameter to be reset to forwarding=0 after it is initialized by inetdev_init.

To enable IP forwarding:

  1. In the /etc/systemd/network/10-eth0.network configuration file, add IPForward=yes to the [Network] section, as shown in the following example:

    [Match]
    Name=eth0
    
    [Network]
    DHCP=yes
    IPForward=yes
    
    [DHCP]
    UseDNS=yes
  2. Run the following command to restart the systemd-networkd service:

    systemctl restart systemd-networkd

Parameter differences between network-scripts and systemd-networkd

Parameter

network-scripts

systemd-networkd

Notes

IP

Configuration file: /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 # Device alias
BOOTPROTO=dhcp # IP acquisition method:
·    static: Static IP address
·    dhcp: DHCP protocol
·    bootp: BOOTP protocol
ONBOOT=yes # Activates the device on system startup.

Configuration file: /etc/systemd/network/10-eth0.network

[Match]
·    Name=eth0
[Network]
·    DHCP=yes
[DHCP]
·    UseDNS=yes

  • When network-scripts starts, it automatically generates a default configuration file.

  • For systemd-networkd, you must add a default configuration file manually.

Gateway

Configuration file: /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=xxx
GATEWAY=192.168.X.X

Configuration file: /etc/systemd/network/10-eth0.network

[Network]
·    Gateway=192.168.X.X
·    DNS=

N/A

DNS

Configuration file: /etc/resolv.conf

nameserver

Configuration file: /etc/resolv.conf

Note

Note: This file is a soft link to /run/systemd/resolve/resolv.conf. Be aware of the persistence issue described in Intermittent DNS resolution timeouts.

nameserver

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