一.网络选项1
创建提供商网络
创建提供商网络
#创建网络
openstack network create --share --external --provider-physical-network provider --provider-network-type flat provider
#创建子网
openstack subnet create --network provider --allocation-pool start=START_IP_ADDRESS,end=END_IP_ADDRESS --dns-nameserver DNS_RESOLVER --gateway PROVIDER_NETWORK_GATEWAY --subnet-range PROVIDER_NETWORK_CIDR provider
#例子
openstack subnet create --network provider --allocation-pool start=10.0.0.100,end=10.0.0.250 --dns-nameserver 8.8.4.4 --gateway 10.0.0.1 --subnet-range 10.0.0.0/24 provider
二.网络选项2
如果使用网络选项2,需要创建提供商网络和自助网络
1.创建提供商网络
创建提供商网络
#创建网络
openstack network create --share --external --provider-physical-network provider --provider-network-type flat provider
#创建子网
openstack subnet create --network provider --allocation-pool start=10.0.0.100,end=10.0.0.250 --dns-nameserver 8.8.4.4 --gateway 10.0.0.1 --subnet-range 10.0.0.0/24 provider
2.创建自助网络
创建自助网络
#创建网络
openstack network create selfservice
#创建子网
openstack subnet create --network selfservice --dns-nameserver DNS_RESOLVER --gateway SELFSERVICE_NETWORK_GATEWAY --subnet-range SELFSERVICE_NETWORK_CIDR selfservice
#例子
openstack subnet create --network selfservice --dns-nameserver 192.168.189.2 --gateway 10.0.0.1 --subnet-range 10.0.0.0/24 selfservice
3.创建路由器
#创建路由器
openstack router create router
#将自助服务网络子网添加为路由器上的接口:
openstack router add subnet router selfservice
#在路由器上的提供程序网络上设置网关
openstack router set router --external-gateway provider
4.验证
#列出网络命名空间。您应该看到一个命名空间qrouter和两个命名空间qdhcp
$ ip netns
qrouter-89dd2083-a160-4d75-ab3a-14239f01ea0b
qdhcp-7c6f9b37-76b4-463e-98d8-27e5686ed083
qdhcp-0e62efcd-8cee-46c7-b163-d8df05c3c5ad
#列出端口(和路由器相连的端口)
$ openstack port list --router router
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------+--------+
| ID | Name | MAC Address | Fixed IP Addresses | Status |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------+--------+
| bff6605d-824c-41f9-b744-21d128fc86e1 | | fa:16:3e:2f:34:9b | ip_address='172.16.1.1', subnet_id='3482f524-8bff-4871-80d4-5774c2730728' | ACTIVE |
| d6fe98db-ae01-42b0-a860-37b1661f5950 | | fa:16:3e:e8:c1:41 | ip_address='203.0.113.102', subnet_id='5cc70da8-4ee7-4565-be53-b9c011fca011' | ACTIVE |
+--------------------------------------+------+-------------------+-------------------------------------------------------------------------------+--------+
$ ping -c 4 203.0.113.102
PING 203.0.113.102 (203.0.113.102) 56(84) bytes of data.
64 bytes from 203.0.113.102: icmp_req=1 ttl=64 time=0.619 ms
64 bytes from 203.0.113.102: icmp_req=2 ttl=64 time=0.189 ms
64 bytes from 203.0.113.102: icmp_req=3 ttl=64 time=0.165 ms
64 bytes from 203.0.113.102: icmp_req=4 ttl=64 time=0.216 ms
--- 203.0.113.102 ping statistics ---
rtt min/avg/max/mdev = 0.165/0.297/0.619/0.187 ms