Managing IP Addresses

Each instance has a private, fixed IP address and can also have a public, or floating IP address.

Private IP addresses are used for communication between instances. When you launch an instance, it is automatically assigned a permanent, private IP address. Rebooting an instance has no effect on the private IP address. The private IP address stays the same until you terminate the instance.

Public IP addresses are used for communication with networks outside the cloud, including the Internet. 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 in the project. Only one floating IP address per 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.

To list floating IP addresses that are allocated to the current project:

$ openstack floating ip list
+------------+---------------------+------------------+------+-------------------+--------------+
| ID         | Floating IP Address | Fixed IP Address | Port | Floating Network  | Project      |
+------------+---------------------+------------------+------+-------------------+--------------+
| <float_id> | 184.94.253.86       | None             | None | <network_id>      | <project_id> |
| <float_id> | 184.94.253.94       | None             | None | <network_id>      | <project_id> |
+------------+---------------------+------------------+------+-------------------+--------------+

Note
If the IP addresses in this list are all in use and you are not able to request a new floating IP address, you may need to disassociate or release an IP address or contact your administrator to see if your cloud has reached the project quota.

Associating a Floating IP Address

You can assign a floating IP address to a project and to an instance:

  1. Request a floating IP address from the network.

    $ openstack floating ip create <NETWORK-ID>
    +---------------------+--------------------------+
    | Field               | Value                    |
    +---------------------+--------------------------+
    | created_at          | None                     |
    | description         | None                     |
    | fixed_ip_address    | None                     |
    | floating_ip_address | 184.94.253.77            |
    | floating_network_id | <network_id>             |
    | id                  | <float_id>               |
    | name                | None                     |
    | port_id             | None                     |
    | project_id          | <project_id>             |
    | revision_number     | None                     |
    | router_id           | None                     |
    | status              | DOWN                     |
    | updated_at          | None                     |
    +---------------------+--------------------------+
    
  2. List instances and choose one to associate with your new floating IP.

    $ openstack server list
    +----------------+------------------+--------+-------------------+------------+
    | ID             | Name             | Status | Networks          | Image Name |
    +----------------+------------------+--------+-------------------+------------+
    | <instance_id>  | testdoc          | ACTIVE |                   | ubuntu     |
    | <instance_id>  | test-test        | ACTIVE | test=192.168.30.3 | ubuntu     |
    +----------------+------------------+--------+-------------------+------------+
    
  3. Associate an IP address with an instance.

     $ openstack server add floating ip <INSTANCE> <IP-ADDRESS> 
    
  4. Verify the instance is now associated with two IP addresses: the private, fixed IP address and the public, floating IP address.

    $ openstack server list
    +----------------+------------------+--------+-----------------------------------+------------+
    | ID             | Name             | Status | Networks                          | Image Name |
    +----------------+------------------+--------+-----------------------------------+------------+
    | <instance_id>  | testdoc          | ACTIVE | test=192.168.30.10, 10.210.69.4   | ubuntu     |
    | <instance_id>  | test-test        | ACTIVE | test=192.168.30.3                 | ubuntu     |
    +----------------+------------------+--------+-----------------------------------+------------+
    

    After you associate the IP address and configure security group rules for the instance, the instance is publicly available at the floating IP address.

Note
If an instance is connected to multiple networks, you can associate a floating IP address with a specific fixed IP address using the openstack server create --nic option.

Disassociating a Floating IP Address

You may need to disassociate an IP address from an instance to free the address for use elsewhere within the project. To disassociate a floating IP address from an instance:

$ openstack server remove floating ip <INSTANCE> <IP_ADDRESS>

After deleting the IP address, it is returned to the pool of IP addresses available for all projects. If the IP address is still associated with a running instance, it is automatically disassociated from that instance. To remove the floating IP address from a project:

$ openstack floating ip delete <IP_ADDRESS>