配置主机的内网静态 IP
打开 Orcale VM VirtualBox 管理器,从菜单中选择 管理 > 主机网络管理器,双击 VirtualBox Host-Only Ethernet Adapter ,修改他的 IP 地址为 192.168.1.1
关闭 DHCP 服务器
配置虚拟机的网卡
加入第一块网卡,配置如下:
加入第二块网卡,配置如下:
注意:虚拟机之间的内网名字可以随便起,这里叫做 neta。如果在配置在第二个虚拟机的时候,也要记得选择 netca 这个内网名字,这样虚拟机之间才可以互相通信。
加入第三块网卡,配置如下:
装系统的步骤就跳过了,博主使用的是 ubuntu 16
进入系统后,输入:
ifconfig -a
查看所有的网卡信息,根据 mac 地址确定三块网卡对应的名称。
在虚拟机内部配置网卡
sudo vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet static
address 192.168.1.2
netmask 255.255.255.0
auto enp0s8
iface enp0s8 inet static
address 192.168.0.2
netmask 255.255.255.0
auto enp0s9
iface enp0s9 inet dhcp
重启 networking 服务使其生效:
/etc/init.d/networking restart
验证
通过主机 ping 虚拟机
ping 192.168.1.2
在虚拟机中 ping 主机
ping 192.168.1.1
ping 不通,尝试关闭主机的防火墙,这次就通了。
虚拟机之间互 ping
ping 192.168.0.2
虚拟机上网
ping baidu.com