Manage floating IP addresses

Create and manage floating IP addresses to enable instance communication with external networks.

Control instance external IP addressing

Assign a specific floating IP address to an instance.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. Assign a floating IP address to an instance.
    Example

    In this example, the floating IP 192.0.2.200 is being assigned to the prod-serv1 instance.

    $ openstack server add floating ip prod-serv1 192.0.2.200

Results

  • Confirm that your floating IP is associated with your instance.
    Example
    $ openstack server show prod-serv1
    Sample output
    +-----------------------------+------------------------------------------+
    | Field                       | Value                                    |
    +-----------------------------+------------------------------------------+
    | OS-DCF:diskConfig           | MANUAL                                   |
    | OS-EXT-AZ:availability_zone | nova                                     |
    | OS-EXT-STS:power_state      | Running                                  |
    | OS-EXT-STS:task_state       | None                                     |
    | OS-EXT-STS:vm_state         | active                                   |
    | OS-SRV-USG:launched_at      | 2024-09-10T13:00:23.000000               |
    | OS-SRV-USG:terminated_at    | None                                     |
    | accessIPv4                  |                                          |
    | accessIPv6                  |                                          |
    | addresses                   | public=198.51.100.56,192.0.2.200         |
    |                             |                                          |
    | config_drive                |                                          |
    | created                     | 2024-09-10T13:00:39Z                     |
    | flavor                      | review-ephemeral                         |
    |                             | (8130dd45-78f6-44dc-8173-4d6426b8e520)   |
    | hostId                      | 2308c8d8f60ed5394b1525122fb5bf8ea55c78b8 |
    |                             | 0ec6157eca4488c9                         |
    | id                          | aef3ca09-887d-4d20-872d-1d1b49081958     |
    | image                       | rhel8                                    |
    |                             | (20724bfe-93a9-4341-a5a3-78b37b3a5dfb)   |
    | key_name                    | example-keypair                          |
    | name                        | prod-serv1                               |
    | progress                    | 0                                        |
    | project_id                  | bd7a8c4a19424cf09a82627566b434fa         |
    | properties                  |                                          |
    | security_groups             | name='default'                           |
    | status                      | ACTIVE                                   |
    | updated                     | 2021-09-10T13:02:14Z                     |
    | user_id                     | 4b7e19a0d723310fd92911eb2fe59743a3a5cd32 |
    |                             | 45f76ffced91096196f646b5                 |
    | volumes_attached            |                                          |
    +-----------------------------+------------------------------------------+

Create a floating IP pool

Create a pool of floating IP addresses for instance allocation.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient

About this task

The Networking service allocates floating IP addresses to all projects (tenants) from the same IP ranges in CIDR format. As a result, all projects can consume floating IPs from every floating IP subnet. You can manage this behavior by using quotas for specific projects. For example, you can set the default to 10 for ProjectA and ProjectB, while setting the quota for ProjectC to 0.

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. When you create an external subnet, you can also define the floating IP allocation pool.
    Example

    In this example, an external subnet, public, is created with an allocation pool that starts with 192.168.100.20, and ends with 192.168.100.100. DHCP allocation is disabled because public hosts only floating IP addresses:

    $ openstack subnet create --no-dhcp \
    --allocation-pool start=192.168.100.20,end=192.168.100.100 \
    --gateway 192.168.100.1 --network 192.168.100.0/24 public

What to do next

  • Confirm that the pool is configured properly by assigning a random floating IP to an instance.

    For more information, see Assigning a random floating IP.

Get quick external connectivity with any available IP

Allocate a random floating IP address from a pool to an instance.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient
  • A pool of routable external IP addresses.

    For more information, see Create a floating IP pool.

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. Randomly allocate a floating IP address from the pool.
    Example

    In this example, a floating IP address is randomly allocated from a network named public.

    $ openstack floating ip create public
    Sample output

    In the following example, the newly allocated floating IP is 192.0.2.200. You can now assign the floating IP to an instance.

    +---------------------+--------------------------------------------------+
    | Field               | Value                                            |
    +---------------------+--------------------------------------------------+
    | fixed_ip_address    | None                                             |
    | floating_ip_address | 192.0.2.200                                      |
    | floating_network_id | f0dcc603-f693-4258-a940-0a31fd4b80d9             |
    | id                  | 6352284c-c5df-4792-b168-e6f6348e2620             |
    | port_id             | None                                             |
    | router_id           | None                                             |
    | status              | ACTIVE                                           |
    +---------------------+--------------------------------------------------+
  3. Enter the following command to locate your instance:
    $ openstack server list
    Sample output
    +-------------+-------------+--------+-------------+-------+-------------+
    | ID          | Name        | Status | Networks    | Image | Flavor      |
    +-------------+-------------+--------+-------------+-------+-------------+
    | aef3ca09-88 | prod-serv1  | ACTIVE | public=198. | rhel9 | review-     |
    | 7d-4d20-872 |             |        | 51.100.56   |       | ephemeral   |
    | d-1d1b49081 |             |        |             |       |             |
    | 958         |             |        |             |       |             |
    |             |             |        |             |       |             |
    +-------------+-------------+--------+-------------+-------+-------------+
  4. Associate the instance name or ID with the floating IP.
    Example
    $ openstack server add floating ip prod-serv1 192.0.2.200

