Tuesday, November 04, 2008

How to : QEMU networking

Hi All,
It has been ages since I have written anything over here. One of the main reason is that I have started posting mathematical post at my wordpress blog.

Anyways, Sameer and I were trying to get our hands dirty on Qemu networking. Although there is a fairly good description is given over here, I am trying to fill in here a few missing bits.

Okay, so here is the scenario we want to create.

On one machine ( say host-A ) we want to create many guest machines ( guestA1, guestA2 ) etc. Similarly, there is another machine ( host-B ) having many guest machines ( guestB1, guestB2 ). We want to make guestA* communicate with guestB*.

I am assuming that readers are aware of how to install a guest OS on a guest machine created by qemu.

First we need to configure a ipv4-over-ipv4 tunnel for the host machines.

--host-A configuration is as follows

ip : 172.27.16.1
netmask : 255.255.255.0
default gateway : 172.27.16.254

host-B configuration is
ip : 172.27.16.2

netmask and gateway is the same as above.

--In host-A ( as root ) do the following

root@hostA# ip tunnel add tunl1 mode ipip remote 172.27.16.2 dev eth0

-- this command essentially create one endpoint of the tunnel in host-A. It says that the other end of the tunnel lies at ip 172.27.16.2. Also, the tunnel device will use eth0 as its physical device.

root@hostA# ip link set tunl1 up

-- this command will bring up the tunnel interface

root@hostA#ifconfig tunl1 10.0.1.1 pointopoint 172.27.16.2

-- guestA network will be 10.0.1.0/24 network and tunnel device should be a part of it. This command gives the tunnel device an ip address and it says that other endpoint of the tunnel will be at 172.27.16.2

root@hostA# route

--this will show you the current configuration of routing table. There might be an entry in the routing table

172.27.16.2 * 255.255.255.255 U 0 0 tunl1

--you need to delete this entry using following command :

root@hostA# route del -net 172.27.16.2 netmask 255.255.255.255 dev tunl1

--Also you need to tell routing table that guestB network ( 10.0.2.0/24) should be routed through the tunnel

root@hostA# route add -net 10.0.2.0 netmask 255.255.255.0 dev tunl1

--You need to repeat the same procedure for hostB with suitable ips ( use 10.0.1.* instead of 10.0.2.* and vice versa , replace 172.27.16.1 with 172.27.16.2 and vice versa )

--By now, your tunnel should be working. To check, try

root@hostA# ping 10.0.2.1

root@hostB# ping 10.0.1.1

--If it does not ping, it might be the case that your firewall is coming into the way. If you are expert enough, modify your firewall rules with iptables. If not, lets first save your firewall rules

root@hostA# iptables-save | cat > iptablebackup.bak

--flush the firewall rules now

root@hostA# iptables -F
root@hostA# iptables -t nat -F

--Now, that firewall is completely disabled, the tunnel should work. (Of course, you need to disable your firewall at hostB as well! ) If it still does not work, then there might be some other problem or you might not have done things right.

-- you can restore your firewall ( later ) with

root@hostA# cat iptablebackup.bak | iptables-restore

--Okay, so the tunnel is working now!! Great news!! But what next??
Next we create a tapping device - a virtual network interface - which will be visible to the guest OSes.

root@hostA# tunctl -u username

-- provide a username here. This user will be able to use this tapping device while initializing qemu process. This command would have created a tapping device (tap0) in your system

--assign an ip address of guestA network to tapping device

root@hostA# ip addr add 10.0.1.2 dev tap0

-- bring the tapping device up

root@hostA# ip link set tap0 up

-- Also create a file /etc/qemu-ifup which can look like following :
#!/bin/bash
#echo "bringing up interface $1"

-- Now start the first guestOS

username@hostA$ qemu -net nic,macaddr=macaddr1 -net tap,ifname=tap0 -net socket,mcast=230.0.0.1:9999 ....

--second guestOS can be started with following
username@hostA$ qemu -net nic,macaddr=macaddr2 -net socket, mcast=230.0.0.1:9999 ...

-- multicast socket is needed for mchines in guestA network to talk to each other

--In the guestA1 do the following :

root@guestA1# ifconfig eth0 10.0.1.3 netmask 255.255.255.0
root@guestA1# route add default gw 10.0.1.2 dev eth0

-- Note that we have given the ip address of tapping device as the gateway fo guest OSes
-- second, third etc guest machines can be configured with different ip addresses for their eth0

-- Repeat this procedure on host-B as well with appropriate ip addresses.

