Chapter 3. Managing floating IP addresses
Chapter 3. Managing floating IP addresses In addition to having a private, fixed IP address, VM instances can have a public, or floating IP address to communicate with other networks. The information in this section describes how to create and manage floating IPs with the Red Hat OpenStack Services on OpenShift (RHOSO) Networking service (neutron). This section contains the following topics: Section 3.1, "Assigning a specific floating IP" Section 3.2, "Creating floating IP pools" Section 3.3, "Assigning a random floating IP" Section 3.4, "Creating port forwarding for a floating IP" 3.1. Assigning a specific floating IP You can assign a specific floating IP address to a VM instance in a Red Hat OpenStack Services on OpenShift (RHOSO) environment. Prerequisites 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 resides on your workstation. Procedure Confirm that the system OS_CLOUD variable is set for your cloud: USD echo USDOS_CLOUD my_cloud Reset the variable if necessary: USD 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. 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. USD openstack server add floating ip prod-serv1 192.0.2.200 Validation steps Confirm that your floating IP is associated with your instance. Example USD 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 | | +-----------------------------+------------------------------------------+ Additional resources Assigning a random floating IP 3.2. Creating floating IP pools You can use floating IP addresses to direct ingress network traffic to your Red Hat OpenStack Services on OpenShift (RHOSO) instances. First, you must define a pool of routable external IP addresses, which you can then assign to instances dynamically. The RHOSO Networking service (neutron) routes all incoming traffic destined for that floating IP to the instance that you associate with the floating IP. Note 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 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 . Prerequisites 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 resides on your workstation. Procedure Confirm that the system OS_CLOUD variable is set for your cloud: USD echo USDOS_CLOUD my_cloud Reset the variable if necessary: USD 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. 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: USD 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 steps 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 . Additional resources subnet create in the Command line interface reference Assigning a random floating IP 3.3. Assigning a random floating IP You can dynamically allocate floating IP addresses to VM instances in your Red Hat OpenStack Services on OpenShift (RHOSO) environment from a pool of external IP addresses. Prerequisites 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 resides on your workstation. A pool of routable external IP addresses. For more information, see Section 3.2, "Creating floating IP pools" . Procedure Confirm that the system OS_CLOUD variable is set for your cloud: USD echo USDOS_CLOUD my_cloud Reset the variable if necessary: USD 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. 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 . USD 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 | +---------------------+--------------------------------------------------+ Enter the following command to locate your instance: USD 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 | | | | | | | | | | | | | +-------------+-------------+--------+-------------+-------+-------------+ Associate the instance name or ID with the floating IP. Example USD openstack server add floating ip prod-serv1 192.0.2.200 Validation steps Enter the following command to confirm that your floating IP is associated with your instance. Example USD 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 | | +-----------------------------+------------------------------------------+ Additional resources Creating floating IP pools 3.4. Creating port forwarding for a floating IP You can use the Red Hat OpenStack Services on OpenShift (RHOSO) Networking service (neutron) to set up port forwarding for a floating IP. Prerequisites 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 resides on your workstation. Your administrator has enabled the Networking service with the port_forwarding service plug-in. For information, see Configuring floating IP port forwarding in Configuring networking services . Procedure Confirm that the system OS_CLOUD variable is set for your cloud: USD echo USDOS_CLOUD my_cloud Reset the variable if necessary: USD 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. Use the following command to create port forwarding for a floating IP: USD 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 : USD 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 Verification 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 : USD 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 | | | | +------------------+---------------------+---------------+---------------+
dnf list installed python-openstackclient echo USDOS_CLOUD my_cloud export OS_CLOUD=my_other_cloud openstack server add floating ip prod-serv1 192.0.2.200 openstack server show prod-serv1 +-----------------------------+------------------------------------------+ | 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 | | +-----------------------------+------------------------------------------+ dnf list installed python-openstackclient echo USDOS_CLOUD my_cloud export OS_CLOUD=my_other_cloud 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 dnf list installed python-openstackclient echo USDOS_CLOUD my_cloud export OS_CLOUD=my_other_cloud openstack floating ip create public +---------------------+--------------------------------------------------+ | 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 | +---------------------+--------------------------------------------------+ openstack server list +-------------+-------------+--------+-------------+-------+-------------+ | 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 | | | | | | | | | | | | | +-------------+-------------+--------+-------------+-------+-------------+ openstack server add floating ip prod-serv1 192.0.2.200 openstack server show prod-serv1 +-----------------------------+------------------------------------------+ | 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 | | +-----------------------------+------------------------------------------+ dnf list installed python-openstackclient echo USDOS_CLOUD my_cloud export OS_CLOUD=my_other_cloud 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> 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 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 +------------------+---------------------+---------------+---------------+ | Internal Port ID | Internal IP Address | Internal Port | External Port | +------------------+---------------------+---------------+---------------+ | 1adfdb09-e8c6-47 | 203.0.113.107 | 8080 | 80 | | 08-b5aa-11f50fc2 | | | | | 2d62 | | | | +------------------+---------------------+---------------+---------------+