<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 5, 2017 at 4:29 PM, Nicolas Bock <span dir="ltr"><<a href="mailto:nicolasbock@gmail.com" target="_blank">nicolasbock@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I am running a webserver on the libvirt host and would like to add a nwfilter such that a VM can access that server. The corresponding iptables rule would look like this:<br>
<br>
iptables --append INPUT --in-interface virbr0 --destination 192.168.122.1 --protocol tcp --dport 80 --jump ACCEPT<br>
<br>
where the network is using virbr0 and sits at 192.168.122.1. I don't want to hardcode the host IP address in the nwfilter so that I can use that filter for other networks. Is it possible to reference the host's IP address in the filter?<br>
<br>
Thanks!<br>
<br>
Nick<br>
<br></blockquote><div>Hi Nick,</div><div><br></div><div>I used to have similar question before too. Not sure if this could be helpful for you,</div><div>Probably just use arp or arpscan. But to be more specific, if the domain name of the </div><div>client (assuming you want to confine HTTP service to only a selected few clients, e.g.,</div><div>192.168.122.1 in your case) is known, you probably could do</div><div><br></div><div><div>$ virsh domiflist DOMAIN</div><div><br></div><div>In particular, to get the IP address of a domain, it is something like the following:</div><div><br></div><div>$ for MAC in `virsh domiflist <DOMAIN> | grep -o -E "([0-9a-f]{2}:){5}([0-9a-f]{2})"` ; do </div><div>        arp -e | grep $MAC  | grep -o -P "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ; </div><div>   done <br></div><div><br></div><div>Alternatively, if the NETWORK name is known, IP addr can be obtained directly with</div><div><br></div><div>$ virsh net-dhcp-leases NETWORK<br></div><div><br></div><div>Another way to the get IP addr, if qemu guest agent is installed on the client, </div><div><br></div><div>$ virsh domifaddr DOMAIN</div></div><div><br></div><div>So that you can pass IP to the XML, and somehow you can trigger the update of</div><div>NWFILTER with some magic, quite a hack.</div><div><br></div><div>Or, you could just use client's MAC addr to define the filter:</div><div><a href="https://libvirt.org/formatnwfilter.html#nwfelemsRulesProtoMAC">https://libvirt.org/formatnwfilter.html#nwfelemsRulesProtoMAC</a><br></div><div><br></div><div>But I don't think there is direct way to specify a client's domain name in</div><div>the NWFILTER XML definition as of now.</div><div><br></div><div>P.S. I am new to libvirt, so everything above could be wrong.</div><div><br></div><div>Dan</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
______________________________<wbr>_________________<br>
libvirt-users mailing list<br>
<a href="mailto:libvirt-users@redhat.com" target="_blank">libvirt-users@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvirt-users" rel="noreferrer" target="_blank">https://www.redhat.com/mailman<wbr>/listinfo/libvirt-users</a><br>
</blockquote></div><br></div></div>