You can assign one or more secondary private IP addresses to an elastic network interface (ENI), whether it is a primary or secondary interface, for scenarios such as multi-application hosting, failover, and load balancing. This topic describes how to assign, configure, and release secondary private IP addresses.
Secondary private IP
If the single primary private IP of an elastic network interface (including the primary network interface and secondary elastic network interfaces) on an ECS instance is not sufficient for your requirements, you can assign multiple secondary private IPs to it. The figure below illustrates the relationship between the network interfaces and private IPs of an ECS instance.

Use cases
Common use cases for secondary private IP addresses include:
Multi-application hosting: Host multiple services on a single ECS instance by assigning a separate secondary private IP address to each application, improving instance utilization.
Failover: When an instance fails, you can detach the secondary ENI from the failed instance and attach it to a standby instance. This redirects traffic for the associated secondary private IP addresses to the standby instance.
Load balancing: Assign multiple secondary private IP addresses to an instance for load balancing, improving system scalability and performance.
Notes
The maximum number of private IP addresses that you can assign to an elastic network interface depends on its status.
If an elastic network interface is Available, you can assign up to 10 private IP addresses to it.
If an elastic network interface is Bound, the instance type determines the maximum number of private IP addresses you can assign. For details, see the Private IPv4 Addresses per ENI column in the Instance Specification Details section of the instance family documentation.
VPC security groups support a limited number of private IP addresses. Therefore, plan your secondary private IP address assignments accordingly. For more information, see Security Group Limits.
Assign a secondary private IP to an ENI
Important For an ECS instance to recognize a secondary private IP address, you must configure the address within its operating system. This configuration, detailed in Step 3, is required in addition to assigning the address through the console in Step 1.
Step 1: Assign a secondary private IP address
On the Manage ENI IP Addresses page, you can add or delete secondary private IP addresses for a target elastic network interface, which can be the primary network interface or a secondary elastic network interface of an ECS instance.
Go to ECS Console - Elastic Network Interfaces.
In the upper-left corner of the page, select a region and resource group.
On the ENIs page, find the elastic network interface to manage, and then click Manage ENI IP Addresses in the Actions column.
In the Manage ENI IP Addresses dialog box, click Add in the Secondary Private IPv4 Address or IPv6 Supported section, and then select a method to assign an IP address.
Auto-assign: The system automatically assigns an available IP address from the private IPv4 or IPv6 CIDR block of the elastic network interface.
Manually Enter: Enter a secondary private IP address. The address must be within the private IPv4 or IPv6 CIDR block of the elastic network interface.
Click OK.
Verify that the secondary private IP address is correctly assigned to the target elastic network interface.
You can confirm this on the ECS instance's elastic network interface details page.
The ENI is bound to one primary private IP address and two secondary private IPv4 addresses.
Step 2 (Optional): Attach a secondary ENI
If you want to add a secondary private IP address to a secondary elastic network interface, you must ensure that the secondary elastic network interface is bound to an ECS instance and has been configured. For more information, see Bind a secondary elastic network interface and Configure a secondary elastic network interface.
This example assigns a secondary private IP address to the primary elastic network interface of an ECS instance, so this step is not required.
Step 3: Configure the secondary private IP address
After assigning a secondary private IP address to an instance, you must also configure it in the instance's operating system. Configuration steps vary by operating system and IP address type.
Configuration example
Note This document shows how to configure a secondary private IPv4 address. For instructions on how to configure a secondary private IPv6 address, see IPv6 communication.
The following table shows the private IPv4 addresses assigned to the network interface for this example. You must replace the IP addresses in the commands and configurations with your own.
Network interface | Primary private IPv4 address | Secondary private IPv4 address 1 | Secondary private IPv4 address 2 |
primary network interface | 192.168.1.201 | 192.168.1.202 | 192.168.1.203 |
Before you begin, make sure that the instance is in the Running state. For instructions, see start an instance.
This document provides configuration steps for several common operating systems. Follow the steps for your operating system.
Linux configuration
Connect to the ECS instance.
For instructions, see Connect to a Linux instance by using Workbench.
Check the current network and routing configuration to find the default gateway and subnet mask.
View the primary private IPv4 address
Run the following command to view the network configuration:
ip a
The command output shows the current network configuration of the instance:
[root@iZxxx ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:16:3e:0e:3b:96 brd ff:ff:ff:ff:ff:ff
altname enp0s5
altname ens5
inet 192.168.1.201/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0
valid_lft 315359875sec preferred_lft 315359875sec
inet6 fe80::216:3exx:xxxx:xxxx scope link
valid_lft forever preferred_lft forever
The output indicates the following network configuration:
View the subnet mask and default gateway
Run the following command to view the routing information:
route -n
The command output shows the following information:
[root@iZufxxx9Z ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.253 0.0.0.0 UG 100 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
Based on the preceding information, the current network configuration is as follows:
Network interface | Status | Default gateway | Subnet mask | Primary private IP address | Secondary private IPv4 address 1 | Secondary private IPv4 address 2 |
eth0 (primary network interface) | UP | 192.168.1.253 | 255.255.255.0 | 192.168.1.201 (auto-configured) | 192.168.1.202 (not recognized, requires configuration) | 192.168.1.203 (not recognized, requires configuration) |
Choose one of the following methods to configure the secondary private IPv4 addresses.
nmcli con
Note NetworkManager is a daemon on Linux systems that manages network connections and settings. It provides the nmcli command-line tool, which lets you easily manage network connections.
This method applies to all operating systems that use NetworkManager to manage network services, including but not limited to Fedora, CentOS, RHEL, Ubuntu, Debian, and systems based on these distributions.
In this example, the connection name corresponds to the eth0 network interface. You must replace the connection name with your actual connection name.
Run the following command to create a file that disables the network configuration feature of cloud-init. This prevents your configuration from being reverted after a restart. For more information, see Auto-initialize network configurations by using cloud-init.
sudo vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Add the following content:
network: {config: disabled}
Run the following command to view the current network connection information.
nmcli con show
Network connection names vary across Linux distributions. The following is an example:
[root@iZxxx ~]# nmcli con show
NAME UUID TYPE DEVICE
System eth0 5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 ethernet eth0
Run the following commands to configure the secondary private IPv4 addresses and default gateway for eth0.
sudo nmcli con modify "System eth0" ipv4.addresses 192.168.1.201/24,192.168.1.202/24,192.168.1.203/24
sudo nmcli con modify "System eth0" ipv4.gateway 192.168.1.253
Run the following command to activate the modified network connection.
sudo nmcli con up "System eth0"
If the configuration is correct, a message similar to "Connection successfully activated" appears.
Configuration files
Important Network configuration files vary depending on the Linux distribution and version.
Back up the original configuration file before you edit it.
This operation involves changing network configuration files. To avoid connectivity issues, carefully verify your changes. An incorrect configuration might make the instance unreachable.
RHEL series
Note Applicable operating systems: Alibaba Cloud Linux 2/3, CentOS 6/7/8, Red Hat 6/7/8/9, Anolis 7/8, and Fedora 33/34/35.
Example operating system: Alibaba Cloud Linux 3.2.
Example network interface: This example uses the eth0 network interface. Replace the network interface identifier with your actual identifier.
Run the following command to check if the main configuration file for the network interface exists. Each network interface has a corresponding configuration file that identifies it.
Note On some operating systems, such as Alibaba Cloud Linux 3.2, the main configuration file for the network interface is automatically generated by cloud-init and you do not need to create it manually.
On some operating systems, such as CentOS 8.5, you need to manually create the main configuration file for the network interface and configure its basic information.
ls /etc/sysconfig/network-scripts/ifcfg-eth0
If the file exists: The main configuration file for the network interface has already been created. Proceed to the next step.
If the file does not exist: Create the file and manually configure the basic information for the network interface.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
Configure the network interface name, set the IP acquisition method, and configure the primary private IPv4 address, subnet mask, and gateway information for the network interface.
In this example, if the ifcfg-eth0 file does not exist, configure it as follows:
# Network interface name, for example: eth0
DEVICE=eth0
TYPE=Ethernet
BOOTPROTO=dhcp
# Activate this network interface at system startup
ONBOOT=yes
Run the following command to configure the first secondary private IPv4 address for the eth0 network interface.
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
In this example, configure the first secondary private IPv4 address for eth0 as follows:
# Network interface name:sequential number of the secondary private IP address
DEVICE=eth0:0
TYPE=Ethernet
# Static IP
BOOTPROTO=static
# Manually configure the IPv4 address and subnet mask
IPADDR=192.168.1.202
NETMASK=255.255.255.0
Configure the second secondary private IPv4 address for the eth0 network interface
Note The process for configuring additional secondary private IP addresses is similar. Take note of the following points:
sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0:1
In this document, the configuration for the second secondary private IPv4 address for the eth0 network interface is as follows:
# Network interface name:sequential number of the secondary private IP address
DEVICE=eth0:1
TYPE=Ethernet
BOOTPROTO=static
# Manually configure the IPv4 address and subnet mask
IPADDR=192.168.1.203
NETMASK=255.255.255.0
Ubuntu 18/20
Run the following command to disable the network configuration feature of cloud-init.
Important The network configuration file (/etc/netplan/50-cloud-init.yaml) is automatically generated by cloud-init when the instance starts. To edit this file, you must first disable the network configuration feature of cloud-init. For more information, see Auto-initialize network configurations by using cloud-init.
sudo vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Add the following content:
network: {config: disabled}
Run the following command to edit the network configuration file and configure the network interface information.
sudo vim /etc/netplan/50-cloud-init.yaml
Example configuration:
network:
version: 2
ethernets:
eth0: # Network interface name
dhcp4: false # Default is DHCP. Set to false to configure the IP address manually.
match:
macaddress: 00:16:3e:16:43:xx # MAC address of your network interface
set-name: eth0
addresses:
- 192.168.1.201/24 # Primary private IP address of the network interface
- 192.168.1.202/24 # Secondary private IP address 1 of the network interface
- 192.168.1.203/24 # Secondary private IP address 2 of the network interface
gateway4: 192.168.1.253 # Default gateway
nameservers:
addresses: [223.5.5.5, 223.6.6.6] # DNS
Ubuntu 22/24 and Debian 12
Run the following command to disable the network configuration feature of cloud-init.
Important The network configuration file (/etc/netplan/50-cloud-init.yaml) is automatically generated by cloud-init when the instance starts. To edit this file, you must first disable the network configuration feature of cloud-init. For more information, see Auto-initialize network configurations by using cloud-init.
sudo vim /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
Add the following content:
network: {config: disabled}
Run the following command to edit the network configuration file and configure the network interface information.
sudo vim /etc/netplan/50-cloud-init.yaml
Example configuration:
network:
version: 2
ethernets:
eth0: # Network interface name
dhcp4: false # Default is DHCP. Set to false to configure the IP address manually.
match:
macaddress: 00:16:3e:16:43:xx # MAC address of your network interface
set-name: eth0
addresses:
- 192.168.1.201/24 # Primary private IP address of the network interface
- 192.168.1.202/24 # Secondary private IP address 1 of the network interface
- 192.168.1.203/24 # Secondary private IP address 2 of the network interface
routes:
- to: default
via: 192.168.1.253 # Default gateway
nameservers:
addresses: [223.5.5.5, 223.6.6.6] # DNS
Restart the network service to apply the changes.
Note If you used the nmcli con method, you do not need to restart the network service. NetworkManager monitors configuration file changes and applies them automatically.
Operating system | Restart command |
Alibaba Cloud Linux 2 CentOS 7 Red Hat 7 Anolis 7 SUSE Linux 11/12/15 OpenSUSE 15/42
| sudo service network restart
or sudo systemctl restart network |
| sudo service network restart
|
Alibaba Cloud Linux 3 CentOS 8 Red Hat 8 Anolis 8 Fedora 33/34/35
| sudo systemctl restart NetworkManager or sudo reboot
|
| sudo netplan apply
|
Ubuntu 14/16 Debian 8/9/10/11
| sudo systemctl restart networking or sudo reboot
|
Repeat the checks in Step 2 to verify the configuration.
[root@i7 xxx ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:16:3e:0e:3b:96 brd ff:ff:ff:ff:ff:ff
altname enp0s5
altname ens5
inet 192.168.1.201/24 brd 192.168.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.1.202/24 brd 192.168.1.255 scope global secondary noprefixroute eth0
valid_lft forever preferred_lft forever
inet 192.168.1.203/24 brd 192.168.1.255 scope global secondary noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::xxx scope link
valid_lft forever preferred_lft forever
Windows configuration
Note Applicable operating system: Windows.
Example operating system: Windows Server 2022.
Example network interface: This example uses the primary network interface Ethernet. If you are configuring a secondary network interface, replace the identifier with the actual one, such as Ethernet 2.
Connect to the Windows instance.
For instructions, see Connect to a Windows instance by using Workbench.
Check the current network and routing configuration to find the default gateway and subnet mask.
Open Command Prompt or Windows PowerShell.
Run the following command to view the current network interface and IP information.
ipconfig
The command output shows the status of your network interfaces and recognized IP addresses:
C:\Users\Administrator>ipconfig
Windows IP Configuration
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::3f8a:c3:22da:3675%6
IPv4 Address. . . . . . . . . . . : 192.168.1.201
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.253
The current network configuration and routing information is as follows:
Network interface | Subnet mask | Default gateway | Primary private IP address | Secondary private IPv4 address 1 | Secondary private IPv4 address 2 |
Ethernet (primary network interface) | 255.255.255.0 | 192.168.1.253 | 192.168.1.201 (auto-configured) | 192.168.1.202 (not recognized, requires configuration) | 192.168.1.203 (not recognized, requires configuration) |
Open the Network and Sharing Center.
Click change adapter settings.
Double-click the primary network interface, Ethernet. In the Ethernet Status dialog box, click Type.
Open Control Panel > Network and Internet > Network Connections.
In the Ethernet Properties dialog box, double-click Internet Protocol Version 4 (TCP/IPv4).
In the Internet Protocol Version 4 (TCP/IPv4) Properties dialog box, select Use the following IP address and then click Premium.
Important This action changes the IP acquisition method to manual configuration. Therefore, you must also configure the primary private IP address of the network interface. Otherwise, you will lose remote access to the instance through its primary private IP address.
In the Advanced TCP/IP Settings dialog box, set the IP addresses.
In the IP Address section, click Add . Then, enter the primary and secondary private IP addresses that you assigned to the Ethernet interface, along with the Subnet Mask you noted earlier.
In this example, two secondary private IP addresses are entered for the Ethernet interface.
In the Default gateways section, click Add and enter the default gateway you noted earlier.
After the configuration is complete, the IP Addresses section should display the secondary IP addresses and subnet masks you added (example: 192.168.1.201 through 192.168.1.203, all with subnet mask 255.255.255.0), and the Default gateways section should display the gateway address (example: 192.168.1.253). Click OK to confirm.
Click OK in each dialog box to save your settings and finish configuring the secondary private IPv4 addresses. Run the command from Step 2 again to verify the configuration.
C:\Users\Administrator>ipconfig
Windows IP Configuration
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::3f8a:c3:22da:3675%6
IPv4 Address. . . . . . . . . . . : 192.168.1.201
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.202
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.203
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.253
Other OS configurations
Ubuntu 14/16 and Debian 8/9/10/11
Run the following command to edit the network configuration file and configure the network interface information.
sudo vi /etc/network/interfaces
Note Starting from some versions of Debian 10, the /etc/network/interfaces file typically contains only references to files in the /etc/network/interfaces.d/ directory. The specific network interface configurations are located in different files within the interfaces.d directory.
Select the appropriate configuration file for your environment. The configuration items are generally the same.
The following is an example of the configuration:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth0:0
iface eth0:0 inet static
address 192.168.1.202
netmask 255.255.255.0
auto eth0:1
iface eth0:1 inet static
address 192.168.1.203
netmask 255.255.255.0
Restart the network service to apply the changes.
SLES series
Note Applicable operating systems: SUSE Linux 11/12/15, OpenSUSE 15.
Example operating system: SUSE Linux 15 SP5.
Example network interface: This example uses the eth0 network interface. Replace the network interface identifier with your actual identifier.
Run the following command to open the configuration file for the eth0 network interface and configure its secondary private IPv4 addresses and subnet mask.
sudo vi /etc/sysconfig/network/ifcfg-eth0
The following is an example of the configuration file:
# Disable DHCP and use static configuration
BOOTPROTO=static
STARTMODE=auto
USERCONTROL=no
# Add a numeric suffix for multiple IP addresses
IPADDR_1=192.168.1.201
NETMASK_1=255.255.255.0
LABEL_1=
IPADDR_2=192.168.1.202
NETMASK_2=255.255.255.0
LABEL_2=0
IPADDR_3=192.168.1.203
NETMASK_3=255.255.255.0
LABEL_3=1
Note You can run sudo cat /etc/sysconfig/network/ifcfg.template to view the explanations in the template configuration file.
Run the following command to check if the global network settings file contains default gateway information:
cat /etc/sysconfig/network/routes
If not, add the default gateway information to the file. The following is an example:
default 192.168.1.253 - -
Restart the network service to apply the changes.
Unassign secondary private IP addresses
This topic describes how to unassign one or more secondary private IP addresses from an elastic network interface (ENI) when they are no longer needed.
Prerequisites
Before you unassign secondary private IP addresses, ensure the following:
The ENI has one or more secondary private IP addresses.
The elastic network interface is in the Available or Bound state.
When you unassign a secondary private IP address from a primary ENI, the attached instance must be in the Running or Stopped state.
Procedure
Go to ECS Console - Elastic Network Interfaces.
In the upper-left corner of the page, select a region and resource group.
On the ENIs page, find the target ENI and in the Actions column, click Manage ENI IP Addresses.
In the Manage ENI IP Addresses dialog box, go to the Secondary Private IPv4 Address section. Find one or more secondary private IP addresses that you want to unassign, and click the
icon in the corresponding row.
Click OK.
Refresh the list. The unassignment is successful if the IP addresses no longer appear in the IP Address column for the target ENI.
Further reading
Automatic network configuration with cloud-init
cloud-init is an open-source tool that initializes a Linux operating system by setting passwords, configuring hostnames, and running custom scripts. cloud-init is installed by default on all Alibaba Cloud public images. When an ECS instance starts, cloud-init automatically generates the system network configuration.
Notes about cloud-init in network configuration files
A note in the network configuration file indicates that cloud-init automatically generated the file. The following example shows the network configuration file /etc/sysconfig/network-scripts/ifcfg-eth0 for Alibaba Cloud Linux 3.2:
# Created by cloud-init on instance boot automatically, do not edit.
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=00:16:3e:09:7d:73
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
Disable the network configuration feature of cloud-init
When to disable the network configuration feature of cloud-init: Disable the network configuration feature of cloud-init in the following scenarios. Otherwise, cloud-init may overwrite your custom network configurations when the system restarts.
Manually configuring a static network in the network configuration file created by cloud-init.
Managing the network with another network management service, such as NetworkManager.
How to disable the network configuration feature of cloud-init: Create the /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg file and add the configuration network: {config: disabled}.
Important For more information about cloud-init, view the /etc/cloud/cloud.cfg.d/README file on your Linux instance.
IP address configuration
You can configure an IP address using two methods: DHCP and static configuration. Choose a method when you configure a secondary private IP address.
Static configuration: You manually configure network parameters, such as the subnet mask, default gateway, and DNS server address.
DHCP dynamic assignment: DHCP is a network protocol that automatically provides devices on a network with configuration information, such as an IP address, subnet mask, default gateway, and DNS server address. You can also configure a secondary private IP address for a Linux instance configured to use DHCP.