红联Linux门户
Linux帮助

一次与iptables有关的Openstack排错

发布时间:2016-10-23 11:57:25来源:cnblogs.com/IvanChen作者:dongdonggeorge
先说下环境: 宿主机A(192.168.1.242)上运行着实例a(192.168.1.176), 宿主机B(192.168.1.56)上运行着实例b(192.168.1.50).
 
用户说从实例b上telnet实例a的9000端口, 但是在实例a上通过netstat -an | grep 9000查看到的Remote IP并不是实例b的, 而是宿主机B的网卡IP(192.1638.1.56). 于是我想是不是把实例a迁移到宿主机B上来就可以解决问题. 但是很可惜, 答案是否.
 
此时的环境: 宿主机B上运行着实例a和b.
 
于是我从iptables着手排查. 发现在宿主机B上有如下几条重要的规则链:
Chain nova-network-snat (1 references)
pkts bytes target     prot opt in     out     source               destination
312K   20M nova-network-float-snat  all  --  *      *       0.0.0.0/0            0.0.0.0/0
0     0 RETURN     all  --  *      *       192.168.1.60         0.0.0.0/0
2   120 RETURN     all  --  *      *       192.168.1.50         0.0.0.0/0
80764 5060K SNAT       all  --  *      *       192.168.1.32/27      0.0.0.0/0  to:192.168.1.56
Chain nova-postrouting-bottom (1 references)
pkts bytes target     prot opt in     out     source               destination
312K   20M nova-compute-snat  all  --  *      *       0.0.0.0/0            0.0.0.0/0
312K   20M nova-network-snat  all  --  *      *       0.0.0.0/0            0.0.0.0/0
231K   15M nova-api-snat  all  --  *      *       0.0.0.0/0            0.0.0.0/0
Chain POSTROUTING (policy ACCEPT 5 packets, 300 bytes)
pkts bytes target     prot opt in     out     source               destination         
368K   23M nova-compute-POSTROUTING  all  --  *      *       0.0.0.0/0            0.0.0.0/0
368K   23M nova-network-POSTROUTING  all  --  *      *       0.0.0.0/0            0.0.0.0/0
312K   20M nova-api-POSTROUTING  all  --  *      *       0.0.0.0/0            0.0.0.0/0
312K   20M nova-postrouting-bottom  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 
此时问题就显而易见了: 192.168.1.33--62范围里的地址会通过SNAT动作将源地址转换为192.168.1.56. 所以在实例b上看到192.168.1.56这个地址也就解释的通了!
 
由于不清楚这条规则有没有实际作用, 所以我采用手动插入以下规则使之生效:
iptables -t nat -I nova-network-snat 2 -s 192.168.1.50/32 -j RETURN
 
本文永久更新地址:http://www.linuxdiyf.com/linux/25317.html