Chinaunix首页 | 论坛 | 博客
  • 博客访问: 533858
  • 博文数量: 526
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 3235
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-29 17:52
文章分类

全部博文(526)

文章存档

2011年(1)

2008年(525)

我的朋友

分类: LINUX

2008-08-29 18:06:15

 
1、kqemu模块的加载

在/etc/modules上增加kqemu,让系统启动时自动加载kqemu模块。

然后udev会自动生成一个叫做kqemu的设备:
xuwei@XIAO:~$ls-l/dev|grepkqemu
crw-rw-rw-1rootroot10,632006-12-1909:28kqemu

2、配置qemu使用tap/tun模式

tap/tun模式需要内核支持tun模块,请先确认。

2.6.18及以上版本内核,由于修改了对tun模块的执行权限,需要增加一个脚本。详细请参阅。在此也把该faq贴过来。

I''musingakernel>=2.6.18andamhavingproblemswithtun/tapandqemu
Startingwith2.6.18auserprocessmustberoottomanagetapinterfaces.Onewaytomakeqemubehaveasbeforeistowraptheprocessinathatmanagestheinterface:

qemu-tap

#!/bin/sh#tomanagetapinterfaceallocation#forlinuxkernels>=2.6.18#setupatapinterfaceforqemu#USERID-uidqemuisbeingrununder.USERID=`whoami`iface=`sudotunctl-b-u$USERID`#generatearandommacaddressfortheqemunic#shellborrowedfromuserpheldens@qemuforumranmac=$(echo-nDE:AD:BE:EF;foriin`seq12`;\doecho-n`echo":$RANDOM$RANDOM"|cut-n-c-3`;done)#specifywhichNICtouse-seeqemu.orgforothersmodel=ne2k_pci#model=ne2k_isa#startqemuwithourparametersqemu$@-netnic,vlan=0,macaddr=$ranmac,model=$model\-nettap,vlan=0,ifname=$iface#qemuhasstopped-nolongerusingtapinterfacesudotunctl-d$iface&>/dev/null
Youwouldthenstartqemuusingthiswrapper:./qemu-tap-hdadeb-sid.img-localtime

Youneedtunctl,aprogramfromtheusermodelinuxproject,tomakethiswork.Ondebianthepackageiscalleduml-utilities.

Pleasefeelfreetomodifythe.

然后,设置/etc/qemu-ifup
xuwei@XIAO:~$cat/etc/qemu-ifup
#!/bin/sh
sudo-p"Passwordfor$0:"/sbin/ifconfig$1172.20.0.1
并且,把该脚本设置成可执行权限:
xuwei@XIAO:~$ls-l/etc|grepqemu
-rwxr-xr-x1rootroot662006-12-1711:17qemu-ifup

这就搞定了。直接qemu-tap.img就可开启虚拟机,并且使用tap/tun模式。开启虚拟机以后,ifconfig可以看到生成了一个tap0接口。host和guest正是通过该tap0接口通信的。

3、配置guest上网

debianetch提供了很方便的途径。可以直接修改/etc/rc.local,添加如下信息:
echo"1">/proc/sys/net/ipv4/ip_forward
iptables-F-tnat
iptables-X-tnat
iptables-Z-tnat
iptables-tnat-PPREROUTINGACCEPT
iptables-tnat-PPOSTROUTINGACCEPT
iptables-tnat-POUTPUTACCEPT
iptables-tnat-APOSTROUTING-oeth0-s172.20.0.0/16-jMASQUERADE

这样,系统启动时自动设置到guest的地址转换。

linuxsir有几篇介绍的文章,都说先要配置bridge接口,然后再去写脚本加载这些模块,感觉没有必要这么麻烦。

debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置debian下qemu配置
阅读(448) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~