20 May 2014
(updated 24 May 2014 at 11:25 UTC) »
Static IPs and DNS for VM guests in Fedora 20
I recently needed to let my guest VMs talk to each other, which I did by assigning them static IPs as described below. Most of this is documented in Virtual Networking
page of the libvirt wiki.Add VM host and guests to /etc/hosts on the host, choosing a static IP for each guest
192.168.122.1 vhost.virtdomain vhost
192.168.122.2 guest1.virtdomain guest1
Find each guest's MAC address:
[root@localhost ~]# virsh domiflist guest1(You can find this info via the virt-manager GUI instead if you prefer.)Add <host> entries mapping MAC to the static IPRun virsh net-edit default to edit the virtual network configuration
Interface Type Source Model MAC
- network default virtio 52:54:00:ab:cd:ef
killall -HUP dnsmasq
Now dnsmasq will make the host's /etc/hosts available to all guests.restart libvirtd
systemctl restart libvirtd.service
Exporting an NFSv3 mount to guest VMs in Fedora 20
<range start='192.168.122.2' end='192.168.122.254'/>
<host mac='52:54:00:ab:cd:ef' name='guest1.virtdomain' ip='192.168.122.2'/>
With my virtual network configured how I wanted it, I could use NFS to share the host's filesystem with the guests. Most of the documentation I found on exporting an FS said to use the 9p protocol, but although that's supported in the Fedora kernel, it isn't supported by my RHEL6 and BSD guests, so I went for NFS. Figuring out the NFS config was harder than the network setup as all the documentation I found was outdated and/or didn't work on Fedora 20.
* On the host:Edit /etc/exports to define the mount point:/foo/bar 192.168.122.0/24(ro,async)
(In my case I'm using ro so I'll only export a read-only filesystem.)Enable the NFS server
systemctl enable nfs-server.service
systemctl restart nfs-server.service
You should be able to list the available exports on the localhost
Configure firewallAdd the virtual network interface to a firewalld zone (I used "internal") and allow 'nfs', 'rpc-bind' and 'mountd' in that zone.Make changes to the "permanent" profile to survive past restart, the runtime profile is not persistent, but can be useful for testing changes.
* On each guest:You should be able to list the available exportsshowmount -e 192.168.122.1
(If you set up DNS as described above you should be able to use host or host.virtdomain instead of the IP address.)
Mount the exported filesystemmkdir /mnt/host
mount -t nfs -o nfsvers=3 192.168.122.1:/foo/bar /mnt/host
By default the clients seemed to want to use NFSv4, so trying to mount failed with an "access denied" error.
On RHEL6 I needed nfsvers=3 in the options, on BSD I needed nfsv3.
If that works correctly you can add it to etc/fstab to make it permanent.