Monday, October 12, 2015

Bridging KVM guest machines

Kernel-based Virtual Machine (KVM) is a virtualization infrastructure for the Linux kernel that turns it into a hypervisor.Am using KVM to run virtual machines on my server, an alternative of kvm is virtualbox (which most of people are familiar with). When installing guest machines on host machine running kvm by default are assigned 192.168.122.0/0 IP address which is virtual address which are accessible only within the host machine, but not outside.
In this lab am going to show you how to bridge guest machines on kvm where will be accessible outside their host machine.This is archived by bridging them on host machine Ethernet interface and will be receiving dhcp from the router where the host machine is connected. Now lets start:

a. Start the kvm virtual manager

➜  ~   sudo virt-manager 



When booting one of my guest machine, by default it was assigned 192.168.122.122 ip address, see




Now lets configure it, so that will be receiving IP from dhcp server from the router.

b. Host machine configuration

Open host machine terminal and create the virtual bridge interface and add your physical on it, as below

➜  ~  sudo vim /etc/network/interfaces

The file should look as below

# interfaces(5) file used by ifup(8) and ifdown(8)

# Include files from /etc/network/interfaces.d:

source-directory /etc/network/interfaces.d



##########Bridge start#####

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet manual

        up ifconfig $IFACE 0.0.0.0 up

        down ifconfig $IFACE down

auto br0
iface br0 inet static
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8
############Bridge end#######

Where i created an virtual interface named br0 and assigned it one of static ip in the range of my LAN ip.

Then, restart your network service

 ➜  ~  sudo /etc/init.d/networking restart

Note:
I have noticed some cases where restarting the network services is not taking effect, so you will have to restart the whole host machine.

So restart the host machine.

➜  ~  sudo reboot

c. Guest machine configuration
When the host machines comes up, start the virtual machine manager and go to specific guest machine where you want to bride it, Go to Edit ,Virtual Machine Details,Details and then click your virtual interface, as seen below



On source device select Specify shared device name and on bridge name type br0 and then save, as seen below





Your done, restart your guest machine and see if it will receive IP via dhcp.


See, it receive 192.168.0. 10 which is my dhcp range.

Hope it help someone.

No comments:

Post a Comment