Automatically assigning floating IPs in OpenStack
When an instance boots, it is assigned a private IP address. This private IP address 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.
Automatically assigning floating IPs to instances gives us the ability, in our environment, to have access to all instances on our network when using the Nova Network modes of Flat, FlatDHCP and VLAN Manager. Although there are times where we might want to manually assign addresses (for example, where we have a limited number of IPs assigned to a tenancy), the convenience of having this done for you is very beneficial and makes our OpenStack environment operate closely to how a cloud like Amazon EC2 operates for example.
To begin with, ensure you are logged in to the Controller node. If this was created using Vagrant, you can log into this node using the following command:
vagrant ssh controller
We will also be using the client machine, so log into your node that has Nova Client installed. If you haven’t created one, the Controller node has this client installed so this can also be used.
How to achieve it…
To ensure each of the instances gets a public (floating) IP address assigned to it when it is launched, carry out the following steps:
- While on our OpenStack API host, run the following command to list any floating ranges we have assigned:
sudo nova-manage floating list
An example of the output when listing the floating IPs is shown as follows, truncated for brevity:
None 172.16.1.1 None nova eth1 None 1
126.96.36.199 None nova eth1
- The values indicate that we have a floating range available for use. Rather than using client tools to assign addresses to instances, a flag in our /etc/nova/nova.conf file ensures our instances are always allocated an address:
- With this added to our nova.conf configuration file, we restart our nova-network and nova-compute services, to pick up the change:
sudo restart nova-compute
sudo restart nova-network
- When an instance spawns, it will automatically be assigned a public floating IP address that we can instantly use to gain access.
How it works…
Instances aren’t automatically accessible outside of the OpenStack host unless a public IP address is assigned to them. Configuring our OpenStack environment so that each instance is assigned an address on launch makes the instances accessible from outside networks.