すべてのプロダクト
Search
ドキュメントセンター

:How to switch network services and impacts on instances running Alibaba Cloud Linux 2

最終更新日:Mar 06, 2025

Overview

This topic describes the impacts of using traditional network script network services and systemd-networkd network services, and how to change the related configuration of instances running Alibaba Cloud Linux 2.

Background information

説明

Please note the following points.

  • Before performing high-risk operations such as changing instance settings or data, it is recommended to verify the disaster recovery and fault tolerance capabilities of the instance to ensure data security.

  • You can change the settings and data of instances, including ECS (Elastic Compute Service) and ApsaraDB RDS instances. It is recommended to create snapshots or enable RDS log backup before changing instance settings or data.

  • If you authorize or submit sensitive information such as login accounts or passwords in the Alibaba Cloud Management Console, it is recommended to change the information in a timely manner.

Network services used by Alibaba Cloud Linux 2 instances

By default, the network services of instances using the following versions of Alibaba Cloud Linux 2 images are switched from systemd-networkd to network scripts to improve compatibility with configuration habits. Existing instances running Alibaba Cloud Linux 2 use the systemd-networkd network configuration mode because these existing instances cannot automatically switch their network services. For more information on how to switch the network services of existing instances running Alibaba Cloud Linux 2 to network-scripts network services, see the section "How to switch network services from systemd-networkd to network-scripts" in this topic.

  • Base image: aliyun_2_1903_x64_20G_alibase_20210208.vhd

  • AMD-compatible 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 image: aliyun_2_1903_x64_20G_dengbao_alibase_20210218.vhd

How to switch network services from systemd-networkd to network-scripts

Impacts of switching network services

  • Impact on existing instances When purchasing a new instance, the network configuration mode of existing instances differs from that of the new instance. It is recommended to switch the network services of existing instances from systemd-networkd to network-scripts.

  • Impact on startup speed

    • Instances configured with traditional network script network services use shell scripts to configure the network. This reduces execution efficiency. If no special settings are applied to the network interface controller (NIC) of these instances, they take 2 to 4 seconds longer to start during the instance startup process from instance creation to instance login using SSH compared to instances configured with systemd-networkd network services.

    • If you cannot accept lower startup speed and can accept network configuration modes incompatible with network scripts, you can switch to systemd-networkd by going to the section "How to switch network services from network-scripts to systemd-networkd" in this topic. For more information on issues related to systemd-networkd, see the section "Common issues and solutions for systemd-networkd" in this topic.

  • Impact on the path of network configuration files Before switching network services, the original path is /etc/systemd/network. If you switch network services to network-scripts, you need to revert to the traditional path /etc/sysconfig/network-scripts/ . For more information on the differences in configuration items between the two configuration files, see the section "Differences in configuration items between network-scripts and systemd-networkd" in this topic.

  • Impact on network service restart commands

    • For instances configured with systemd-networkd, run the following command to restart the network service: sudo systemctl restart systemd-networkd

    • For instances configured with network scripts, run the following command to restart the network service: sudo systemctl restart network

Switching network services of existing instances to network-scripts

Before performing the following operations, ensure that you understand the impacts of switching network services.

説明

Note: The following operations involve network configuration. Accidental operations may cause network disconnection. To avoid data security and network risks caused by accidental operations, create a snapshot of the system disk of the Linux instance. For more information on how to create snapshots, see "Creating disk snapshots".

  1. Run the following command to complete the configuration based on whether the original resolv.conf configuration file is retained.

    • If the original resolv.conf configuration file is retained, perform the following operations.

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

        mv /etc/resolv.conf /etc/resolv.conf.bak

      2. Run the following command to write the contents of the backup file to the new resolv.conf configuration file:

        cat /etc/resolv.conf.bak > /etc/resolv.conf

      3. Run the following command to lock the resolv.conf configuration file and protect the resolv.conf configuration file:

        chattr + i /etc/resolv.conf

    • If the original resolv.conf configuration file is not retained, perform the following operation to delete the original resolv.conf configuration file:

      rm /etc/resolv.conf
      説明

      Note:

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

    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 verify whether the network service of the instance has been switched to network-scripts:

    systemctl status network

How to switch network services from network-scripts to systemd-networkd

If you want to speed up startup and specify known issues and risks of sitemd-networkd network services, you can perform the following operations to switch network services from network-scripts to systemd-networkd.

説明

