枫叶飞翔 发表于 2015-4-15 09:45:24

关于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

Code
if [ "$1" = "" ]; then
    echo -e "$RED\n `basename "$0"` {start|stop} $WHTE\n"
    exit 1
fi

if [ `id -u` -ne 0 ]; then
    echo -e "$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。
页: [1]
查看完整版本: 关于virtualBox 的host interface网络设置