Binding a Virtual IP Address to an Instance or EIP
Scenarios
- Bind a virtual IP address to an instance. You can:
- Bind one or more virtual IP addresses to an instance.
- Bind a virtual IP address to multiple instances.
- Bind a virtual IP address to an EIP to enable public network communication.
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 to an EIP or Instance on the Console
- Go to the subnet list page.
- In the subnet list, locate the target subnet and click its name.
- On the IP Addresses tab, bind an EIP to the virtual IP address:
- Locate the row that contains the virtual IP address and click Bind to EIP in the Operation column.
The Bind to EIP dialog box is displayed.
- Select an EIP and click OK.
In the virtual IP address list, you can view the bound EIP.
- Locate the row that contains the virtual IP address and click Bind to EIP in the Operation column.
- On the IP Addresses tab, bind an instance to the virtual IP address:
- Locate the row that contains the virtual IP address and click Bind to Instance in the Operation column.
The Bind to Instance dialog box is displayed.
- Select an instance and click OK.
In the virtual IP address list, you can view the bound instance.
- After you bind one or more virtual IP addresses to an ECS on the console, you need to manually configure the virtual IP addresses on the ECS. For details, see Configuring a Virtual IP Address for an ECS.
- If you want to bind a virtual IP address to multiple ECSs and use Keepalived to build an HA cluster, see Using a Virtual IP Address and Keepalived to Set Up a High-Availability Web Cluster.
- Locate the row that contains the virtual IP address and click Bind to Instance in the Operation column.
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.
- 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
- Obtain the network interface that the virtual IP address is to be bound and the connection of the network interface:
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.
- 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
- 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)
- Check whether the virtual IP address has been bound:
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:
- 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
- Make the deletion take effect by referring to 3.
- Delete the virtual IP address from the connection of the network interface:
- Obtain the network interface that the virtual IP address is to be bound:
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 ... - Switch to the /etc/netplan directory:
cd /etc/netplan
- Add a virtual IP address to the network interface.
- Open the configuration file 01-netcfg.yaml:
vim 01-netcfg.yaml
- Press i to enter the editing mode.
- 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 - Press Esc, enter :wq!, save the configuration, and exit.
- Open the configuration file 01-netcfg.yaml:
- Make the configuration in 3 take effect:
netplan apply
- Check whether the virtual IP address has been bound:
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:
- Obtain the network interface that the virtual IP address is to be bound and the connection of the network interface:
Information similar to the following is displayed:
[root@ecs-hce ~]# 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.
- Add the virtual IP address for the connection:
nmcli connection modify "connection-name-of-the-network-interface" +ipv4.addresses virtual-IP-address
The parameters are described 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 command:- Adding a single virtual IP address: nmcli connection modify "System eth0" +ipv4.addresses 192.168.0.23
- Adding multiple virtual IP addresses: nmcli connection modify "System eth0" +ipv4.addresses 192.168.0.23,192.168.0.25
- Make the configuration in 2 take effect:
nmcli connection up "connection-name-of-the-network-interface"
Example command:
nmcli connection up "System eth0"
Information similar to the following is displayed:[root@ecs-hce ~]# nmcli connection up "System eth0" Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
- Check whether the virtual IP address has been bound:
Information similar to the following is displayed. In the command output, virtual IP address 192.168.0.23 is bound to network interface eth0.
[root@ecs-hce ~]# 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:af brd ff:ff:ff:ff:ff:ff inet 192.168.0.23/32 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet 192.168.0.3/24 brd 192.168.0.255 scope global dynamic noprefixroute eth0 valid_lft 315359982sec preferred_lft 315359982sec inet6 fe80::f816:3eff:fe54:acaf/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:
- 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
- Make the deletion take effect by referring to 3.
- Delete the virtual IP address from the connection of the network interface:
- Obtain the network interface that the virtual IP address is to be bound and the connection of the network interface:
Information similar to the following is displayed:
root@ecs-debian:~# nmcli connection NAME UUID TYPE DEVICE Ifupdown (eth0) 681b428f-beaf-8932-dce4-687ed5bae28e ethernet eth0 lo 03e619be-07fa-4994-86dc-7b434c9646b7 loopback lo Ifupdown (eth1) 7b635ed6-2640-7ad8-675d-744db12dd9fa ethernet -- Ifupdown (eth2) 226544c9-6fc1-ece7-546d-3ee32748889b ethernet -- Ifupdown (eth3) 7f363dc1-9ded-33e4-2e54-4d44c6c458d1 ethernet -- Ifupdown (eth4) 9186222c-4821-e5d9-f5fd-35125fc70b0a 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.
- Ifupdown (eth0) in the NAME column indicates the connection of the network interface, which is managed by the traditional ifupdown tool. The network interface information is configured in /etc/network/interfaces.
- Add a virtual IP address to the network interface.
- Open the configuration file:
- Press i to enter the editing mode.
- In the network interface configuration area, add a virtual IP address.
In this example, add a virtual IP address for eth0:
up ip addr add 192.168.0.22/32 dev eth0
In the preceding command, 192.168.0.22/32 indicates the virtual IP address. Set it based on the site requirements.
The file content is as follows:auto eth0 iface eth0 inet dhcp up ip addr add 192.168.0.22/32 dev eth0To add multiple virtual IP addresses, add one IP address in each line. For example, to add two virtual IP addresses 192.168.0.22 and 192.168.0.23, add the following content:
up ip addr add 192.168.0.22/32 dev eth0
up ip addr add 192.168.0.23/32 dev eth0
- Press Esc, enter :wq!, save the configuration, and exit.
- Check the network service status:
- Enable automatic system startup to preserve configuration after restart:
Information similar to the following is displayed:
root@ecs-debian:~# systemctl enable networking Synchronizing state of networking.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable networking Created symlink /etc/systemd/system/multi-user.target.wants/networking.service → /lib/systemd/system/networking.service. Created symlink /etc/systemd/system/network-online.target.wants/networking.service → /lib/systemd/system/networking.service.
- Restart the ECS for the configuration in 2 to take effect:
reboot
- Check whether the virtual IP address has been bound:
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-debian:~# 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 noprefixroute 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:c9 brd ff:ff:ff:ff:ff:ff altname enp0s3 altname ens3 inet 192.168.0.29/24 brd 192.168.0.255 scope global dynamic noprefixroute eth0 valid_lft 315358226sec preferred_lft 315358226sec inet 192.168.0.22/32 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::c29f:1bdd:5027:6acc/64 scope link noprefixroute 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:
- Obtain the network interface that the virtual IP address is to be bound and the connection of the network interface:
Information similar to the following is displayed. In this example, the network interface with the virtual IP address bound is eth0.
ecs-suse:~ # 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:eb brd ff:ff:ff:ff:ff:ff altname enp0s3 altname ens3 inet 192.168.0.63/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:fe54:aceb/64 scope link valid_lft forever preferred_lft forever
- Add a virtual IP address to the network interface.
- Open the configuration file:
- Press i to enter the editing mode.
- In the network interface configuration area, add a virtual IP address.
In this example, add a virtual IP address for eth0:
IPADDR_1=192.168.0.22
NETMASK_1=255.255.255.0
In the preceding command, 192.168.0.22 indicates the virtual IP address. Set it based on the site requirements. 255.255.255.0 indicates the mask of the virtual IP address. The value is fixed and does not need to be changed.
The file content is as follows:DEVICE="eth0" BOOTPROTO="dhcp" STARTMODE="auto" TYPE="Ethernet" IPADDR_1=192.168.0.22 NETMASK_1=255.255.255.0
To add multiple virtual IP addresses, add one IP address in each line. For example, to add two virtual IP addresses 192.168.0.22 and 192.168.0.23, add the following content:
IPADDR_1=192.168.0.22
NETMASK_1=255.255.255.0
IPADDR_2=192.168.0.23
NETMASK_2=255.255.255.0
- Press Esc, enter :wq!, save the configuration, and exit.
- Restart the network service for the configuration in 2 to take effect:
systemctl restart network
- Check whether the virtual IP address has been bound:
Information similar to the following is displayed. In the command output, virtual IP address 192.168.0.22 is bound to network interface eth0.
ecs-suse:~ # 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:eb brd ff:ff:ff:ff:ff:ff altname enp0s3 altname ens3 inet 192.168.0.22/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.0.63/24 brd 192.168.0.255 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::f816:3eff:fe54:aceb/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:
The following operations use Windows Server as an example.
- In Control Panel, click Network and Sharing Center, and click the corresponding local connection.
- On the displayed page, click Properties.
- On the Network tab page, select Internet Protocol Version 4 (TCP/IPv4).
- Click Properties.
- 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 1 Configuring private IP address
- Click Advanced.
- On the IP Settings tab, click Add in the IP addresses area.
Add the virtual IP address, for example, 10.0.0.154.
Figure 2 Configuring virtual IP address
- Click OK.
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot