关于virtualBox 的host interface网络设置

NND,以前在网上看到说vbox的连接用nat的方式,主机和client不在一个网段中,无法互联,想要互联要设置成为 host interface 方式。
我就找阿找。最好找到了一个这个。
http://blog.chinaunix.net/u2/61789/showart_1360043.html

以下是根据自己的方式修改了一下
sudo apt-get install uml-utilities bridge-utils
ContractedBlock.gif ExpandedBlockStart.gif Code
if [ "$1" = "" ]; then
    echo 
-"$RED\n `basename "$0"` {start|stop} $WHTE\n"
    exit 
1
fi

if [ `id -u` -ne 0 ]; then
    echo 
-"$RED\n Must be root $WHTE\n"
    exit 
1
fi

if [ "$1" = "start" ] ; then
        
# Create a tap device with permission for the user running vbox
        # 建立一个使用者(user)有权限的设备tap0,-u 参数为自己用户名 或 id
        tunctl -t tap0 -u shengshuai # 不能用 `id -u`,因为使用sudo 执行时id为0
        chmod 0666 /dev/net/tun

        
# Bring up ethX and tapX in promiscuous mode
        # 将ethx和tapx网卡界面设为混杂模式(Promiscuous)
        ifconfig eth1 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 eth1
        brctl addif br0 tap0

        
# 下面是两种获取IP的方式,可以自由选择,把不需要的注释掉就好了。
        # 将bridge设成静态IP。XXX都分别对应IP、子网掩码、网关。
        ifconfig br0 192.123.1.52 netmask 255.255.255.0 up
        
#route add default gw 192.168.1.1
        # 将bridge设成动态DHCP分配IP。
        #dhclient br0
fi


if [ "$1" = "stop" ] ; then
        
## 刪除 tap0
        tunctl -d tap0
        
##
        ## 刪除 br0
        ifconfig br0 down
        brctl delbr br0
        
##
        ## 将tap0, eth0 移出bridge(br0)
        brctl delif br0 tap0
        brctl delif br0 eth0

        
## 自定义恢复IP地址,默认网关
        ifconfig eth1 192.123.1.52 netmask 255.255.255.0 up
        
#route add default gw 192.168.1.1
        #dhclient eth0
fi

后来想了想,我只许要在clent中能访问host就可以了,不需要,访问clent,所以还是用回了NAT。

转载于:https://www.cnblogs.com/shengshuai/archive/2009/04/03/1428699.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值