+--------------------+
| |
| Host PC |
+--------------------+
| tap0 | tap1 | |
+--+------+----------+
| |
| |
+--+------+---+------+
wan | eth0 | eth1 | |
+-------------+------+
+-------------+ | Qemu emulate router
lan | eth2 | eth3 | |
+---+------+--+------+
| |
| |
+-----------+ | +--+---------+
| client 1 |--+ | client 2 | Qemu emulate PCs
| | | |
+-----------+ +------------+
qemu-router 之环境设计
最近想用qemu在linux下 build 一个环境,来模拟开发路由器。好处有很多,比如便于调试kernel阿,乱搞不会破坏系统阿之类的。
于是写了两个script,一个负责模拟router端,一个负责模拟客户机。整个环境配置如图:
router模拟了2个wan口,2个lan口,wan口通过tap跟host(主机)联系,host端启动的script为/etc/qemu-ifup
#!/bin/sh
inf=$1
ip3=${inf##tap}
sudo /sbin/ifconfig $1 172.20.${ip3}.1
inf=$1
ip3=${inf##tap}
sudo /sbin/ifconfig $1 172.20.${ip3}.1
这样就保证了host端的tap interface根据tap0, tap1 ...来配置ip,使得tap0为172.20.0.1, tap1为172.20.1.1,从而配合router模拟出multi wan的环境。
然后是router的启动脚本q-router.sh
#!/bin/bash
port_base=8010
((port1 = port_base + 1))
((port2 = port_base + 2))
QEMU_PATH=/home/fog/study/kernel/emulate/qemu-0.9.1
export PATH=${QEMU_PATH}:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
IMAGE=linux-2.6.16/arch/i386/boot/bzImage
FS=fs-router.squashfs
QEMU=qemu
sudo ${QEMU} -nographic \
-net nic -net tap \
-net nic -net tap \
-net nic,vlan=1 -net socket,vlan=1,listen=:${port1} \
-net nic,vlan=2 -net socket,vlan=2,listen=:${port2} \
-hda ${FS} -hdb ${FS} -kernel ${IMAGE} \
-append "console=ttyS0 root=/dev/hdb rw sb=0x220,5,1,5 ide3=noprobe ide4=noprobe ide5=noprobe clock=pit" -s -S
port_base=8010
((port1 = port_base + 1))
((port2 = port_base + 2))
QEMU_PATH=/home/fog/study/kernel/emulate/qemu-0.9.1
export PATH=${QEMU_PATH}:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
IMAGE=linux-2.6.16/arch/i386/boot/bzImage
FS=fs-router.squashfs
QEMU=qemu
sudo ${QEMU} -nographic \
-net nic -net tap \
-net nic -net tap \
-net nic,vlan=1 -net socket,vlan=1,listen=:${port1} \
-net nic,vlan=2 -net socket,vlan=2,listen=:${port2} \
-hda ${FS} -hdb ${FS} -kernel ${IMAGE} \
-append "console=ttyS0 root=/dev/hdb rw sb=0x220,5,1,5 ide3=noprobe ide4=noprobe ide5=noprobe clock=pit" -s -S
'-s -S' 是为了gdb调试用的。eth0, eth1, eth2, eth3的ip设定都在root fs中的etc/rcS中实现。
client端pc的模拟就更简单了,为了方便,我直接把ip通过kernel的参数做了指定。q-client.sh
#!/bin/bash
port_base=8010
ip3_base=9
cn=$1 # client number
: ${cn:="1"}
((port = port_base + cn))
((ip3 = ip3_base + cn))
QEMU_PATH=/home/fog/study/kernel/emulate/qemu-0.9.1
export PATH=${QEMU_PATH}:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
IMAGE=linux-2.6.16/arch/i386/boot/bzImage
FS=fs-client.squashfs
QEMU=qemu
sudo ${QEMU} -nographic \
-net nic,vlan=1 -net socket,vlan=1,connect=127.0.0.1:${port} \
-hda ${FS} -hdb ${FS} -kernel ${IMAGE} \
-append \
"console=ttyS0 root=/dev/hdb rw \
ip=192.168.${ip3}.2::192.168.${ip3}.1:255.255.255.0::eth0:off \
sb=0x220,5,1,5 ide3=noprobe ide4=noprobe ide5=noprobe clock=pit"
port_base=8010
ip3_base=9
cn=$1 # client number
: ${cn:="1"}
((port = port_base + cn))
((ip3 = ip3_base + cn))
QEMU_PATH=/home/fog/study/kernel/emulate/qemu-0.9.1
export PATH=${QEMU_PATH}:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
IMAGE=linux-2.6.16/arch/i386/boot/bzImage
FS=fs-client.squashfs
QEMU=qemu
sudo ${QEMU} -nographic \
-net nic,vlan=1 -net socket,vlan=1,connect=127.0.0.1:${port} \
-hda ${FS} -hdb ${FS} -kernel ${IMAGE} \
-append \
"console=ttyS0 root=/dev/hdb rw \
ip=192.168.${ip3}.2::192.168.${ip3}.1:255.255.255.0::eth0:off \
sb=0x220,5,1,5 ide3=noprobe ide4=noprobe ide5=noprobe clock=pit"
这样,先启动router,然后启动client,一个简单的模拟环境就架起来了。
2023年8月07日 03:35
Pleasant site and completely extraordinary. You can improve yet regardless I say this perfect.Keep striving generally advantageous. 먹튀검증업체
2023年8月09日 04:27
Incredible post I might want to thank you for the endeavors you have made in composing this fascinating and learned article. Ac repair las vegas
2023年8月28日 06:12
I am upbeat to locate your recognized method for composing the post. Presently you make it simple for me to comprehend and execute the idea. Much obliged to you for the post. uncompressed
2023年9月03日 07:14
it was a magnificent opportunity to visit this sort of site and I am upbeat to know. much thanks to you such a great amount for allowing us to have this open door.. 먹튀검증업체
2023年10月04日 03:35
I am glad to discover this post extremely valuable for me, as it contains part of data. I generally like to peruse the quality substance and this thing I found in you post. A debt of gratitude is in order for sharing. www.mt-spot.com
2023年11月01日 00:16
An intriguing discussion will probably be worth comment. There’s no doubt that that you simply write regarding this topic, it will not certainly be a taboo subject but usually consumers are not enough to communicate on such topics. An additional. Cheers Sports leggings
2023年11月01日 20:03
produce,I thought overall often the “invisible” men and women probably would not discover i am, pointless, buyers anything like me, where ever all of the fireflies are just like the actual bluish event, plenty to pay off marvelous a sufficient quantity of. Sports leggings
2023年11月03日 00:22
I will immediately snatch your rss feed as I can not in finding your email subscription link or e-newsletter service. Do you’ve any? Kindly allow me recognise so that I may subscribe. Thanks. Packers and Movers pune to Gurgaon
2023年11月14日 21:52
Hello I am so delighted I found your website, I really located you by mistake, while I was looking on google for something else, Anyways I am here now and could just like to say cheers for a tremendous post and a all round entertaining blog. Please do keep up the great work. rút tiền f8bet
2023年11月16日 18:44
Your blog is spectacular. A lot of the things on your own page are usually my consent concerning. we appreciate you discussing. HB88
2023年11月17日 23:08
Hello there, just became aware of your blog through Google, and found that it’s really informative. I will appreciate if you continue this in future. Numerous people will benefit from your writing. Cheers! 79king casino
2023年11月21日 15:07
Get daily teer result, shillong teer result, khanapara teer result, teer result common number daily success live teer result here. shillong teer result
2023年11月21日 22:54
2023年11月22日 20:56
Awesome article , I’m going to spend more time researching this subject f8bet game
2023年11月23日 21:11
An impressive share, I simply given this onto a colleague who was doing a little analysis during this. And the man the fact is bought me breakfast since I ran across it for him.. smile. So let me reword that: Thnx for your treat! But yeah Thnkx for spending time to go over this, I’m strongly over it and enjoy reading more on this topic. If you can, as you become expertise, do you mind updating your blog site with additional details? It really is highly a good choice for me. Big thumb up due to this writing! livescore888
2023年11月24日 15:57
That'sthe justification selling you ought to correct home work in advance of composing. It is practical to jot down greater offer this particular. UFABETเว็บตรงที่ดีที่สุด
2023年11月24日 18:25
That's why it is best that you relevant researching previously penning. You're able to construct more desirable put up this way. UFABETเว็บพนันตรง
2023年11月24日 20:14
That'sthe justification selling you ought to correct home work in advance of composing. It is practical to jot down greater offer this particular. UFABETเว็บพนันตรงไม่มีขั้นต่ำ
2023年11月24日 22:07
Because of this , promotional advertisements email campaigns that allows you to advantageous study sooner than offer. In other words to put in writing more practical space something like this. UFABETฝากถอนไม่มีขั้นต่ำ
2023年11月24日 23:50
The main reason why it's always a lot better that one can significant researching preceding doing. You'll be able to share improved page using this method. UFABETฝากขั้นต่ำ
2023年11月25日 12:52
The accumulated onto your blog site despite the fact paying off acceptance just many tid little submits. Gratifying strategy for honest, I will be bookmarking before you start acquire merchandise realization spgs right in place. https://gab.com/mmedispa1
2023年11月25日 18:49
As soon as we obtained on your web site despite the fact that obtaining thing to consider essentially fairly little bit submits. Enjoyable technique for forthcoming, I'm book-marking simultaneously obtain types finish increases up-wards. Star Joker slot machine
2023年11月26日 18:08
That appears to be absolutely good. These teeny main features are intended acquiring great deal of qualifications skills. Now i am attracted to the product loads. UFABETสมัครแทงบอลฟรีไม่มีขั้นต่ำ
2023年11月27日 17:55
Because of this , promotional advertisements email campaigns that allows you to advantageous study sooner than offer. In other words to put in writing more practical space something like this. tải app Jun88
2023年11月27日 22:44
Rapidly this kind of fantastic web site will surely unquestionably often be well-known amongst many creating any website people, for your meticulous articles along with testimonies. homedesignlooks
2023年11月28日 15:59
Speedily this specific web page could indisputably become popular involving most writing a blog along with site-building persons, for you to their fastidious blogposts or possibly testimonials. radiostyrd fbil
2023年11月28日 18:49
Speedily this specific web page could indisputably become popular involving most writing a blog along with site-building persons, for you to their fastidious blogposts or possibly testimonials. enjoy soffa
2023年11月28日 22:03
When i actually procured against your website check having said that contributing knowledge just a little touching submits. Awesome way of possibilities, We're also book-marking by carrying out a phase obtain editions finish spgs manner right up. Alien Labs Disposable
2023年11月29日 14:02
Rapidly this kind of internet site can easily definitely recognition among virtually all blogging and site-building and also site-building individuals, because careful content or simply opinions. https://karta.com/blog/26-best-things-to-do-in-henderson-nv/
2023年11月29日 16:10
This approach is normally how it looks quite best. Every one about health issues demonstrates really are made using many different ways of life proficiency. I propose you the technology rather a lot. 온라인카지노사이트
2023年11月30日 14:48
Rapidly this kind of link may well irrefutably find yourself famous among each creating many individuals, as a result of thorough posts and also critiques and also scores. video ngentot
2023年11月30日 19:31
It will be in addition a tremendous write-up i usually without a doubt liked inspecting. It's not actually inevitably day-to-day i usually build up the possibility to see all sorts of things. pappy van winkle 23 for sale
2023年12月02日 15:25
Hence it is better you have to affiliated understand when setting up. It is easy to put up a lot better apply for right away. lunchtime result
2023年12月03日 14:14
Thanks for your article. One other thing is that if you are disposing your property by yourself, one of the difficulties you need to be conscious of upfront is how to deal with household inspection reviews. As a FSBO vendor, the key concerning successfully moving your property plus saving money about real estate agent commissions is understanding. The more you recognize, the better your property sales effort will be. One area in which this is particularly essential is inspection reports. video bokep sma
2023年12月04日 19:32
wonderful put up, very informative. I’m wondering why the opposite experts of this sector do not realize this. You should proceed your writing. I am sure, you’ve a huge readers’ base already! rút tiền bong88
2023年12月04日 23:17
I love to most of the information, I must claim when i liked, When i would love additional information related to that, because it's very good., Appreciate it about unveiling. children's smartwatch
2023年12月05日 14:40
I quite like the many written content, I've got to declare my spouse and i loved, My spouse and i would really like more details relating to this specific, mainly because it is quite wonderful., Thanks a lot with regards to disclosing. skf bearing
2023年12月05日 19:55
When i open the Give food to it provides me with many different garbled text, may be the concern on my small end? đăng ký 8xbet
2023年12月06日 20:28
I likewise conceive thus, perfectly written post! . đăng nhập 78win
2023年12月09日 19:07
An impressive share, I merely given this onto a colleague who was doing a little analysis for this. Anf the husband in truth bought me breakfast simply because I found it for him.. smile. So i want to reword that: Thnx for your treat! But yeah Thnkx for spending plenty of time to talk about this, I feel strongly regarding this and really like reading regarding this topic. If it is possible, as you grow expertise, can you mind updating your blog site with a lot more details? It’s highly useful for me. Huge thumb up with this writing! dang nhap jun88
2023年12月14日 20:40
Hi! I ran across your site accidentally today, but am really pleased that people did! Its not only entertaining, but additionally straightforward to make use of compared with lots that Ive viewed! https://123b.loan/
2023年12月15日 23:10
I have truly enjoyied reading through your nicely written post. It looks like you spend a great deal of effort and time on your blog. I have bookmarked it and I am looking forward to looking at new content articles. Keep up the good work! https://www.reverbnation.com/artist/mmedispa
2023年12月16日 18:15
“I’m just writing to make you understand what a helpful experience my princess enjoyed reading through your web page. She learned a lot of pieces, including what it is like to have an ideal teaching heart to get other individuals with no trouble learn selected impossible subject areas. You truly surpassed readers’ desires. Many thanks for churning out such invaluable, healthy, informative and fun tips on the topic to Julie.” https://xo88.team/
2023年12月21日 00:18
Images entirely on your internet site even when creating awareness swiftly a small amount of sum submits. Rewarding technique for lasting upcoming, I will be book-marking at that time grow to be the surface area end develops inches upwards inches. plug and play vape
2023年12月21日 21:34
Quickly this page probably will without doubt maybe always be recognized regarding a lot of websites folks, due to the thoughtful articles or blog posts or perhaps ideas. Ivan Petrov
2023年12月22日 00:16
Quickly this site could without doubt generally always be dominant relating to every one of web site buyers, since thoughtful stories plus exams. แทงบอลsbobet
2023年12月22日 17:33
This is the most creative release from Guru Gang Starr and Solar. This classic Hip Hop album Dj Premier
2023年12月22日 22:26
Pretty quickly this specific outstanding site need to indisputably grown to be regarded within just each of the blog site most of the people, due to fastidious content as well as testimonials or it could be opinions. clean廠 官網
2023年12月23日 15:41
I quite like the many written content, I've got to declare my spouse and i loved, My spouse and i would really like more details relating to this specific, mainly because it is quite wonderful., Thanks a lot with regards to disclosing. Bongdalu
2023年12月23日 22:09
Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your blog? My website is in the very same area of interest as yours and my users would really benefit from a lot of the information you present here. Please let me know if this okay with you. Regards! 더킹플러스카지노 3만
2023年12月24日 00:38
I like the many blogposts, I seriously liked, I want details about it, since it is rather wonderful., Cheers pertaining to expressing. nhà cái uy tín
2023年12月25日 16:03
Swiftly this web site can irrefutably become popular between almost all blogging and site-building folks, because thorough posts or perhaps critiques. Locksmith Dundee
2023年12月26日 18:42
produce,It happens to be love people raised countless party while in the turntable, the main turntable will not avoid so that the overall victorious one that will not always appreciate what people. ĐĂNG KÝ VIN777
2023年12月30日 15:45
I was really lucky to find this internet site on bing, just what I was searching for : D likewise saved to favorites . bongdalu beer
2024年1月02日 23:02
Quick the website will undoubtedly grow to be well known along with almost all working the weblog households, due to the painstaking content articles or evaluation content articles. bongdalu