Showing posts with label virtualization. Show all posts
Showing posts with label virtualization. Show all posts

Tuesday, April 24, 2012

Wireless Bridging For KVM

This tutorial aims to establish a wireless bridge between the host wireless interface and the guest Ethernet interface. The guest will behave as standalone machine with dedicated IP address and has full connectivity to the outside world. Even SSH between the host and the guest is available.


Keep in mind that this procedure works only with assigning the guest a static IP address not DHCP but the host can get its IP with static or DHCP.


1. First install parprouted pakcage :
In CentOS :


yum install parprouted


2. Enable IP forwarding in your host:


echo 1 > /proc/sys/net/ipv4/ip_forward


3. Configure the tap interface :


tunctl -t tap0
ip link set tap0 up
ip addr add 10.10.10.10/32 dev tap0


Important : the ip address of tap interface does not have to be in the same  subnet of your wireless and guest IP addresses. For my case the wireless addresses in the subnet 192.168.0.0 network and tap0 is in 10.0.0.0 network, but the guest IP address MUST be on the same network of the wireless interface.


4. Bridge your wireless LAN interface with the tap interface :


parprouted ra0 tap0


My wireless interface is ra0 so replace with your interface (maybe wlan0)


5. If iptables firewall is active , we MUST add rules for allowing connections through tap0 :


vi /etc/sysconfig/iptables


and add the following :



-A INPUT -i tap0 -j ACCEPT 
-A FORWARD -i tap0 -j ACCEPT 
-A FORWARD -o tap0 -j ACCEPT 


6. Now the bridge is ready. Start your VM :


qemu-kvm -hda test.img -m 512 -net nic -net tap,ifname=tap0,script=no


I faced a little problem with the vnc connection : there was two mouse cursors and that was annoying and the solution is simple; add the option
 -usb -usbdevice tablet to the last qemu-kvm command.


7. Inside the guest VM configure its interface with static IP address and this step depends on the type of your guest operating system. Remember : the same subnet of your wireless inerface. 


Example : wlan0 address : 192.168.0.2 
                Guest IP address : 192.168.0.3


Also configure your guest DNS and Default gateway as that of your host.




Monday, March 26, 2012

Creating Permanent Bridged Network Interface

This is very useful in many cases like if you want to add additional security layer using firewall or if you want to rum KVM virtualizaions with permanent interfaces accessed by the hosts as if the guest is a real machine.

I am using Centos 6.2 64 bit and I am using DHCP for assigning IP addressed and DNS and other configurations

1. Install bridge-utils :yum install bridge-utils
2. Bring down the interfaces eth0 : ifdown eth0
3. Edit the configuration file of the eth0 interface to use the bridge and create a new file for the bridge :

vi /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT="yes"
HWADDR=64:31:50:04:93:B9
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
#
BRIDGE=br0

The most important line is BRIDGE=br0 where br0 is the name of the bridge device we shall create.

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

DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
DELAY=0

Note the line TYPE=Bridge

4. The most important part that peventing the bridge from functioning properly was the line :  UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03 in the ifcfg-eth0 file so I commented it out.

5 .Bring up the interfaces : ifup eth0 ; ifup br0;

6. Configure the iptables firewall to accept connections from the new bridge interface br0 :

 vi /etc/sysconfig/iptables
 
Add this line : -A INPUT -i br0 -j ACCEPT

7. Restart the iptables and network services

 service network restart
 service iptables restart

That is it !