Wednesday, December 3, 2014

Setting up KVM in Centos 6.5 with Bridged Networking

NOTE:  This is all assuming your computer supports virtualization.  If you aren't sure run this command as root -> more /proc/cpuinfo | grep vmx  If it returns anything, it should work assuming it is turned on in the bios.

The first thing you need to do is install the KVM Packages

sudo yum install @Virt*
sudo yum install kvm*
sudo yum install libvirt* 

Next you will want to restart the libvertd

sudo service libvertd restart

Now check to make sure its set to start on boot

sudo chkconfig --list | grep libvirtd

if it is not run the following

sudo chkconfig libvrtd on

At this point the KVM should be installed and working.

To run the GUI manager type:

sudo virt-manager

If you are having trouble with connecting to the qemu then run the following:

lsmod | grep kvm

If this doesn't return a value there is an issue.  Double check that your bios has VT enabled.

Now if you want each VM to act as if they are their own entity on the network with their own IP we need to change some things.  I will say this.... I was on a machine with NIS configured and was doing all these changes while my user and once the network is broken, you as the user become unknown when the NIS server can't be reached.  Do all the following as root.

Locate your ethernet config file in /etc/sysconfig/network-scripts/

Lets back it up first

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.bak

Open up the ifcfg file and this is all I have in mine.


The hwaddr is probably already there so don't change the value.  Also the bridge name is what I called the next file so it can be whatever as long as the two match.

Lets create a new file

vim /etc/sysconfig/network-scripts/ifcfg-br0


Like I mentioned the DEVICE name must match the BRIDGE name above.

Now run:

service network restart

To show if the bridge is up and working run

brctl show

If you are running iptables we need to add some new rules to it

iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
service iptables save
service iptables restart

Next we need to add some kernel settings.  Open /etc/sysctl.conf

Add the following:

net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

Close and save. Run the following to verify they were added.

sysctl -p /etc/sysctl.conf
service libvirtd reload

I had issues with NetworkManager so I turned it off

chkconfig NetworkManager off

Now reboot and run virt-manager to start building your VM.

SourceLink Link Link