Assigning multiple Floating IP addresses to a single VM
By default, when a VM is created, it is assigned one internal IP address. One Floating IP address can be attached to it. To attach multiple Floating IP addresses to a single VM, you need to create additional ports in the subnet, attach them to the VM, and bind a Floating IP address to each port.
- Make sure the OpenStack client is installed, and authenticate in the project.
- Select or create a virtual machine in your VK Cloud project.
- Connect the virtual machine to a network. Write down the network and subnet IDs.
- Add the required number of Floating IP addresses to the project.
-
For each additional Floating IP address, add a port to the virtual machine subnet.
-
Make sure the ports are created:
openstack port list --network <NETWORK_NAME_OR_ID>
-
Attach the created ports to the VM:
openstack server add port <VM_ID> <PORT_ID> -
Make sure the ports are successfully attached to the VM:
openstack port list --server <VM_ID>
-
Bind each free Floating IP address to the corresponding VM port.
-
Make sure the Floating IP addresses are successfully bound to the ports:
openstack floating ip list
After the ports are added, additional network interfaces will appear on the VM.
For each new port, check and configure the network interface inside the VM operating system.
By default, all outgoing packets are sent through the primary VM interface. Because of this, responses to requests received through the additional interfaces go out through the primary interface, and the Floating IP addresses bound to them do not work.
To make each interface use its own route, configure routing rules (policy routing). For each interface, create a routing table and a rule that routes packets from the IP address of that interface through its gateway.
Below are examples for the eth1 interface with the internal IP address 10.0.1.97/24 and gateway 10.0.1.1.
-
Add the
routesandrouting-policyparameters to the/etc/netplan/50-cloud-init.yamlfile for each additional interface.Example:
network:version: 2ethernets:eth0:dhcp4: trueeth1:dhcp4: trueroutes:- to: 0.0.0.0/0via: 10.0.1.1table: 101routing-policy:- from: 10.0.1.97/32table: 101For each subsequent interface, use the next table number (102, 103, etc.) and specify the corresponding IP address and gateway.
-
Apply the settings:
sudo netplan apply
-
Make sure each Floating IP address is accessible from the outside. Run the check from your computer:
ping <FLOATING_IP_1>ping <FLOATING_IP_2> -
Make sure each interface has an internal IP address from the subnet:
LinuxWindowsip addr show -
Check the connectivity between the Floating IP address and the internal IP address:
LinuxWindowscurl --interface <INTERFACE_NAME> ifconfig.meThe command will return the Floating IP address bound to that interface.
-
Make sure the routing rules are applied:
LinuxWindowsip rule listip route show table <TABLE_NUMBER>