You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Network interface and IP address
Configuring secondary network interfaces for ECS instances
Copy page
Download PDF
Configuring secondary network interfaces for ECS instances
Applicable scenarios​
After you mount a secondary network interface to an ECS instance, except for the images listed below, other images may not automatically identify the primary private IP address of the secondary network interface or add the corresponding routes. As a result, the secondary network interface cannot work as expected. You need to configure the secondary network interface and routes for the ECS instance.​
​
Operating system type​
Version​
CentOS​
CentOS 8.x, CentOS Stream​
Fedora​
Fedora 37 64 bit​
Windows Server​
All versions​
​
Prerequisites​
This procedure is required only if the image used by the ECS instance does not identify the primary private IPv4 address of the secondary network interface. Otherwise, no operations are required.​
tip​
Commands for viewing IP addresses:​
  • Linux: Execute the ip address show command in the command line.​
  • Windows: Execute the ipconfig command in the command line.​
Configure secondary network interfaces​
Tool-based configuration​
The VolcanoEngine platform provides you with an automatic configuration tool for secondary network interfaces. Non-lightweight bare metal instances based on the following image types can use the tool to configure secondary network interfaces with a few clicks.​
​
Operating system type​
Version​
CentOS​
CentOS 7.1–7.9 64 bit​
Ubuntu​
  • Ubuntu Server 22.04 LTS 64 bit​
  • Ubuntu Server 20.04 LTS 64 bit​
  • Ubuntu Server 18.04 LTS 64 bit​
  • Ubuntu Server 16.04 LTS 64 bit​
​
Limits​
After you configure a secondary network interface by using the automatic configuration tool, you can manage the secondary network interface only by using the default network management tool of the image.​
​
Operating system type​
Version​
Default network management tool​
CentOS​
  • CentOS 7.1-7.9 64 bit​
  • ifup ethx​
  • ifdown ethx​
Ubuntu​
  • Ubuntu Server 16.04 LTS 64 bit​
  • Ubuntu Server 22.04 LTS 64 bit​
  • Ubuntu Server 20.04 LTS 64 bit​
  • Ubuntu Server 18.04 LTS 64 bit​
  • ifdown ethx​
  • ifconfig ethx up​
  • ifconfig ethx down​
​
tip​
If you have edited the configuration file of the secondary network interface according to the manual configuration guidelines, you need to delete the manually added configuration before you can use the automatic configuration tool for secondary network interfaces.​
​
CentOS 7
Ubuntu
​
For instances running CentOS 7.1 to 7.9, you can configure the secondary network interface by using the automatic configuration tool.​
  1. For CentOS 7 systems where the network service type is set to network-scripts, you can execute the following commands to download and install the automatic configuration tool for secondary network interfaces.​
  • ​
    wget http://mirrors.ivolces.com/extra-tools/centos/7/rpms/multi-nic-hotlog-for-centos7-v1.0.1-1.ve1.x86_64.rpm​
    yum install ./multi-nic-hotlog-for-centos7-v1.0.1-1.ve1.x86_64.rpm​
    ​
  1. After you install the tool, execute the reboot command to restart the instance. After a restart, the tool automatically completes the secondary network interface configuration.​
  1. Execute the ip address show command to check whether the primary private IP address of the secondary network interface can be identified.​
  • As shown in the following figure, the primary private IP address of the secondary network interface eth1 is identified as expected.​
  • ​​​
  1. Log in to the ECS instance to check whether the automatically generated routes for the secondary network interface meet your business requirements. If they do not meet your business requirements, you can modify network interface routes.​
​
Manual configuration​
If the images of your instance do not support the automatic configuration tool, you need to manually configure the secondary network interface.​
​
Debian/veLinux
OpenSUSE
Ubuntu
​
Debian 9, Debian 10, Debian 11, and veLinux 1.0 system configuration​
  1. Remotely connect to and log in to the ECS instance. For more information, see Logging in to Linux instances.​
  1. Execute the following command to open the configuration file for the eth1 network interface.​
  • vi /etc/network/interfaces​
  1. Press i to enter the edit mode, and add configuration information to the configuration file for the eth1 network interface.​
  • After the configuration is complete, press Esc on the keyboard, input :wq, then press the Enter key to save the changes and exit.​
eth1 is the newly configured network interface.​
  • ​
    auto eth0​
    iface eth0 inet dhcp​
    ​
    auto eth1​
    iface eth1 inet dhcp​
    ​
  1. Run the following command to view the network interface configuration file and confirm the changes.​
  • cat /etc/network/interfaces​
  1. Execute the following command to restart the network service.​
  • systemctl restart networking​
  1. You can execute the ip address show command to check whether the primary private IP address of the eth1 network interface is identified.​
  • As shown in the following figure, the primary private IP address of the eth1 secondary network interface is identified as expected.​
  • ​​​
​
Subsequent operation​
After you configure a secondary network interface, the operating system automatically generates routes for the secondary network interface. You can log in to the ECS instance to check whether the automatically generated routes for the secondary network interface meet your business requirements. If they do not meet your business requirements, you can modify network interface routes.​
tip​
Commands for viewing routes:​
  • Linux: Execute the ip route command in the command line.​
  • Windows: Execute the route printcommand in the command line.​
