Managing floating IP addresses

A virtual machine connected to a virtual network can be accessed from public networks, such as the Internet, by means of a floating IP address. Such an address is picked from a physical network and mapped to the VM’s private IP address. The floating and private IP addresses are used at the same time on the VM’s network interface. The private IP address is used to communicate with other VMs on the virtual network. The floating IP address is used to access the VM from public networks. The VM guest operating system is unaware of the assigned floating IP address.

Prerequisites

  • You have a virtual router created, as described in Creating virtual routers.
  • The virtual machine to assign a floating IP to has a fixed private IP address.
  • The virtual router connects the physical network, from which a floating IP will be picked, with the VM’s virtual network.

To create a floating IP address and assign it to a virtual machine

Admin panel

  1. On the Compute > Network > Floating IPs tab, click Add floating IP.
  2. In the Add floating IP address, select a physical network, from which a floating IP will be picked, and a VM network interface with a fixed private IP address.

  3. Click Add.

Command-line interface

Use the following command:

vinfra service compute floatingip create [--floating-ip <floating-ip>]
                                         [--port-id <port-id>]
                                         [--fixed-ip <fixed-ip>]
                                         [--description <description>]
                                         --network <network>
--floating-ip <floating-ip>
Floating IP address
--port-id <port-id>
ID of the port to be associated with the floating IP address. To learn the port ID of the selected virtual machine, use the command vinfra service compute server iface list.
--fixed-ip <fixed-ip>
Port IP address (required only if the port has multiple IP addresses)
--description <description>
Description of the floating IP address
--network <network>
ID or name of the network from which to allocate the floating IP

For example, to create a floating IP address from the physical network public and assign it to a virtual machine on port with the ID 418c8c9e-aaa5-42f2-8da7-24bfead6f28b and the virtual IP address 192.168.128.5, run:

# vinfra service compute floatingip create public --port-id 418c8c9e-aaa5-42f2-8da7-24bfead6f28b \
--fixed-ip-address 192.168.128.5
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attached_to         | a172cb6a-1c7b-4157-9e86-035f3077646f |
| description         |                                      |
| fixed_ip_address    | 192.168.128.5                        |
| floating_ip_address | 10.94.129.72                         |
| floating_network_id | 720e45bc-4225-49de-9346-26513d8d1262 |
| id                  | a709f884-c43f-4a9a-a243-a340d7682ef8 |
| port_id             | 418c8c9e-aaa5-42f2-8da7-24bfead6f28b |
| project_id          | 894696133031439f8aaa7e4868dcbd4d     |
| router_id           | f7f86029-a553-4d61-b7ec-6f581d9c5f5f |
| status              | DOWN                                 |
+---------------------+--------------------------------------+

The created floating IP address will appear in the vinfra service compute floatingip list output:

# vinfra service compute floatingip list -c id -c fixed_ip_address -c port_id -c floating_ip_address
+----------------+------------------+----------------+---------------------+
| id             | fixed_ip_address | port_id        | floating_ip_address |
+----------------+------------------+----------------+---------------------+
| a709f884-<...> | 192.168.128.5    | 418c8c9e-<...> | 10.94.129.72        |
+----------------+------------------+----------------+---------------------+

To re-assign a floating IP address to another virtual machine

Admin panel

  1. Click the ellipsis icon next to the floating IP address, and then click Unassign.
  2. Once the VM name disappears in the Assigned to column, click the ellipsis icon again, and then select Assign.
  3. In the Assign floating IP address window, select a VM network interface with a fixed private IP address.
  4. Click Assign.

Command-line interface

Use the following command:

vinfra service compute floatingip set [--port-id <port-id>] [--fixed-ip <fixed-ip>]
                                      [--description <description>] <floating-ip>
--port-id <port-id>
ID of the port to be associated with the floating IP address
--fixed-ip <fixed-ip>
Port IP address (required only if the port has multiple IP addresses)
--description <description>
Description of the floating IP address
<floating-ip>
ID of the floating IP address

For example, to assign the floating IP address with the ID a709f884-c43f-4a9a-a243-a340d7682ef8 to a virtual machine on port with the ID 8c11c29b-9a73-4017-baff-1e872b18b54b and the virtual IP address 192.128.30.15, run:

# vinfra service compute floatingip set a709f884-c43f-4a9a-a243-a340d7682ef8 \
--port-id 8c11c29b-9a73-4017-baff-1e872b18b54b --fixed-ip-address 192.128.30.15
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attached_to         | 3a092f6f-bbaf-47a9-bcc7-f86223aacb55 |
| description         |                                      |
| fixed_ip_address    | 192.128.30.15                        |
| floating_ip_address | 10.94.129.72                         |
| floating_network_id | 720e45bc-4225-49de-9346-26513d8d1262 |
| id                  | a709f884-c43f-4a9a-a243-a340d7682ef8 |
| port_id             | 8c11c29b-9a73-4017-baff-1e872b18b54b |
| project_id          | 894696133031439f8aaa7e4868dcbd4d     |
| router_id           | f7f86029-a553-4d61-b7ec-6f581d9c5f5f |
| status              | ACTIVE                               |
+---------------------+--------------------------------------+

To remove a floating IP address

Admin panel

  1. Unassign it from a virtual machine. Click the ellipsis icon next to the floating IP address, and then click Unassign.
  2. Click the ellipsis icon again, and then select Delete.

Command-line interface

Use the following command:

vinfra service compute floatingip delete <floating-ip>
<floating-ip>
ID of the floating IP address

For example, to delete the floating IP address with the ID a709f884-c43f-4a9a-a243-a340d7682ef8, run:

# vinfra service compute floatingip delete a709f884-c43f-4a9a-a243-a340d7682ef8
Operation successful