Wednesday, September 16, 2009

QEMU "host only network"

Abstract: Setup an LAN network of only the host and guest.

Recently I'm trying something on qemu and want to access the guest from the host more freely than user mod port redirect, but I do not want to expose my guest to the host network. All I did is to wrap everything into a script:

#!/bin/sh

HOSTIP="192.168.1.250"
GUESTIP="192.168.2.10"
NETMASK="255.255.255.0"
USERID=`whoami`
IFNAME=`sudo tunctl -b -u $USERID`

sudo ifconfig $IFNAME $HOSTIP netmask $NETMASK up

echo ":: Host IP is $HOSTIP"
echo ":: Run the follwing command in guest to set IP and gateway:"
echo " # ifconfig eth0 $GUESTIP"
echo " # route add default gw $HOSTIP"
echo ":: Starting QEMU with TUN/TAP network..."

qemu -hda webdev.qcow \
-boot c -m 256 \
-k en-us -localtime\
-net nic,vlan=0,model=rtl8139 \
-net tap,vlan=0,ifname=$IFNAME,script=no,downscript=no

sudo tunctl -d $IFNAME
HOSTIP="19

Btw, I find sticky note gadget on iGoogle a great tool to share a couple of lines between machines - I'm writing on my Windows laptop and the script is in my Linix desktop, just a few paste and copy brings the script here :)

No comments:

Post a Comment