ebtables是linux专门做二层数据链路层过滤的。
root@node1:~# ebtables -t nat -L
Bridge table: nat
Bridge chain: PREROUTING, entries: 2, policy: ACCEPT
-i tap0678bf1d-41 -j libvirt-I-tap0678bf1d-41
-i tap496fa038-9e -j libvirt-I-tap496fa038-9e
Bridge chain: OUTPUT, entries: 0, policy: ACCEPT
Bridge chain: POSTROUTING, entries: 0, policy: ACCEPT
Bridge chain: libvirt-I-tap0678bf1d-41, entries: 4, policy: ACCEPT
-j I-tap0678bf1d-41-mac
-p IPv4 -j I-tap0678bf1d-41-ipv4-ip
-p ARP -j I-tap0678bf1d-41-arp-mac
-p ARP -j I-tap0678bf1d-41-arp-ip
Bridge chain: I-tap0678bf1d-41-mac, entries: 2, policy: ACCEPT
-s fa:16:3e:a6:5f:70 -j RETURN
-j DROP
Bridge chain: I-tap0678bf1d-41-ipv4-ip, entries: 3, policy: ACCEPT
-p IPv4 --ip-src 0.0.0.0 --ip-proto udp -j RETURN
-p IPv4 --ip-src 10.16.0.131 -j RETURN
-j DROP
Bridge chain: I-tap0678bf1d-41-arp-mac, entries: 2, policy: ACCEPT
-p ARP --arp-mac-src fa:16:3e:a6:5f:70 -j RETURN
-j DROP
Bridge chain: I-tap0678bf1d-41-arp-ip, entries: 2, policy: ACCEPT
-p ARP --arp-ip-src 10.16.0.131 -j RETURN
-j DROP
Bridge chain: libvirt-I-tap496fa038-9e, entries: 4, policy: ACCEPT
-j I-tap496fa038-9e-mac
-p IPv4 -j I-tap496fa038-9e-ipv4-ip
-p ARP -j I-tap496fa038-9e-arp-mac
-p ARP -j I-tap496fa038-9e-arp-ip
Bridge chain: I-tap496fa038-9e-mac, entries: 2, policy: ACCEPT
-s fa:16:3e:58:1:ac -j RETURN
-j DROP
Bridge chain: I-tap496fa038-9e-ipv4-ip, entries: 3, policy: ACCEPT
-p IPv4 --ip-src 0.0.0.0 --ip-proto udp -j RETURN
-p IPv4 --ip-src 10.16.0.111 -j RETURN
-j DROP
Bridge chain: I-tap496fa038-9e-arp-mac, entries: 2, policy: ACCEPT
-p ARP --arp-mac-src fa:16:3e:58:1:ac -j RETURN
-j DROP
Bridge chain: I-tap496fa038-9e-arp-ip, entries: 2, policy: ACCEPT
-p ARP --arp-ip-src 10.16.0.111 -j RETURN
-j DROP
在通过nova创建虚拟机后,会生成libvirt的一个xml配置文件
路径在:/etc/libvirt/nwfilter/nova-base.xml
里面定义了以下规则,这些规则限制了在虚拟机上的地址,在二层上就做了过滤
<filter name='nova-base' chain='root'>
<uuid>12ec8693-253a-7db0-7cd3-f8cc0a1e1b02</uuid>
<filterref filter='no-mac-spoofing'/>
<filterref filter='no-ip-spoofing'/>
<filterref filter='no-arp-spoofing'/>
<filterref filter='allow-dhcp-server'/>
</filter>
然后为每个虚拟机创建一个xml文件,每个虚拟机的xml配置中包含了nova-base.xml中的配置
打开其中一个虚拟机的xml配置,可以看到,这个配置文件中只放行了指定IP在二层上可以通过,所以其它手动配置的地址是不可用的。
cat /etc/libvirt/nwfilter/nova-instance-instance-0000000f-fa163e5801ac.xml
<filter name='nova-instance-instance-0000000f-fa163e5801ac' chain='root'>
<uuid>972d18be-2db0-4bf2-2853-a0a61beac036</uuid>
<filterref filter='nova-base'>
<parameter name='DHCPSERVER' value='10.16.0.102'/>
<parameter name='IP' value='10.16.0.111'/>
<parameter name='PROJMASK' value='255.255.255.0'/>
<parameter name='PROJNET' value='10.16.0.0'/>
</filterref>
</filter>
libvirt可以通过在这些xml配置的规则,去生成ebtables规则,最终是ebtables做出限制。
如何破解?
修改nova-base.xml文件
注释掉以下三行
<filterref filter='no-mac-spoofing'/>
<filterref filter='no-ip-spoofing'/>
<filterref filter='no-arp-spoofing'/>
然后重启libvirt进程,libvirt会重新读取xml中的配置,生成新的ebtables规则。
修改后,我通过新建虚拟机,重启nova-computer进程,或者直接重启宿主机,这个base文件都不会发生变化了。
还有就是修改nova源码(未测试)
源码位置在
/usr/lib/python2.7/dist-packages/nova/virt/libvirt/firewall.py
第198行(G版本中)
去掉no-mac-spoofing,no-ip-spoofing,no-arp-spoofing这三行,以后生成nova-base.xml文件就可以不包含这3个选项了。
转载:http://lustlost.blog.51cto.com/2600869/1324832