Manually associating and dissociating floating IPs of instances – OpenStack
Recommended by 0 users
Manually associating floating IPs to instances
OpenStack Networking allocates floating IP addresses to all projects (tenants) from the same IP ranges. Where floating IPs are configured in a deployment, each project will have a limited number of floating IPs controlled by a quota. However, these need to be allocated to the project from the central pool prior to their use—usually by the administrator of the project.
When you create an OpenStack instance, the self-service portal displays all associated fixed IP addresses and any floating IP addresses on the instance. You can use the self-service portal to associate a floating IP address to a fixed IP address on the OpenStack instance. A floating IP address allows the instance to be publicly accessible. Each instance, has a private, fixed IP address and can also have a public, or a floating IP address.
Define a pool of floating IP addresses.
Reserve a specific floating IP address from the pool.
Associate the reserved floating IP address with the instance.
A pool of floating IP addresses, configured by the cloud administrator, is available in OpenStack Compute. The project quota defines the maximum number of floating IP addresses that you can allocate to the project. After you allocate a floating IP address to a project, you can:
- Associate the floating IP address with an instance of the project. Only one floating IP address can be allocated to an instance at any given time.
- Disassociate a floating IP address from an instance in the project.
- Delete a floating IP from the project, which automatically deletes that IP’s associations.
When an instance boots, it is assigned a private IP address. This IP range is only accessible within our virtual environment’s network. To access this instance to serve the rest of the network or the public, we need to assign it a floating IP, which is the range we configure when we set up public IP ranges.
There are two ways to allocate floating IPs to instances: either automatically, as the instance is spawned, or manually through our client tools. In both cases, our tenancy must have a range of floating IPs assigned to it so they can be allocated.
To begin with, ensure you’re logged in to the Controller server (our OpenStack VirtualBox Virtual Machine, controller, created in the Keystone OpenStack Identity Service). If this was created using Vagrant, you can log into this box using the following command:
vagrant ssh controller
While on the controller host, run the following command to list any floating ranges that we have assigned:
sudo nova-manage floating list
This should list the IP range we originally set up when we first installed our openstack1 server.
None 172.16.1.1 None nova eth1 None
172.16.1.2 None nova eth1
To allocate a floating IP to an instance, ensure you’re logged in to a client that is running Nova Client.
How to accomplish it…
To assign a floating (public) IP address to an instance using Nova Client, carry out the following steps:
- To allocate one of the floating IP addresses available to our project, we run the following command:
- An address will appear from the pool of IPs we have available, for example
- To associate this address to an instance, we issue the following command:
nova add-floating-ip \ 6c79552c-7006-4b74- a037-ebe9707cc9ce \ 172.16.1.1
We are now able to communicate with that instance using this assigned floating IP address.
How it works…
Instances are not automatically accessible outside of the OpenStack host unless a public IP address is attached to it. Manually associating an address consists of the following two steps:
- Allocating an address from the available IP range.
- Associating the address with an instance.
This is an important concept, as it allows you to control the allocation of IP addresses as well as allocating specific addresses to specific instances, which is very much like Amazon’s Elastic IP feature.
Manually disassociating floating IPs from instances
In our cloud environment, we have the ability to add and remove access to and from the instance, publicly by adding or removing a floating IP address to or from it. This flexibility allows us to move services seamlessly between instances. To the outside world, it would appear to be the same instance, as their access to it is via that IP that has not changed.
To begin with, ensure you are logged into a client machine with Nova Client installed.
How to do it…
To disassociate a public (floating) address from an instance using Nova Client, carry out the following steps:
- We first list the instance in our environment, to identify the instance we wish to remove the public IP address from, as follows:
- Once we have identified the instance, we wish to disassociate the IP from it, hence we execute the following command:
nova remove-floating-ip \ 2abf8d8d-6f45-
42a5-9f9f-63b6a956b74f \ 172.16.1.1
- This immediately removes the association with this address from the instance.
If we no longer require that floating IP address for our project, we can remove it from our project’s pool by issuing the following command:
nova floating-ip-delete 172.16.1.1
How it works…
Removing a floating IP address is very straightforward. When using Nova Client, we use the remove-floating-ip option to the nova command.