使用 VirutalBox, CentOS 7,二者安裝過程省略
在宿主機的 VirutalBox 設置虛擬機的網卡服務器
Adapter 1: Atached to: Host-only Adapter Name: vboxnet0 混雜模式: 拒絕 Adapter 2: 鏈接方式: 網絡地址轉換NAT
進入虛擬機查看網絡
$ ipconfig -a
$ nmcli con
Ubuntu:測試
$ sudo vi /etc/network/interfaces
CentOS:ui
$ sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
ifcfg-enp0s3(負責內網互聯)內容:this
BOOTPROTO="static" HWADDR="" ONBOOT="yes" # IPADDR 自定義,要求與網關同一網段 IPADDR="192.168.56.10" NETWORK="192.168.56.0" NETMASK="255.255.255.0" GATEWAY="192.168.56.1" DNS="114.114.114.114 192.168.56.1" #use this file not network manager to manage interface NM_CONTROLLED="no"
使用命令查看 uuid(命令爲 nmcli con ) 後,複製 enp0s8 的 uuid 並粘貼到 ifcfg-enp0s8
ifcfg-enp0s8(負責鏈接外網)內容:rest
DEVICE="enp0s8" TYPE="ethernet" UUID="" HWADDR="" NM_CONTROLLED="no" ONBOOT="yes" BOOTPROTO="dhcp"
sudo systemctl restart network.service
$ ip addr
$ ping 192.168.56.1
$ ping 114.114.114.114
Done!