【转】Linux下虚拟网卡(tap)安装方法

虚拟网卡在設定過程中需要兩支工具程式,各在uml-utilities,bridge-utils套件中取得。 
tunctl(uml-utilities) 
brctl (bridge-utils) 

首先為Host OS建立橋接界面(Bridge)和虛擬網卡設備(tap device),這樣作的原故,是使將來取得IP是由橋接界面(bridge),而不是由ethx或tapx來取得IP。 

底下的命令(commands)是採取動態取得IP(DHCP)的方式來設定,所以可以將這些命令寫入 rc.local 中,在開機後就可將環境設定好。 


# Create a tap device with permission for the user running vbox 
# 建立一個使用者(user)有權限的設備檔 tap0 
tunctl -t tap0 -u {user} 
chmod 666 /dev/net/tun 

# Bring up ethX and tapX in promiscuous mode 
# 將ethx和tapx網卡界面設為混雜模式(Promiscuous) 
ifconfig eth0 0.0.0.0 promisc 
ifconfig tap0 0.0.0.0 promisc 

# Create a new bridge and add the interfaces to the bridge. 
# 建立新的橋接界面(bridge),並把 eth0, tap0加入bridge 
brctl addbr br0 
brctl addif br0 eth0 
brctl addif br0 tap0 

# Give the bridge a dhcp address. 
# 將bridge設成動態取得IP(譯註:若為ADSL撥接環境,則可設為 
# ifconfig br0 0.0.0.0 up 則Host OS 和Guest OS各自可以不同的撥接帳號來連網 ) 
dhclient br0 

現在可以在VirtualBox的Guest OS網路設定畫面中,將attached to的選項中選擇host interface,interface name選項中設為tap0。 
這樣就完成Guest OS橋接網路模式的設定了,馬上啟動Guest OS 吧 ! Guest OS 的網路設定和Host OS是獨立平行的。 

附註: 
測試網路設定時,記得將防火牆關閉。 

實用小指令: 
刪除 tap0 
tunctl -d tap0 

刪除 br0 
ifconfig br0 down 
brctl delbr br0 

將tap0, eth0 移出bridge(br0) 
brctl delif br0 tap0 
brctl delif br0 eth0


脚本例:放在home目录下,每次可以手动启动。
#! /bin/bash tunctl -t tap0 -u star tunctl -t tap1 -u star tunctl -t tap2 -u star tunctl -t tap3 -u star tunctl -t tap4 -u star tunctl -t tap5 -u star tunctl -t tap6 -u star tunctl -t tap7 -u star tunctl -t tap8 -u star tunctl -t tap9 -u star tunctl -t tap10 -u star tunctl -t tap11 -u star tunctl -t tap12 -u star tunctl -t tap13 -u star tunctl -t tap14 -u star tunctl -t tap15 -u star ifconfig eth0 0.0.0.0 promisc ifconfig tap0 0.0.0.0 promisc ifconfig tap1 0.0.0.0 promisc ifconfig tap2 0.0.0.0 promisc ifconfig tap3 0.0.0.0 promisc ifconfig tap4 0.0.0.0 promisc ifconfig tap5 0.0.0.0 promisc ifconfig tap6 0.0.0.0 promisc ifconfig tap7 0.0.0.0 promisc ifconfig tap8 0.0.0.0 promisc ifconfig tap9 0.0.0.0 promisc ifconfig tap10 0.0.0.0 promisc ifconfig tap11 0.0.0.0 promisc ifconfig tap12 0.0.0.0 promisc ifconfig tap13 0.0.0.0 promisc ifconfig tap14 0.0.0.0 promisc ifconfig tap15 0.0.0.0 promisc brctl addbr br0 brctl addif br0 eth0 brctl addif br0 tap0 brctl addif br0 tap1 brctl addif br0 tap2 brctl addif br0 tap3 brctl addif br0 tap4 brctl addif br0 tap5 brctl addif br0 tap6 brctl addif br0 tap7 brctl addif br0 tap8 brctl addif br0 tap9 brctl addif br0 tap10 brctl addif br0 tap11 brctl addif br0 tap12 brctl addif br0 tap13 brctl addif br0 tap14 brctl addif br0 tap15 dhclient br0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值