-- Now, you should be able to ping machines from guestA network to guestB network and vice versa. However, this does not yet allow you to connect to host network. To do that, you need to enable ip forwardng

root@hostA# echo "1" > /proc/sys/net/ipv4/ip_forward

-- perform source NAT

root@hostA# iptables -t nat -I POSTROUTING 1 -o eth0 -j SNAT --to-source 172.27.16.1

--Now, from guestA network ( 10.0.1.0/24 ) you should be able to connect to ( 10.0.2.0/24 ) as well as host network ( 172.27.16.0/24 )

-- To delete the tunnel

root@hostA# ip link set tunl1 down
root@hostA# ip tunnel del tunl1

--To delte the tapping device

root@hostA# tunctl -d tap0

--Above mentioned setup is tested with host machines running fedora core 9 and guest machines running Arch Linux, Debian etc.

If you have any queries post it as comments, I will be willing to answer if I can.

Sunday, September 14, 2008

A few gems from Saif Palanpuri

I stumbled upon this nice collection of gems by saif palanpuri on gujaratikavita.

મૅટ્રિકની પરીક્ષામાં નાપાસ થવાની ખુશાલીમાં મીત્રોને બાલારામની પિકનિક પર લઈ જનાર શાયર સૈફ પાલનપુરીના કેટલાક શેરો ને મુક્તક માણીએ.....

જીવનની સમી સાંજે મારે જખ્મોની યાદી જોવી'તી
બહુ ઓછા પાના જોઈ શક્યો બહુ અંગત અંગત નામ હતા.

**************

બે ચાર શ્વાસ લઈને જે બાળક મરી ગયું,
એની કને ખુદાની કોઈ બાતમી હતી.

**************

હવે તો 'સૈફ' ઈચ્છું છું કે મૃત્યુ દ્વાર ખખડાવે,
ઘડીભર તો મને લાગે કોઈના આગમન જેવું.

**************

ઘણા દિવસ પછી બારીએ કાગડો આવ્યો,
ને કહી ગયો કે હવે કોઈ આવનાર નથી.

**************

હું તો વિચારતો રહ્યો ખૂણે ઊભો રહી,
મારી નજીકથી જે ગઈ, જિંદગી હતી.

**************

પહેલા સમું તરસનું એ ધોરણ નથી રહ્યું,
પાણી મળે છે તો ય હવે પી જવાય છે.

**************

જીવી રહ્યો છું કિન્તુ જીવન લાગતું નથી,
એવું મરી ગયું ગયું છે કે મન લાગતું નથી.
લાગે છે મારી લાશને ઊંચકી લીધી છે મેં,
દુઃખ આવે છે તો એનું વજન લાગતું નથી.

**************

કદી વસતી મહીં ભૂલા પડ્યા છો ?
હૃદય જેવા હૃદય સાથે લડ્યા છો ?
મોહબ્બત શું છે ? શું સમજાવું તમને -
કદી કોઈ વાર તહેવારે રડ્યા છો ?

Friday, September 12, 2008

A gazal by mariz

It's been a while since I posted anything here. I just stumbled upon this beautiful gazal by mariz.

એવો કોઈ દિલદાર જગતમાં નજર આવે,
આપી દે મદદ કિઁતુ ન લાચાર બનાવે.

હમદર્દ બની જાય જરા સાથમાં આવે,
આ શું કે બધા દૂરથી રસ્તા જ બતાવે!

શું એને ખબર કોની નજર પ્યાસી રહી ગઈ?
જે ભેજમાં ચાલે અને પાલવ ન ઉઠાવે.

એ સૌથી વધુ ઉચ્ચ તબક્કો છે મિલનનો,
કહેવાનું ઘણું હો ને કશું યાદ ના આવે.

કોઈ પ્રેમીથી તમારા, વાતોની કલા લ્યે,
એક વાત કરે એમાં ઘણી વાત છુપાવે.

રડવાની જરુરત પડે ત્યાં સૂકા નયન હો,
ને હસતો રહું ત્યાં જ જ્યાં હસવું નહિં આવે.

છે મારી મુસીબતનું 'મરીઝ' એક આ કારણ,
હું મુજથી રૂઠેલો છું, મને કોણ મનાવે?

Tuesday, May 06, 2008

A gazal by befam : મને આબાદ કર - બરકત વિરાણી ‘બેફામ’

I read this nice gazal on tahuko.com.
__________________

ખોટ તારે ત્યાં ખુદા શી છે ? મને આબાદ કર,
છે ધરા પર ઝાંઝવાં તો આભથી વરસાદ કર.

