Updated on 2025-10-30 GMT+08:00

Managing Virtual IP Addresses

Scenarios

A virtual IP address is a private IP address independently assigned from a VPC subnet. It can be released when no longer needed. You can:
  • Bind one or more virtual IP addresses to a cloud server so that you can use either the virtual or private IP address to access the server. If you have multiple services running on a cloud server, you can use different virtual IP addresses to access them.
  • Bind a virtual IP address to multiple cloud servers. You can use a virtual IP address and an HA software (such as Keepalived) to set up a high-availability active/standby cluster. If you want to improve service availability and avoid single points of failure, you can deploy cloud servers in the active/standby mode or deploy one active cloud server and multiple standby cloud servers. In this arrangement, the cloud servers all use the same virtual IP address. If the active cloud server goes down, the standby cloud server becomes the active server and continues to provide services.

This section describes how to bind and configure a virtual IP address for an ECS.

Background

Generally, cloud servers use private IP addresses for internal communications. Virtual IP addresses provide similar access and support communications within a VPC at Layer 2 and Layer 3, between VPCs with VPC peering connections, between cloud and on-premises networks with VPN or Direct Connect, and Internet access with EIPs. Figure 1 describes how private IP addresses, the virtual IP address, and EIPs work together.
  • Private IP addresses are used for internal network communication.
  • The virtual IP address works with Keepalived to build an HA cluster. ECSs in this cluster can be accessed through one virtual IP address.
  • EIPs are used for Internet communication.
Figure 1 Different types of IP addresses used by ECSs

For details about virtual IP addresses, see Virtual IP Address Overview.

Constraints

It is recommended that a maximum of eight virtual IP addresses be bound to an ECS. If an ECS has multiple virtual IP addresses, each virtual IP address is used by a specific service. If there are too many services, the ECS may become overloaded and compromise user experience.

Binding a Virtual IP Address

  1. Log in to the management console.
  2. Click . Under Compute, click Elastic Cloud Server.
  3. On the Elastic Cloud Server page, click the name of the target ECS.

    The ECS details page is displayed.

  4. On the Network Interfaces tab, locate the target virtual IP address and click Manage Virtual IP Address.
  5. On the IP Addresses tab of the displayed page, locate the row containing the target virtual IP address and select Bind to EIP or Bind to Server in the Operation column.

    Multiple ECSs deployed to work in active/standby mode can be bound with a virtual IP address to improve DR performance.

  6. Click OK.

Configuring a Virtual IP Address for an ECS

After you bind one or more virtual IP addresses to an ECS on the console, you must log in to the ECS to manually configure these virtual IP addresses.

The following OSs are used as examples here. For other OSs, see the help documentation on their official websites.
  • Linux: CentOS 8.2 64bit, Ubuntu 22.04 server 64bit, Huawei Cloud EulerOS 2.0 Standard 64bit, Debian 12.0.0 64bit, and SUSE Linux Enterprise Server 15 SP5 64bit
  • Windows: Windows Server
The following uses CentOS 8.2 64bit as an example.
  1. Obtain the network interface that the virtual IP address is to be bound and the connection of the network interface:

    nmcli connection

    Information similar to the following is displayed:
    [root@ecs-centos ~]# nmcli connection
    NAME         UUID                                  TYPE      DEVICE 
    System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0   
    System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  --     
    System eth2  3a73717e-65ab-93e8-b518-24f5af32dc0d  ethernet  --     
    System eth3  c5ca8081-6db2-4602-4b46-d771f4330a6d  ethernet  --     
    System eth4  84d43311-57c8-8986-f205-9c78cd6ef5d2  ethernet  -- 

    The command output in this example is described as follows:

    • eth0 in the DEVICE column indicates the network interface that the virtual IP address is to be bound.
    • System eth0 in the NAME column indicates the connection of the network interface.
  2. Add the virtual IP address for the connection:

    nmcli connection modify "connection-name-of-the-network-interface" +ipv4.addresses virtual-IP-address

    Configure the parameters as follows:

    • connection-name-of-the-network-interface: The connection name of the network interface obtained in 1. In this example, the connection name is System eth0.
    • virtual-IP-address: Enter the virtual IP address to be added. If you add multiple virtual IP addresses at a time, separate every two with a comma (,).
    Example commands:
    • Adding a single virtual IP address: nmcli connection modify "System eth0" +ipv4.addresses 192.168.0.22
    • Adding multiple virtual IP addresses: nmcli connection modify "System eth0" +ipv4.addresses 192.168.0.22,192.168.0.23
  3. Make the configuration in 2 take effect:

    nmcli connection up "connection-name-of-the-network-interface"

    In this example, run the following command:

    nmcli connection up "System eth0"

    Information similar to the following is displayed:
    [root@ecs-centos ~]# nmcli connection up "System eth0"
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
  4. Check whether the virtual IP address has been bound:

    ip a

    Information similar to the following is displayed. In the command output, virtual IP address 192.168.0.22 is bound to network interface eth0.
    [root@ecs-centos ~]# 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 fa:16:3e:54:ac:fa brd ff:ff:ff:ff:ff:ff
        inet 192.168.0.22/32 scope global noprefixroute eth0
           valid_lft forever preferred_lft forever
        inet 192.168.0.78/24 brd 192.168.0.255 scope global dynamic noprefixroute eth0
           valid_lft 315359994sec preferred_lft 315359994sec
        inet6 fe80::f816:3eff:fe54:acfa/64 scope link 
           valid_lft forever preferred_lft forever

    After the preceding configurations are complete, the configurations will not be lost after the ECS is restarted.

    To delete an added virtual IP address, perform the following steps:

    1. Delete the virtual IP address from the connection of the network interface:

      nmcli connection modify "connection-name-of-the-network-interface" -ipv4.addresses virtual-IP-address

      To delete multiple virtual IP addresses at a time, separate every two with a comma (,). Example commands are as follows:
      • Deleting a single virtual IP address: nmcli connection modify "System eth0" -ipv4.addresses 192.168.0.22
      • Deleting multiple virtual IP addresses: nmcli connection modify "System eth0" -ipv4.addresses 192.168.0.22,192.168.0.23
    2. Make the deletion take effect by referring to 3.