Results

  • Enter the following command to confirm that your floating IP is associated with your instance.
    Example
    $ openstack server show prod-serv1
    Sample output
    +-----------------------------+------------------------------------------+
    | Field                       | Value                                    |
    +-----------------------------+------------------------------------------+
    | OS-DCF:diskConfig           | MANUAL                                   |
    | OS-EXT-AZ:availability_zone | nova                                     |
    | OS-EXT-STS:power_state      | Running                                  |
    | OS-EXT-STS:task_state       | None                                     |
    | OS-EXT-STS:vm_state         | active                                   |
    | OS-SRV-USG:launched_at      | 2024-09-10T13:16:43.000000               |
    | OS-SRV-USG:terminated_at    | None                                     |
    | accessIPv4                  |                                          |
    | accessIPv6                  |                                          |
    | addresses                   | public=198.51.100.56,192.0.2.200         |
    |                             |                                          |
    | config_drive                |                                          |
    | created                     | 2024-09-10T13:17:22Z                     |
    | flavor                      | review-ephemeral                         |
    |                             | (8130dd45-78f6-44dc-8173-4d6426b8e520)   |
    | hostId                      | 2308c8d8f60ed5394b1525122fb5bf8ea55c78b8 |
    |                             | 0ec6157eca4488c9                         |
    | id                          | aef3ca09-887d-4d20-872d-1d1b49081958     |
    | image                       | rhel8                                    |
    |                             | (20724bfe-93a9-4341-a5a3-78b37b3a5dfb)   |
    | key_name                    | example-keypair                          |
    | name                        | prod-serv1                               |
    | progress                    | 0                                        |
    | project_id                  | bd7a8c4a19424cf09a82627566b434fa         |
    | properties                  |                                          |
    | security_groups             | name='default'                           |
    | status                      | ACTIVE                                   |
    | updated                     | 2024-09-10T13:19:06Z                     |
    | user_id                     | 4b7e19a0d723310fd92911eb2fe59743a3a5cd32 |
    |                             | 45f76ffced91096196f646b5                 |
    | volumes_attached            |                                          |
    +-----------------------------+------------------------------------------+

Create floating IP port forwarding for external access

Configure port forwarding for a floating IP address.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient
  • Your administrator has enabled the Networking service with the port_forwarding service plugin.

    For information, see Enable floating IP port forwarding for users.

About this task

Important

You cannot deploy FIP port forwarding and distributed FIP management on a router (ovn-router) if any network connected to the router uses VLAN or Flat tenant network types.

If you have one of those configurations, choose a workaround:

  • Use the Geneve network type instead of VLAN or Flat.
  • Disable distribute FIP management to use centralized FIP management:
    enable_distributed_floating_ip = False

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. Use the following command to create port forwarding for a floating IP:
    $ openstack floating ip port forwarding create \
    --internal-ip-address <internal-ip-address> \
    --port <port> \
    --internal-protocol-port <port-number> \
    --external-protocol-port <port-number> \
    --protocol <protocol> \
    <floating-ip>
    • Replace <internal-ip-address> with the internal, destination IP address.

      This is the IP address that is associated with the instance on which the application is running.

    • Replace <port> with the name or ID of the Networking service port to which the instance is attached.
    • Replace <port-number> in --internal-protocol-port with the internal, destination port number.

      This is the port number that the application running in the instance uses.

    • Replace <port-number> in --external-protocol-port with the external, source port number.

      This is the port number that the application running outside of your RHOSP cloud uses.

    • Replace <protocol> with the protocol, such as TCP or UDP, used by the application that receives the port-forwarded traffic.
    • Replace <floating-ip> with the floating IP whose specified port traffic you want to forward.
      Example

      This example creates port forwarding for an instance that is attached to the floating IP 198.51.100.47. The floating IP uses the Networking service port 1adfdb09-e8c6-4708-b5aa-11f50fc22d62. When the Networking service detects incoming, external traffic addressed to 198.51.100.47:80, it forwards the traffic to the internal IP address, 203.0.113.107, on TCP port, 8080:

      $ openstack floating ip port forwarding create \
      --internal-ip-address 203.0.113.107 \
      --port 1adfdb09-e8c6-4708-b5aa-11f50fc22d62 \
      --internal-protocol-port 8080 \
      --external-protocol-port 80 \
      --protocol tcp \
      198.51.100.47

Results

  • Confirm that the Networking service has established forwarding for the floating IP port.
    Example

    The following example verifies successful port forwarding for the floating IP 198.51.100.47:

    $ openstack floating ip port forwarding list 198.51.100.47 \
    -c "Internal Port ID" -c "Internal IP Address" -c "Internal Port" \
    -c "External Port" --max-width 74
    Sample output

    The output shows that traffic sent to the floating IP 198.51.100.47 on TCP port 80 is forwarded to port 8080 on the instance with the internal address 203.0.113.107:

    +------------------+---------------------+---------------+---------------+
    | Internal Port ID | Internal IP Address | Internal Port | External Port |
    +------------------+---------------------+---------------+---------------+
    | 1adfdb09-e8c6-47 | 203.0.113.107       |          8080 |            80 |
    | 08-b5aa-11f50fc2 |                     |               |               |
    | 2d62             |                     |               |               |
    +------------------+---------------------+---------------+---------------+