现在的位置: 首页 > 综合 > 正文

openstack 虚拟机不配置floating ip不能访问外网的问题

2014年05月15日 ⁄ 综合 ⁄ 共 1362字 ⁄ 字号 评论关闭

之前一直以为openstack虚拟机没有配置floating ip就不能访问外网。其实是没有配置floating ip的VM也是可以访问外网的。

fixed_ip使用的网段是100.100.100.0/24。

需要在nova.conf中有以下配置:fixed_range="100.100.100.0/24" (fixed_range的默认配置是10.0.0.0/24)

简单验证:

[root@compute1 ~]# nova list
+--------------------------------------+----------+--------+----------------------------+
| ID                                   | Name     | Status | Networks                   |
+--------------------------------------+----------+--------+----------------------------+
| 08d11d8d-a958-441d-be60-60e32c39a05f | test3    | ACTIVE | private-net=100.100.100.3  |

+--------------------------------------+----------+--------+----------------------------+

[root@compute1 ~]# ssh cirros@100.100.100.3
cirros@100.100.100.3's password: 


$ sudo su -
# ping g.cn
PING g.cn (74.125.31.160): 56 data bytes
64 bytes from 74.125.31.160: seq=0 ttl=32 time=72.407 ms
64 bytes from 74.125.31.160: seq=1 ttl=32 time=68.134 ms


实现原理:

nova-network会在nova-network-snat中添加中添加SNAT规则, 从fixed_ip网段经过public_interface出去的包进行SNAT。实现了网关的作用。从这点上看,floating IP的实现是floating ip到fixed ip的全端口映射。

[root@compute1 ~]# iptables -nvL nova-network-snat -t nat
Chain nova-network-snat (1 references)
 pkts bytes target     prot opt in     out     source               destination         
  142 17018 nova-network-float-snat  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    1    84 SNAT       all  --  *      eth0    100.100.100.0/24     0.0.0.0/0           to:10.224.148.12 

另外,似乎将此处snat 10.224.148.12(eth0的ip)改为masquerade会更灵活些,当然eth0的ip一般也不会变,因此也无伤大雅。

抱歉!评论已关闭.