The following uses Ubuntu 22.04 server 64bit as an example. If the ECS runs Ubuntu 22 or Ubuntu 20, perform the following operations:
  1. Obtain the network interface that the virtual IP address is to be bound:

    ifconfig

    Information similar to the following is displayed. In this example, the network interface with the virtual IP address bound is eth0.
    root@ecs-X-ubantu:~# ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 172.16.0.210  netmask 255.255.255.0  broadcast 172.16.0.255
            inet6 fe80::f816:3eff:fe01:f1c3  prefixlen 64  scopeid 0x20<link>
            ether fa:16:3e:01:f1:c3  txqueuelen 1000  (Ethernet)
            RX packets 43915  bytes 63606486 (63.6 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 3364  bytes 455617 (455.6 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    ...
  2. Switch to the /etc/netplan directory:

    cd /etc/netplan

  3. Add a virtual IP address to the network interface.
    1. Open the configuration file 01-netcfg.yaml:

      vim 01-netcfg.yaml

    2. Press i to enter the editing mode.
    3. In the network interface configuration area, add a virtual IP address.

      In this example, add a virtual IP address for eth0:

      addresses:

      - 172.16.0.26/32

      The file content is as follows:
      network:
          version: 2
          renderer: NetworkManager
          ethernets:
              eth0:
                  dhcp4: true
                  addresses:
                  - 172.16.0.26/32
              eth1:
                  dhcp4: true
              eth2:
                  dhcp4: true
              eth3:
                  dhcp4: true
              eth4:
                  dhcp4: true
    4. Press Esc, enter :wq!, save the configuration, and exit.
  4. Make the configuration in 3 take effect:

    netplan apply

  5. Check whether the virtual IP address has been bound:

    ip a

    Information similar to the following is displayed. In the command output, virtual IP address 172.16.0.26 is bound to network interface eth0.
    root@ecs-X-ubantu:/etc/netplan# ip a
    ...
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        link/ether fa:16:3e:01:f1:c3 brd ff:ff:ff:ff:ff:ff
        altname enp0s3
        altname ens3
        inet 172.16.0.26/32 scope global noprefixroute eth0
           valid_lft forever preferred_lft forever
        inet 172.16.0.210/24 brd 172.16.0.255 scope global dynamic noprefixroute eth0
           valid_lft 107999971sec preferred_lft 107999971sec
        inet6 fe80::f816:3eff:fe01:f1c3/64 scope link 
           valid_lft forever preferred_lft forever

    After the preceding configurations are complete, the configurations will not be lost after the ECS is restarted.

    To delete an added virtual IP address, perform the following steps:

    1. Open the configuration file 01-netcfg.yaml and delete the virtual IP address of the corresponding network interface by referring to 3.
    2. Make the deletion take effect by referring to 4.

The following operations use Windows Server as an example.

  1. In Control Panel, click Network and Sharing Center, and click the corresponding local connection.
  2. On the displayed page, click Properties.
  3. On the Network tab page, select Internet Protocol Version 4 (TCP/IPv4).
  4. Click Properties.
  5. Select Use the following IP address and set IP address to the private IP address of the ECS, for example, 10.0.0.101.
    Figure 2 Configuring private IP address
  6. Click Advanced.
  7. On the IP Settings tab, click Add in the IP addresses area.

    Add the virtual IP address, for example, 10.0.0.154.

    Figure 3 Configuring virtual IP address
  8. Click OK.
  9. In the Start menu, open the Windows command line window and run the following command to check whether the virtual IP address has been configured:

    ipconfig /all

    In the command output, IPv4 Address is the virtual IP address 10.0.0.154, indicating that the virtual IP address of the ECS's network interface has been correctly configured.