How to Assign a Fixed IP to an Instance

A private or fixed IP is assigned to an instance based off the network specified on boot. However, the need may arise to re-assign this fixed IP in certain situations.

For example, consider a scenario where a fixed IP associated with an instance is hardcoded into or otherwise being referenced by your application, and the instance needs to be taken down for maintenance while maintaining minimal downtime for the application. Hence, another instance needs to be created to take its place with the same IP.

When such a scenario arises, it is required to re-assign the fixed IP of the instance which is undergoing maintenance to the replacement instance.

Environment

Procedure

For each step, run the provided command on the host for which you have the OpenStack CLI installed.

  1. Remove the IP from the instance.

     openstack server remove fixed ip <INSTANCE_ID> <IP>
    
  2. Add a new IP to the instance.

     openstack server add fixed ip --fixed-ip-address <IP> <INSTANCE_ID> <NETWORK_ID>
    
If attempting to allocate an IP which has a port associated with it already, ensure the port is deleted beforehand.

If the port is active, remove the IP from the instance with which the port is associated, or delete the instance altogether.

Troubleshooting

The following describes any known issues which may arise while performing this procedure and tips on how to resolve them.

Flag --fixed-ip-address is not recognized

openstack server add fixed ip: error: unrecognized arguments: --fixed-ip-address

An older version of the OpenStack CLI is installed. An upgrade of the CLI package is necessary for this flag to be recognized. Refer to the OpenStack CLI section under Additional Information for guidance on installing the latest CLI client.

Additional Information

LBaaS

Leveraging LBaaS (Load Balancer as a Service) is also an option which would allow you to maintain a static IP/endpoint for multiple instances.

External Networks

A floating IP could be used for this purpose if utilizing an external network.

For more information on external networks, refer to Networking with Neutron - Basic Concepts.

OpenStack CLI

For guidance with installing the OpenStack CLI client on your machine, refer to Installing OpenStack CLI Clients.


July 05, 2018