qemu在linux和windows下tap網絡的配置方法
要讓qemu虛擬機和宿主機位于同一個網絡中被該網絡的其他機器訪問,就需要使用TUN/TAP的網絡方式來啟動qemu虛擬機。具體的啟動指令是:qemu -m 192 -hda disk.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup
如果是在WindowsXP下面,就不需要script=/etc/qemu-ifup這個啟動腳本了,直接將tap0換成網橋的名字即可。
第一步,建立一個虛擬網絡接口。
在linux下:
1?#?mknod?/dev/net/tun?c?10?200
在Windows下,有開源的虛擬網卡軟件,找一個來裝好就行了。
第二步,建立網橋。
在linux下:
修改/etc/network/interface配置文件。此處建立一個名為br0的網橋,先橋接上eth0,在啟動qemu時,再橋接上tap0。
?1?#?/etc/network/interface
?2?#?This?file?describes?the?network?interfaces?available?on?your?system
?3?#?and?how?to?activate?them.?For?more?information,?see?interfaces(5).
?4?
?5?#?The?loopback?network?interface
?6?auto?lo
?7?iface?lo?inet?loopback
?8?
?9?#?The?bridge?network?interface(s)
10?auto?br0
11?iface?br0?inet?static
12?address?192.168.1.2
13?network?192.168.1.0
14?netmask?255.255.255.0
15?broadcast?192.168.1.255
16?gateway?192.168.1.1
17?bridge_ports?eth0
18?bridge_fd?9
19?bridge_hello?2
20?bridge_maxage?12
21?bridge_stp?off
?2?#?This?file?describes?the?network?interfaces?available?on?your?system
?3?#?and?how?to?activate?them.?For?more?information,?see?interfaces(5).
?4?
?5?#?The?loopback?network?interface
?6?auto?lo
?7?iface?lo?inet?loopback
?8?
?9?#?The?bridge?network?interface(s)
10?auto?br0
11?iface?br0?inet?static
12?address?192.168.1.2
13?network?192.168.1.0
14?netmask?255.255.255.0
15?broadcast?192.168.1.255
16?gateway?192.168.1.1
17?bridge_ports?eth0
18?bridge_fd?9
19?bridge_hello?2
20?bridge_maxage?12
21?bridge_stp?off
在windowsXP下,在網絡屬性窗口中,直接將要橋接的兩塊網卡選中,然后點擊鼠標右鍵,選擇“橋”菜單即完成橋接。
第三步,建立qemu-ifup腳本啟動qemu時調用。
在linux下:
建立/etc/qemu-ifup腳本文件(參見qemu指令的-net參數)
1?#!/bin/sh
2?
3?sudo?/sbin/ifconfig?$1?0.0.0.0?promisc?up
4?sudo?/usr/sbin/brctl?addif?br0?$1
5?sleep?2
WindowsXP在下不用這個腳本,直接把-net的ifname參數設為網橋的名字即可。2?
3?sudo?/sbin/ifconfig?$1?0.0.0.0?promisc?up
4?sudo?/usr/sbin/brctl?addif?br0?$1
5?sleep?2
posted on 2006-11-20 23:54 javaFever 閱讀(8255) 評論(2) 編輯 收藏 所屬分類: Linux