5.4. 分配随机浮动 IP
您可以从外部 IP 地址池动态为虚拟机实例分配浮动 IP 地址。
先决条件
可路由的外部 IP 地址池。
更多信息请参阅 第 5.1 节 “创建浮动 IP 池”。
流程
输入以下命令从池中分配浮动 IP 地址。在本例中,网络名为
public
。示例
$ openstack floating ip create public
输出示例
在以下示例中,新分配的浮动 IP 是
192.0.2.200
。您可以将其分配给实例。+---------------------+--------------------------------------------------+ | Field | Value | +---------------------+--------------------------------------------------+ | fixed_ip_address | None | | floating_ip_address | 192.0.2.200 | | floating_network_id | f0dcc603-f693-4258-a940-0a31fd4b80d9 | | id | 6352284c-c5df-4792-b168-e6f6348e2620 | | port_id | None | | router_id | None | | status | ACTIVE | +---------------------+--------------------------------------------------+
输入以下命令查找您的实例:
$ openstack server list
输出示例
+-------------+-------------+--------+-------------+-------+-------------+ | ID | Name | Status | Networks | Image | Flavor | +-------------+-------------+--------+-------------+-------+-------------+ | aef3ca09-88 | prod-serv1 | ACTIVE | public=198. | rhel8 | review- | | 7d-4d20-872 | | | 51.100.56 | | ephemeral | | d-1d1b49081 | | | | | | | 958 | | | | | | | | | | | | | +-------------+-------------+--------+-------------+-------+-------------+
将实例名称或 ID 与浮动 IP 关联。
示例
$ openstack server add floating ip prod-serv1 192.0.2.200
验证步骤
输入以下命令确认您的浮动 IP 与您的实例相关联。
示例
$ openstack server show prod-serv1
输出示例
+-----------------------------+------------------------------------------+ | Field | Value | +-----------------------------+------------------------------------------+ | OS-DCF:diskConfig | MANUAL | | OS-EXT-AZ:availability_zone | nova | | OS-EXT-STS:power_state | Running | | OS-EXT-STS:task_state | None | | OS-EXT-STS:vm_state | active | | OS-SRV-USG:launched_at | 2021-08-11T14:45:37.000000 | | OS-SRV-USG:terminated_at | None | | accessIPv4 | | | accessIPv6 | | | addresses | public=198.51.100.56,192.0.2.200 | | | | | config_drive | | | created | 2021-08-11T14:44:54Z | | flavor | review-ephemeral | | | (8130dd45-78f6-44dc-8173-4d6426b8e520) | | hostId | 2308c8d8f60ed5394b1525122fb5bf8ea55c78b8 | | | 0ec6157eca4488c9 | | id | aef3ca09-887d-4d20-872d-1d1b49081958 | | image | rhel8 | | | (20724bfe-93a9-4341-a5a3-78b37b3a5dfb) | | key_name | example-keypair | | name | prod-serv1 | | progress | 0 | | project_id | bd7a8c4a19424cf09a82627566b434fa | | properties | | | security_groups | name='default' | | status | ACTIVE | | updated | 2021-08-11T14:45:37Z | | user_id | 4b7e19a0d723310fd92911eb2fe59743a3a5cd32 | | | 45f76ffced91096196f646b5 | | volumes_attached | | +-----------------------------+------------------------------------------+
其他资源
- 命令行界面参考中的 floating ip create
- Command Line Interface Reference 中的 server add floating ip
- 命令行界面参考中的 server show
- 创建浮动 IP 池