When you're using kvm to run virtual machines, you more than likely also want them to have some sort of network access. There's two very basic setups that seem useful:
This configuration is, thanks to some recent additions to libvirt, available by default. Recent versions of libvirt, e.g. the 0.2.2 in rawhide, set everything up by default, and all you need to do is to make sure the virt-install command you use to create the guest looks something like
virt-install --accelerate --hvm --connect qemu:///system \
--network network:default \
... usual options for memory/disk files/boot CD ...
(Of course, if you're using virt-manager, this is a simple matter of pointing and clicking the right thing
)
If you have dnsmasq installed, and you should, libvirt will start dnsmasq to provide DHCP and DNS for the guests on the default network, and you'll have your very own, completely enclosed network for the guests, that is NAT'd and forwarded over the host's physical network connections.
If you're curious, the default network is described in the file /etc/libvirt/qemu/networks/default.xml If you make changes to it, you need to let libvirt know by using the virsh net-* commands.
Assuming you have one physical NIC on your host, and you want to bridge all the guests onto the physical network, you need to setup a bridge for that and enslave the physical NIC to it. We'll call the bridge eth0 and the physical device peth0. Note that the bridge device eth0 is the one that receives an IP address. With that, you need to put two files into /etc/sysconfig/network-scripts: the file ifcfg-peth0 should be
DEVICE=peth0
ONBOOT=yes
BRIDGE=eth0
HWADDR=XX:XX:XX:XX:XX:XX
and the file ifcfg-eth0 should be
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Bridge
You also want to add an iptables rule that allows forwarding of packets on the bridged physical NIC (otherwise DHCP from your guests won't work):
# service iptables start
# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
# service iptables save
You can now create your guests and add them to the bridge by running virt-install like so:
virt-install --accelerate --hvm --connect qemu:///system \
--bridge eth0 \
... usual options for memory/disk files/boot CD ...
peth0 and the bridge eth0 didn't work for me last week. Dan Berrange pointed out that that does work for him. I just tried it on a freshly installed rawhide box, and things seem to be working fine.Comments are closed for this post.