Note: The following operations involve network configuration. Accidental operations may cause network disconnection. To avoid data security and network risks caused by accidental operations, create a snapshot of the system disk of the Linux instance. For more information on how to create snapshots, see "Creating disk snapshots".

  1. Run the following command to complete the configuration based on whether the original resolv.conf configuration file is retained.

    • If the original resolv.conf configuration file is retained, perform the following operations.

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

        cp /etc/resolv.conf /etc/resolv.conf.bak

      2. Run the following command to lock the resolv.conf configuration file and protect the resolv.conf configuration file:

        chattr + i /etc/resolv.conf

    • If the original resolv.conf configuration file is not retained, perform the following operations.

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

        rm /etc/resolv.conf

      2. Run the following command to generate a symbolic link for the resolv.conf configuration file:

        ln -sf /Run /systemd/resolve/resolv.conf /etc/resolv.conf

  2. Run the following command to ensure that the network interface configuration file exists and is valid:

    cat /etc/systemd/networ k/10-eth0.net work

    The command output similar to the following is returned:

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

  3. Run the commands in sequence to switch network services:

    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 verify that the systemd-networkd network service has started:

    systemctl status systemd-networkd

Common issues and solutions for systemd-networkd

The following sections describe common issues and solutions when using systemd-networkd network services. You can select the corresponding solution based on the issue.

Default route settings for multiple NICs

Description

Solution

If the following network settings are used in the [Match] section of the /etc/systemd/networ k/XX-ethN.net work configuration file, systemd-networkd automatically sets the default route for all NICs.

[Match]
Name=eth*

[Network]
DHCP=yes

[DHCP]
UseDNS=yes 

For more information, see the section "ENI settingsENI settings for instances running Alibaba Cloud Linux 2" in the topic "". Configure each NIC individually as needed to avoid automatically setting the default route on specified NICs.

UDP port 5355 on systemd-resolved

Description

Solution

By default, systemd-resolved allows the Domain Name System (DNS) service to listen on and occupy port 5355.

If you want to close port 5355, replace LLMNR=yes with LLMNR=no in the /etc/systemd/resolved.conf configuration file.

[Resolve]
# DNS=
# FallbackDNS=XXXXX
LLMNR=yes 
説明

Note:

  • LLMNR=yes line is commented out, remove the number sign (#) in front of the line.

  • If the LLMNR=yes line is not included in the configuration file, add the LLMNR=yes line to the [Resolve] section.

Intermittent timeout of DNS domain name resolution

Description

Cause

Solution

  • If intermittent timeout of DNS domain name resolution occurs on instances running Alibaba Cloud Linux 2 or CentOS, the [Name or service not known] message is displayed. This is a known issue with a provided solution. For more information, see the section "Image FAQHow to handle CentOS DNS resolution timeouts" in the topic "".

  • etc/resolv.confoptions timeout:2 attempts: 3 rotate single-request-reopenoptions settings to the file, the settings cannot be persisted on Alibaba Cloud Linux 2 instances configured with systemd-resolve. After restarting the instance or systemd-resolved network service, the settings are invalid.

  • The systemd-resolved network management tool relies on systemd-resolved to manage DNS domain name resolution configurations. However, systemd-resolved cannot automatically set the above options parameters. You can only manually set them in the /etc/resolv.conf file.

  • /etc/resolv.conf file is by default a symbolic link file pointing to the /run/systemd/resolve/resolv.conf file. You cannot lock the /etc/resolv.conf file with the chattr + i command. When the instance or network service is restarted, the information written to the /etc/resolv.conf file is lost.

Failure of IP forwarding settings

Description

Cause

Solution

The default network forwarding setting of sysconfig is default.forwarding==1. However, the forwarding parameter of the new NIC is automatically set to 0, causing IP forwarding of the new NIC to fail.

Because the systemd-networkd configuration does not include IPForward=no, the normal initialization of inetdev_init forwarding=$default is set to forwarding=0.

Perform the following operations to add a new IP forwarding setting and enable the forwarding function.

  1. Add the line IPForward=yes to the [Network] section of the /etc/systemd/networ k/10-eth0.net work configuration file as shown in the following section:

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

  2. Run the following command to restart systemd-networkd:

    systemctl restart systemd-networkd

Differences in configuration items between network-scripts and systemd-networkd

Configuration item

network-scripts

systemd-networkd

Note

IP

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

DEVICE=eth0# Custom name of NIC
BOOTPROTO=dhcp# Method to obtain IP address:
    static: Static IP address
・dhcp: Dynamic Host Configuration Protocol (DHCP)
・bootp: Bootstrap Protocol (BOOTP)
ONBOOT=yes# Whether to activate the instance at system startup

Configuration file: /etc/systemd/networ k/10-eth0.net work

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

  • For instances configured with network scripts, the network configuration service is enabled, and the default configuration file is automatically generated.

  • For instances configured with systemd-networkd, you need to manually add the default configuration file.

Gateway

Configuration file: /etc/sysconfig/network

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

Configuration file: /etc/systemd/networ k/10-eth0.net work

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

N/A

DNS

Configuration file: /etc/resolv.conf

nameserver

Configuration file: /etc/resolv.conf

説明

Note: This file is a symbolic link pointing to the /run/systemd/resolve/resolv.conf file. For more information, see the section "Intermittent timeout of DNS domain name resolution" in this topic.

nameserver

For more information on how to change DNS, see "How to customize DNS settings for Alibaba Cloud Linux 2 instances using the /etc/resolv.conf file".

Scope of application

  • ECS