- 论坛徽章:
- 0
|
Qemu-network
Licy 2008.6.17Testing environment: Ubuntu 7.10(gcc 4.1.3) on Inter Celeron CPU 2.53G and 512M memory.
Now let's divide the process into four steps.
1> Compile and setup qemu and kqemu
If you use debian or ubuntu, you can use
apt-cache search qemu
sudo apt-get install qemu
or if you use other linux versions, you can try to download a qemu package first and remember to check your gcc version, sometimes there will be some problems.
./configure && make && make install
Then you can verify qemu install correctly or not
whereis qemu
Now next we should install the kqemu, go to the directories of your kqemu-source and install.
sudo ./configure
sudo make
sudo make install
Verify that device node /dev/kqemu exists.
ls -l /dev/kqemu
If not, execute the following commands.
sudo mknod /dev/kqemu c 250 0
sudo chmod 666 /dev/kqemu
Then activate module kqemu and verify that it loaded properly.
sudo modprobe kqemu || sudo insmod kqemu.ko
lsmod | grep kqemu
dmesg | tail
2> Installation of guestOS
I have finished the installation of ubuntu in qemu, you can try others, win, freebsd, or something else. And you need a cd or an ISO file to install.
qemu-img create ubuntu.img -f raw 10G
qemu -hda ubuntu.img -cdrom ubuntu-8.04-server-i386.iso -kernel-kqemu -m 512
3> Setup of tun/tap network interface on hostOS and guest OS
First you need to check whether the kernel support the tun/tap network interface or not. I use 2.6.24 and it does, in fact, after the 2.6.18 version, the kernel support the tun/tap network interface and if you use an old kernel you should choose the options in the process of compiling the kernel.
ls -l /lib/modules/2.6.22-14-generic/kernel/drivers/net/tun.ko
If everything is ok, now go to execute the next commands.
sudo apt-get install uml-utilities
sudo modprobe tun
sudo mkdir /dev/net
sudo mknod /dev/net/tun c 10 200
sudo tunctl
Then edit the /etc/qemu-ifup, the content is:
/sbin/ifconfig $1 192.168.10.1 netmask 255.255.255.0
My ip address is 192.168.1.225, so don't set the ip as 192.168.1.X. Then you can start the guestOS in the ubuntu.img in qemu and setup the guestOS network interface eth0 and network route table.
ifconfig eth0 192.168.10.2 up
route add default gw 192.168.10.1
4> NAT setup to allow guestOS access to the internet.
Execute the following as root, so first change to the root user.
echo "1" > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -o eth0 -s 192.168.10.0/24 -j MASQUERADE
Now it's ok, start the qemu:
qemu -serial stdio -net nic,model=rtl8139 -net tap ubuntu.img
The guestOS not only can access the hostOS, but also can access the internet. And you can access the hostOS and guestOS with 192.168.10.2 and 192.168.1.195 via the internet, too.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76848/showart_1137587.html |
|