આટલી મારી મદદ ઓ પ્રેમનો ઉન્માદ કર,
રોજ એના ઘર તરફ જા, રોજ એને સાદ કર.

પ્રેમમાં સાંભરવા જેવું હવે શું છે બીજું ?
એ તને ભૂલી ગયાં છે એટલું બસ યાદ કર.

દુઃખની વચ્ચે જીવવાની એ જ બેત્રણ રીત છે,
સામનો કર કે સબર કર કે પછી ફરિયાદ કર.

જે પ્રયોજન છે સુરાનું એ સુરા જેવું જ છે,
આ બધા કડવા અનુભવનો જ તું આસ્વાદ કર.

હોય સૌ નાદાન ત્યાં કોઇ તો દાનો જોઇએ,
દોસ્ત કર બે-ચાર, દુશ્મન પણ કોઇ એદાદ કર.

જો પછી કે શૂન્ય વિણ બાકી કશું રહેશે નહીં,
ઓ ખુદા તારા જગતમાંથી મને તું બાદ કર.

અંતવેળા છે, ન એની રાહ જો બેફામ તું,
જિન્દીની જેમ તારું મોત ના બરબાદ કર.

Wednesday, April 09, 2008

Duplex printing script

Well,
Our department printer by default runs in single side printing mode. This causes a lot of paper wastage. I finally sat down and wrote a shell script which will takes one PDF file as an input and outputs two PDF files. One with all odd-pages. Another with all even pages in reverse order so that output papers from odd-page printing can be directly fed to input tray. Of course, this requires a bit of manual intervention, but it is not a big price to pay for saving paper ( and saving trees ).
Here is a link to the script :
http://sbjoshi.googlepages.com/duplexprinting.sh

Please let me know if any bug is found in the script or if you want to suggest some improvements.
--Saurabh Joshi

A humourous quote

I read this quote on iitb.h posted by prof soumen.
--------------------
Reality is delirium caused by acute alcohol deficiency
--------------------

Joke : Why men don't write advice columns

After a long time I have read some awesome piece of humour on iitb.humour. Following is a copy from iitb.h
---------
Why men don't write advice columns
>
> Dear Walter:
> I hope you can help me here. The other day I set off for work
leaving my
> husband in the house watching the TV as usual. I hadn't gone
more than a
> mile down the road when my engine conked out and the car
shuddered to a
> halt. I walked back home to get my husband's help. When I got
home I
> couldn't believe my eyes. He was in the bedroom with a neighbor
lady .
> I am 32, my husband is 34 and we have been married for twelve
years.
> When I confronted him, he broke down and admitted that he'd been
having an
> affair for the past six months.
> I told him to stop or I would leave him. He was let go from his
job six
> months ago and he says he has been feeling increasingly
depressed and
> worthless. I love him very much, but ever since I gave him the
ultimatum
> he has become increasingly distant. I don't feel I can get
through to
> him anymore.
> Can you please help?
> Sincerely,
> Mrs... Sheila Usk
>
>
> Dear Sheila:
> A car stalling after being driven a short distance can be caused
by a
> variety of faults with the engine. Start by checking that there
is no
> debris in the fuel line. If it is clear, check the jubilee clips
holding
> the vacuum pipes onto the inlet manifold. If none of these
approaches
> solves the problem, it could be that the fuel pump itself is
faulty,
> causing low delivery pressure to the carburetor float chamber.
> I hope this helps.
> Walter
---------------------

Sunday, April 06, 2008

Original Joke : Google bhi bandh hai

Well,
It has be a really long time since I have posted anything humorous on my blog. It may be indicative of the fact that life at IIT Bombay was more fun as compared to life at IIT Kanpur.

Anyways, the other day Sameer, Anshul, Sourabh and I were discussing about how people working in software industry themselves are ignorant about how some software related technology works. Anshul depicted the following incident happening at a company his friend was working for :
----------------------------------------------------
Guy 1: Kya yaar, kya kar raha hai?
Guy 2 : kya kar sakte hai?? sala aaj internet bandh hai.
Guy 1: Abe internet to chhodo Google bhi bandh hai ( :-O :-D )
----------------------------------------------------
It may not sound much funny right now, but it surely was when Anshul was telling it to us.
--Saurabh

Friday, April 04, 2008

Quote about rat race

Well,
It so happened that two of my friends had the following quote as their gtalk status line :
"The trouble with the rat race is that even if you win, you are still a rat"

Surprisingly, they don't know each other. What are the odds, eh?