<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/8 Sven Schwedas <span dir="ltr"><<a href="mailto:sven.schwedas@tao.at" target="_blank">sven.schwedas@tao.at</a>></span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

Hi,<br>
<br>
I'm trying to configure nwfilter for KVM, but so far I haven't managed<br>
to figure out a working configuration.<br>
<br>
Network setup: The dom0 (Debian 7.1, kernel 3.2.46-1, libvirt 0.9.12) is<br>
connected via eth0, part of the external subnet <a href="http://192.168.17.0/24" target="_blank">192.168.17.0/24</a>, and has<br>
an additional subnet <a href="http://192.168.128.160/28" target="_blank">192.168.128.160/28</a> routed to its main address<br>
192.168.17.125.<br>
<br>
The host's subnet is configured as bridge in virsh:<br>
> <network><br>
>   <name>foo</name><br>
>   <forward dev='eth0' mode='route'><br>
>     <interface dev='eth0'/><br>
>   </forward><br>
>   <bridge name='foo-br0' stp='off' delay='0' /><br>
>   <ip address='192.168.128.161' netmask='255.255.255.240'><br>
>   </ip><br>
> </network><br>
<br>
The domU is configured to use this bridge (static IP configured in DomU):<br>
<br>
> <interface type='network'><br>
>   <source network='foo'/><br>
>   <target dev='vnet0'/><br>
>   <model type='virtio'/><br>
>   <filterref filter='test-eth0'><br>
>     <parameter name='CTRL_IP_LEARNING' value='none'/><br>
>     <parameter name='IP' value='192.168.128.162'/><br>
>   </filterref><br>
>   <alias name='net0'/><br>
>   <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/><br>
> </interface><br>
<br>
With an empty filter, connectivity is working fine. Now, if I add the<br>
example ruleset suggested in the documentation (<br>
<a href="http://libvirt.org/formatnwfilter.html#nwfwriteexample" target="_blank">http://libvirt.org/formatnwfilter.html#nwfwriteexample</a> ), *incoming*<br>
ICMP works (but not outgoing), and inbound SSH traffic is blocked,<br>
together with outbound DNS.<br>
<br>
The linked rules produce the following iptables chains:<br>
<br>
> Chain INPUT (policy ACCEPT)<br>
> target     prot opt source               destination<br>
> libvirt-host-in  all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
> ACCEPT     udp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            udp dpt:53<br>
> ACCEPT     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp dpt:53<br>
> ACCEPT     udp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            udp dpt:67<br>
> ACCEPT     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp dpt:67<br>
><br>
> Chain FORWARD (policy ACCEPT)<br>
> target     prot opt source               destination<br>
> libvirt-in  all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
> libvirt-out  all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
> libvirt-in-post  all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
> ACCEPT     all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://192.168.128.160/28" target="_blank">192.168.128.160/28</a><br>
> ACCEPT     all  --  <a href="http://192.168.128.160/28" target="_blank">192.168.128.160/28</a>   <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
> ACCEPT     all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
> REJECT     all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            reject-with icmp-port-unreachable<br>
> REJECT     all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            reject-with icmp-port-unreachable<br>
><br>
> Chain OUTPUT (policy ACCEPT)<br>
> target     prot opt source               destination<br>
><br>
> Chain FI-vnet0 (1 references)<br>
> target     prot opt source               destination<br>
> RETURN     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp spt:22 state ESTABLISHED ctdir ORIGINAL<br>
> RETURN     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp spt:80 state ESTABLISHED ctdir ORIGINAL<br>
> RETURN     icmp --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            state NEW,ESTABLISHED ctdir REPLY<br>
> RETURN     udp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            udp dpt:53 state NEW,ESTABLISHED ctdir REPLY<br>
> DROP       all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
><br>
> Chain FO-vnet0 (1 references)<br>
> target     prot opt source               destination<br>
> ACCEPT     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp dpt:22 state NEW,ESTABLISHED ctdir REPLY<br>
> ACCEPT     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp dpt:80 state NEW,ESTABLISHED ctdir REPLY<br>
> ACCEPT     icmp --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            state ESTABLISHED ctdir ORIGINAL<br>
> ACCEPT     udp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            udp spt:53 state ESTABLISHED ctdir ORIGINAL<br>
> DROP       all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
><br>
> Chain HI-vnet0 (1 references)<br>
> target     prot opt source               destination<br>
> RETURN     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp spt:22 state ESTABLISHED ctdir ORIGINAL<br>
> RETURN     tcp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            tcp spt:80 state ESTABLISHED ctdir ORIGINAL<br>
> RETURN     icmp --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            state NEW,ESTABLISHED ctdir REPLY<br>
> RETURN     udp  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            udp dpt:53 state NEW,ESTABLISHED ctdir REPLY<br>
> DROP       all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a><br>
><br>
> Chain libvirt-host-in (1 references)<br>
> target     prot opt source               destination<br>
> HI-vnet0   all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>           [goto]  PHYSDEV match --physdev-in vnet0<br>
><br>
> Chain libvirt-in (1 references)<br>
> target     prot opt source               destination<br>
> FI-vnet0   all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>           [goto]  PHYSDEV match --physdev-in vnet0<br>
><br>
> Chain libvirt-in-post (1 references)<br>
> target     prot opt source               destination<br>
> ACCEPT     all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            PHYSDEV match --physdev-in vnet0<br>
><br>
> Chain libvirt-out (1 references)<br>
> target     prot opt source               destination<br>
> FO-vnet0   all  --  <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>            <a href="http://0.0.0.0/0" target="_blank">0.0.0.0/0</a>           [goto]  PHYSDEV match --physdev-out vnet0<br>
<br>
I've tried fidgeting with the configuration (direction inout instead of<br>
in/out, etc.), but I didn't find a setup that works as intended. What am<br>
I missing?</blockquote><div style>I always use ebtables instead of iptables and everything works fine for me. </div><div style>ebtables works with <span style="background-color:rgb(245,245,245);color:rgb(0,0,0);font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:12px">mac stp vlan arp rarp ipv4 ipv6 , tcp udp works with iptables.   </span> </div>

</div></div></div>