Bridged mode is really important if you plan on using your VMs for any sort of server. In NAT mode they will not be able to communicate with any other machines on your local network. Bridged mode makes it so your VMs share the physical interface of your KVM host.
First, we need to install some software:
sudo apt-get install libcap2-bin bridge-utils
From (https://help.ubuntu.com/community/KVM/Networking):
Give qemu the inheritable CAP_NET_ADMIN capability, for 64-bit:
sudo setcap cap_net_admin=ei /usr/bin/qemu-system-x86_64
or for 32-bit:
sudo setcap cap_net_admin=ei /usr/bin/qemu
We will now edit /etc/network/interfaces to add the bridge. Assuming your current config looks like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.10
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
Change it to look like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 192.168.0.10
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
If you are using DHCP, you would want it to look something like this:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
Now we just need to restart networking:
sudo /etc/init.d/networking restart
That's it. You can now start using your new bridge with your VMs. All you have to do is select the bridge created in the VM settings in virt-manager.
Hi; when I try and run sudo setcap cap_net_admin=ei /usr/bin/qemu on my (fairly clean) Ubuntu 12.04, I get the error "Failed to set capabilities on file `/usr/bin/qemu' (No such file or directory)
ReplyDelete". What I tried instead was sudo setcap cap_net_admin=ei /usr/bin/qemu-system-i386. And then proceeded as directed.
Perhaps you can add a section at the end to explain how to test that everything is working properly?
When I try the approach above, my network stops working ie. my browser is no longer able to access common sites like Google. I reverted all the changes.
ReplyDeleteI'm not sure what's wrong. I followed my How-To when I set up some 12.04 boxes and I don't remember having to change anything. That was a few months ago though.
DeleteI'm using Virt-Manager and stuck after setting the bro interface. Your screenshot helps me. Thanks.
ReplyDelete