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.




Saturday, April 7, 2012

Adding Additional Options to DHCP Client on Centos

I struggled to solve this :)
I wanted to add a dns server to /etc/resolv.conf before the name server the client gets from dhcp server.

In Debian based linux the procedure is to add the option to /etc/dhclient.conf or similar then restart the network or bring up the interface, But in Centos / RHEL there is some trick :

You have to create a file named dhclient-<interface_name>.conf in the /etc.

Example :

 To add another dns for the eth0 interface create : /etc/dhclient-eth0.conf
file and add this line to it :
prepend domain-name-servers 10.1.1.1;

Where 10.1.1.1 is your additional name server

In fact it is more logical as you can have different settings for different interfaces.


Monday, April 2, 2012

Anaconda Headless Rescue Mode

One of the options you can pass to the grub boot entry options is the keyword : telnet

Combined with assigning a static ip address for you machine you can remote rescue in case of troubles.


Then anaconda will wait for your telnet connection




Finally,  from your remote machine you can telnet to the machine :

telnet 192.168.1.100

You are in rescue mode and you can do whatever you like to rescue the system.

Redirecting Bacula Console Command's Output

Working with bconsole , Sometimes the output of certain commands is so long that it scrolls fast and yout terminal history size will not be sufficient to catch all the output. For example : 

*list files jobid=32

The output was 29870 lines .. so either set your terminal history size to 30000 and keep scrolling and sacrificing your RAM or use the redirecting way!

The Redirecting Way:

While on bconsole command :

*@output testfile
*list files jobid=32
*@output

where testfile is the name of the output file required.

Now you can easily less or grep yout new file.