VK Cloud logo

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.

Preparation steps

  1. Make sure the OpenStack client is installed, and authenticate in the project.
  2. Select or create a virtual machine in your VK Cloud project.
  3. Connect the virtual machine to a network. Write down the network and subnet IDs.
  4. Add the required number of Floating IP addresses to the project.

1. Create additional ports

  1. For each additional Floating IP address, add a port to the virtual machine subnet.

  2. Make sure the ports are created:

    openstack port list --network <NETWORK_NAME_OR_ID>

2. Attach the ports to the VM

  1. Attach the created ports to the VM:

    openstack server add port <VM_ID> <PORT_ID>
  2. Make sure the ports are successfully attached to the VM:

    openstack port list --server <VM_ID>

3. Bind the Floating IP addresses to the VM ports

  1. Bind each free Floating IP address to the corresponding VM port.

  2. Make sure the Floating IP addresses are successfully bound to the ports:

    openstack floating ip list

4. Configure the network interfaces on the VM

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.

5. Configure routing

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.

  1. Add the routes and routing-policy parameters to the /etc/netplan/50-cloud-init.yaml file for each additional interface.

    Example:

    network:  version: 2  ethernets:    eth0:      dhcp4: true    eth1:      dhcp4: true      routes:        - to: 0.0.0.0/0          via: 10.0.1.1          table: 101      routing-policy:        - from: 10.0.1.97/32          table: 101

    For each subsequent interface, use the next table number (102, 103, etc.) and specify the corresponding IP address and gateway.

  2. Apply the settings:

    sudo netplan apply

6. Verify the availability of the Floating IP addresses

  1. 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>
  2. Connect to the VM.

  3. Make sure each interface has an internal IP address from the subnet:

    ip addr show
  4. Check the connectivity between the Floating IP address and the internal IP address:

    curl --interface <INTERFACE_NAME> ifconfig.me

    The command will return the Floating IP address bound to that interface.

  5. Make sure the routing rules are applied:

    ip rule listip route show table <TABLE_NUMBER>
Was this article helpful?