Modify network interface routes​
After you log in to the ECS instance, if you find that the current network interface routes do not meet your business requirements, you can refer to the following instructions to modify the network interface routes.​
Modify routes in the command line​
You can quickly modify routing information of an ECS instance in the command line.​
tip​
Routes modified in a Linux instance by using this method become invalid after the instance restarts. To address this, you can create a script that automatically adds the required routes when the instance starts.​
​
Modify network interface routes for a Linux instance
Modify network interface routes for a Windows instance
​
For the existing ECS instance vm-1, the primary private IP address of the primary network interface eth0 is 192.168.1.11, and the primary private IP address of the newly associated secondary network interface eth1 is 192.168.2.2.​
  1. Remotely connect to and log in to the ECS instance. For more information, see Logging in to Linux instances.​
  1. Execute the following command to check whether the current routes meet your business requirements.​
  • ​
    route -n​
    ​
  • Sample output:​
  • ​​​
  • If the current routes meet your business requirements, no further operations are required.​
  • If the current routes do not meet your business requirements, add or remove route forwarding policies based on your business requirements by referring to Step 3.​
  1. You can execute the following command to view route-related commands.​
  • ​
    ip route help​
    ​
  • This topic describes commonly used commands for adding and removing static routes. Example:​
  • ​
    ip -4 route <Policy> <Destination CIDR block> via <Gateway address> dev <Interface> metric <Priority>​
    ​
  • ​
    Parameter​
    Description​
    <Policy>​
    The command-based action. Valid values:​
    • add: Add a route.​
    • del: Remove a route.​
    <Destination CIDR block>​
    Routes are matched according to the longest mask principle: the longer the subnet mask, the higher its priority for routing.​
    <Gateway address>​
    The gateway address of the specified network interface.​
    <Interface>​
    The specified network interface.​
    <Priority>​
    When the destination CIDR block is the same, a route with a smaller value of the metric parameter has a higher priority.​
    ​
  1. For example, when the secondary network interface eth1 is associated with an EIP, the EIP of the secondary network interface must be used by default to access the Internet.​
  • Execute the following commands to add or remove route forwarding policies for eth1 and eth0.​
  • ​
    ip -4 route add 0.0.0.0/0 via 192.168.2.1 dev eth1 metric 98​
    ip -4 route add 0.0.0.0/0 via 192.168.1.1 dev eth0 metric 99​
    ip -4 route del 0.0.0.0/0 via 192.168.1.1 dev eth0 metric 0​
    ​
​
Modify routes by using a script​
You can add a route configuration script for a Linux ECS instance to automatically configure routing information when the instance starts.​
​
CentOS/RHEL/Rocky Linux/AlmaLinux
Ubuntu
veLinux/Debian
​
  • CentOS 7.1​
  1. Execute the following command to create the /etc/sysconfig/network-scripts/route-<Interface> file.​
  • ​
    vim /etc/sysconfig/network-scripts/route-eth1​
    ​
  1. Press the i key to enter the edit mode, and add the following content to configure routes.​
  • ​
    0.0.0.0/0 via 192.168.2.1 dev eth1 metric 98​
    ​
  1. Press the Esc key to exit the edit mode, enter :wq, and then press Enter to save the changes and exit the file.​
  1. Similarly, configure the routes for eth0.​
  1. Execute the following command to restart the ECS instance.​
  • ​
    reboot​
    ​
  1. Execute the following command to view the routes.​
  • ​
    route -n​
    ​
  • Procedure for modifying the routes by using a script when CentOS Stream 9, RHEL 9, CentOS Stream 8, CentOS 8, RHEL 8, Rocky Linux, or AlmaLinux is used:​
  1. Create a routing configuration script file.​
  1. Execute the following command to create a script file named route_config.sh.​
  • ​
    vim /root/route_config.sh​
    ​
  1. Press the i key to enter the edit mode, and then copy and paste the following content into the file.​
  • ​
    #!/bin/bash​
    function add_ip_route() {​
    local retries=0​
    until /usr/sbin/ip -4 route add default via 192.168.***.**1 dev eth1 table 100; do​
    ((retries++))​
    if [ $retries -gt 10 ]; then​
    echo "Add IP route failed."​
    return 1​
    fi​
    sleep 3​
    done​
    return 0​
    }​
    ​
    function add_ip_rule() {​
    local retries=0​
    until /usr/sbin/ip -4 rule add from 192.168.***.4 lookup 100; do​
    ((retries++))​
    if [ $retries -gt 10 ]; then​
    echo "Add IP rule failed."​
    return 1​
    fi​
    sleep 3​
    done​
    return 0​
    }​
    ​
    add_ip_route​
    if [ $? -ne 0 ]; then​
    exit 1​
    fi​
    ​
    add_ip_rule​
    if [ $? -ne 0 ]; then​
    exit 1​
    fi​
    ​
tip​
This script is used to create a routing table for the secondary network interface and a corresponding routing policy associated with that table. Where:​
  • Secondary network interface name: eth1.​
  • Gateway address: 192.168.***.**1.​
  • Primary IPv4 address of the secondary network interface: 192.168.***.4.​
  1. Press the Esc key to exit the edit mode, enter :wq, and then press Enter to save the changes and close the file.​
  1. Execute the following command to add executable permission to the script file.​
  • ​
    chmod +x route_config.sh​
    ​
  1. Execute the following command to configure the default route.​
  • ​
    sh /root/route_config.sh​
    ​
  1. Configure automatic routing updates when the instance starts.​
  1. Execute the following command to open the /etc/rc.local file.​
  • ​
    vim /etc/rc.local​
    ​
  1. Press the i key to enter the edit mode and add the following content.​
  • ​
    sh /root/route_config.sh​
    ​
  1. Press the Esc key to exit the edit mode, enter :wq, and then press Enter to save the changes and close the file.​
  1. Execute the following command to add executable permission to the script file.​
  • ​
    chmod +x /etc/rc.local​
    ​
  1. Execute the following command to restart the ECS instance.​
  • ​
    reboot​
    ​
  1. Execute the following command to view the configured routes and IP rules.​
  • ​
    ip route list table 100 && ip rule list​
    ​
tip​
Replace table 100 with the actual route table name configured in your script.​
​
Last updated: 2026.06.18 17:49:50