羊的窝

for 羊 in 佛 旅行 英语 香水 道 清明梦 Linux; do wget http://Matt.BackOZ.info:88 >> $羊; done

利用tcpdump诊断iptables防火墙设置错误引起KVM虚拟机的网络问题

yang | 13 七月, 2010 10:13

有一台打印服务器(win2000 Server)与虚拟机(win2003)在不同网段,可以ping通,但虚拟机无法共享打印服务器上的HP打印机。今天偶然使用tcpdump诊断其他问题时,发现以前的打印机问题。

环境(IP地址虚构):

打印服务器 物理机 Win2000 Server ip 10.8.0.5/24 gw 10.8.0.1
虚拟机服务器 KVM&OpenVZ Debian 5 ip 192.168.1.2/24 gw 192.168.1.1
打印客户机 虚拟机 KVM Win2003 Server ip 192.168.1.3/24 gw 192.168.1.1

三台服务器可以通过网关10.8.0.1 / 192.168.1.1 互通,生产业务无任务问题,但192.168.1.3的机器无法使用打印服务器10.8.0.5上面共享出来的HP打印机。

在Win2003 Server 上 ping 打印服务器 10.8.0.5 再使用tcpdump在虚拟机服务器上抓包,

vemast-10:/var/lib/vz/template/iso# tcpdump -vv -nn -i vmbr0 host 10.8.0.5


18:38:57.518393 IP (tos 0x0, ttl 128, id 13955, offset 0, flags [none], proto ICMP (1), length 60) 192.168.1.2 > 10.8.0.5: ICMP echo request, id 512, seq 1280, length 40
18:38:57.518717 IP (tos 0x0, ttl 126, id 59040, offset 0, flags [none], proto ICMP (1), length 60) 10.8.0.5 > 192.168.1.2: ICMP echo reply, id 512, seq 1280, length 40
18:38:58.507354 IP (tos 0x0, ttl 128, id 13984, offset 0, flags [none], proto ICMP (1), length 60) 192.168.1.2 > 10.8.0.5: ICMP echo request, id 512, seq 1536, length 40
18:38:58.507631 IP (tos 0x0, ttl 126, id 59042, offset 0, flags [none], proto ICMP (1), length 60) 10.8.0.5 > 192.168.1.2: ICMP echo reply, id 512, seq 1536, length 40

发现发起ping的机器IP为虚拟机服务器的192.168.1.2 而不是打印客户机的192.168.1.3。经检查

 vemast-10:/var/lib/vz/template/iso# iptables -t nat -nL


Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

原来在服务器配置初为了方便将NAT打开了。删除MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0 这一条后,重启Win2003 Server即恢复正常。

评论

发表评论
 authimage
 
旅行图册 - English Blog - 中文网志 - 米呀的网志
Powered by Redhat - Apache - Mysql - PHP - LifeType