Sometimes you can accidentally broke an instance and when you launch a new one to replace the old one, you want the new instance with the IP address that you had in the old instance.
The steps are very simple, first you have to remove the port that is associated with the instance. You can identify it by its current IP address:
$ sudo neutron port-list --fixed-ips ip_address=172.16.2.128 +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+ | id | name | mac_address | fixed_ips | +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+ | aa2e65ec-bf1c-44c7-b38b-0b27fcc41d8f | | fa:16:3e:05:f2:fe | {"subnet_id": "6be599d7-702f-4e54-b18d-3dfca1441617", "ip_address": "172.16.2.128"} | +--------------------------------------+------+-------------------+-------------------------------------------------------------------------------------+
With the instance stopped remove the port:
$sudo neutron port-delete aa2e65ec-bf1c-44c7-b38b-0b27fcc41d8f Deleted port: aa2e65ec-bf1c-44c7-b38b-0b27fcc41d8f
And now attach a new one with the desired IP address to your instance (c842228b-71e3-49d6-a5b5-33e6416e2669):
$ sudo nova interface-attach --fixed-ip 172.16.2.106 --net-id 26f6d6f9-0ff6-4825-99e8-35c3821f855f c842228b-71e3-49d6-a5b5-33e6416e2669
That’s all, now you can start your instance with the new Ip address.