Hello,
I came across an interesting problem in my home lab a few weeks ago as I'm prepping for my RHCE exam using Michael Jang study guide. I've been at this for days now, and I still can't wrap my head around how two or more virtual networks in default NAT configuration are even allowed to communicate with each other despite what the libvirt documentation said.
By default, guests that are connected via a virtual network with <forward mode='nat'/> can make any outgoing network connection they like. Incoming connections are allowed from the host, and from other guests connected to the same libvirt network, but all other incoming connections are blocked by iptables rules.
Also here's another assertion from 'The virtual network driver' section in
http://libvirt.org/firewall.html:
type=nat
Allow inbound related to an established connection. Allow outbound, but only from our expected subnet. Allow traffic between guests. Deny all other inbound. Deny all other outbound.
I have three virtual networks with the following configs:
-----------------------------------------------------------------------------
<network connections='1'>
<name>default</name>
<uuid>9c6796be-d54e-42bc-bcbe-2e4feee7154a</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:5a:5d:0e'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
<network connections='1'>
<name>outsider</name>
<uuid>247e380a-8795-466a-b94a-5be2d05267bb</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr1' stp='on' delay='0'/>
<mac address='52:54:00:7f:a1:fb'/>
<domain name='outsider'/>
<ip address='192.168.100.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.100.2' end='192.168.100.254'/>
</dhcp>
</ip>
</network>
<network connections='1'>
<name>besider</name>
<uuid>cc714cce-dbba-452d-b2bf-d36084dcb723</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr2' stp='on' delay='0'/>
<mac address='52:54:00:59:67:7f'/>
<domain name='besider'/>
<ip address='192.168.110.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.110.2' end='192.168.110.254'/>
</dhcp>
</ip>
</network>
----------------------------------------------------------------------------
Here is the output of the 'FORWARD' iptables chain rules on my host (still using firewall-cmd):
------------------------------------------------------------------------
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
--------------------------------------------------------------------------
I have a VM in each network:
nest3.example.net (virbr2) - 192.168.110.25
I'm quite aware the above iptables rules were added by libvirt, but I'm still managing the firewall primarily through the
firewall-cmd command.
From what I gathered...
----------------------------------------------------------
nest3 can ping nest1 and nest2.
Nest3 ping nest1 and made a hit here:
Nest3 ping nest2 and made a hit here:
----------------------------------------------------------
----------------------------------------------------------
Nest1 can ping nest2, but cannot ping nest3.
Nest1 ping nest2 and made a hit here:
Nest1 ping nest3 and made a hit here:
----------------------------------------------------------
----------------------------------------------------------
Nest2 cannot ping nest1 and nest3.
Nest2 ping nest1 and made a hit here:
Nest2 ping test3 and made a hit here:
----------------------------------------------------------
From my observation, I see that the order of the virtual networks in the iptables FORWARD chain makes a difference. Each chunk associated with the virtual network in the chain, consisting of five lines, is exactly as described in the aforementioned link (
http://libvirt.org/firewall.html). The virtual network in the top chunk of the chain can communicate with virtually all networks as opposed to the network in the last chunk that is consistent with the intention of the original design.
I'm using CentOS 7.3 with libvirt 2.0. I even tried reproducing this with CentOS 6.9 as I thought it was possible the firewalld may have influenced the change, but I was still getting similar result.
Right now, I'm not certain if this is already a reported known bug, but I'm highly convinced this configuration is unofficially unsupported for quite a while. Can someone confirm this? This is my very first mailing list submission ever, and I apologize in advance if I couldn't figure out how to conveniently search up a similar discussion as this one in the archive. If this is in fact near impossible to implement in accordance to the intended design, then I'd like to have this confirmation publicly included in the docs.
Thanks,
Travis Johnson