立即注册 登录
About云-梭伦科技 返回首页

xng2012的个人空间 https://www.aboutyun.com/?199 [收藏] [复制] [分享] [RSS]

日志

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

已有 1088 次阅读2014-11-8 23:58

之前一直以为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一般也不会变,因此也无伤大雅。


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

关闭

推荐上一条 /2 下一条