免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1352 | 回复: 0
打印 上一主题 下一主题

qemu启动网络设置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-21 17:14 |只看该作者 |倒序浏览

                                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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP