Examples of practical solutions using a command line interface (CLI)¶
Changing the IP address assigned to the instance port¶
Note
Linking an IP address in Openstack is not done to the instance directly, but to the port that is assigned to it. To change the IP address with which the instance is accessed, therefore, you must change the IP address for the port.
Commands used:
- Show project properties
openstack project show <ProjectName>
- where
<ProjectName> - is the name of the cloud-based project
- Show list of ports for project
openstack port list --project <ProjectID>
- where
<ProjectID> - is the cloud project ID
- Delete current fixed IP address of port
openstack port set --no-fixed-ip <PortID>
- where
<PortID> - is the ID of the port for which the IP address value will be changed
- Assign fixed IP address for port
openstack port set --fixed-ip subnet=<SubnetID>,ip-address=<IPaddress> <PortID>
- where
<SubnetID> - is the subnetwork ID from whose range the IP address will be allocated<IPaddress> - is the IP address that will be assigned to the port<PortID> - is the ID of the port for which the IP address will be assignedInitial data:
- “demo” - is the project name
- 10.100.100.4 - is the current IP address
- 10.100.100.8 - is the new IP address to which we wish to change the current address
Procedure:
1. Define the project ID based on the project nameopenstack project show demo +-------------+----------------------------------+ | Field | Value | +-------------+----------------------------------+ | description | | | domain_id | b90911e0cc464e4d83c04bed2febc37a | | enabled | True | | id | a84030ae422a4173b4d0e7495cda2581 | | is_domain | False | | name | demo | | parent_id | b90911e0cc464e4d83c04bed2febc37a | +-------------+----------------------------------+
- The value in the ‘id’ field (a84030ae422a4173b4d0e7495cda2581) is our ID
2. Obtain a list of ports for the project and their parameters$ openstack port list --project a84030ae422a4173b4d0e7495cda2581 +--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+ | ID | Name | MAC Address | Fixed IP Addresses | Status | +--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+ ... | c9153547-e72a-4f20-8792-6f6574d5baff | | fa:16:3e:a6:d0:0d | ip_address='172.16.0.3', subnet_id='17f8d13a-31cd-494d-a161-95e360ad3cd8' | ACTIVE | | 27ad2d67-e35f-4b6f-877f-fdd36690d72f | | fa:16:3e:22:93:a6 | ip_address='10.100.100.4', subnet_id='8e82d9b3-0757-4ddc-9cf7-c82f1024d277' | ACTIVE | ... +--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+
- Choose the required data:
The ‘ID’ value (c95d4d1d-233b-4322-8b3a-d77df89b3bf1) — is our <PortID> The ‘ip_address’ value (10.100.100.4) - это наш <IPaddress> The ‘subnet_id’ value (8e82d9b3-0757-4ddc-9cf7-c82f1024d277) - is our <SubnetID>3. Now, having obtained all the necessary data:
Delete the old IP address value for our port
openstack port set --no-fixed-ip 27ad2d67-e35f-4b6f-877f-fdd36690d72fAssign the required IP to the port
openstack port set --fixed-ip subnet=8e82d9b3-0757-4ddc-9cf7-c82f1024d277,ip-address=10.100.100.8 27ad2d67-e35f-4b6f-877f-fdd36690d72f4. In the port or instance properties we now see the new IP address we have assigned:$ openstack port list --project a84030ae422a4173b4d0e7495cda2581 +--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+ | ID | Name | MAC Address | Fixed IP Addresses | Status | +--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+ ... | c9153547-e72a-4f20-8792-6f6574d5baff | | fa:16:3e:a6:d0:0d | ip_address='172.16.0.3', subnet_id='17f8d13a-31cd-494d-a161-95e360ad3cd8' | ACTIVE | | 27ad2d67-e35f-4b6f-877f-fdd36690d72f | | fa:16:3e:22:93:a6 | ip_address='10.100.100.8', subnet_id='8e82d9b3-0757-4ddc-9cf7-c82f1024d277' | ACTIVE | ... +--------------------------------------+------+-------------------+-----------------------------------------------------------------------------+--------+