更改網絡適配器
點擊自己要共享網絡的網卡,我這裏是WLAN,在屬性面板選擇共享,在家庭網絡連接裏選擇自己的虛擬機網卡名,我這裏的VitrubalBox就是虛擬機的。
注意:第一次設置會提示要把IP變爲192.168.137.1,同時設置成動態ip,按要求設置即可。
設置虛擬機網絡參數配置
點擊要設置的虛擬機設置網卡1爲NET模式:
設置網卡2位host-only模式
配置虛擬機網卡
啓動虛擬機,ifconfig查看當前網卡信息
這裏看到有2個,分別是enp0s3和enp0s8,然後在/etc/sysconfig/network-scripts/目錄下找到對應網卡配置:
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-enp0s3 ifdown-eth ifdown-post ifdown-TeamPort ifup-eth ifup-plip ifup-sit init.ipv6-global
ifcfg-enp0s8 ifdown-ib ifdown-ppp
enp0s3對應網卡1,內容如下:
[root@localhost network-scripts]# cat ifcfg-enp0s3
TYPE="Ethernet"
NAME="enp0s3"
HWADDR=08:00:27:11:46:D3
ONBOOT="yes"
BOOTPROTO="DDHCP"
enp0s8對應網卡2,內容如下:
[root@localhost network-scripts]# cat ifcfg-enp0s8
DEVICE=enp0s8
HWADDR=08:00:27:43:62:90
TYPE=Ethernet
NAME=enp0s8
ONBOOT=yes
#BOOTPROTO=dhcp
GATEWAY=192.168.137.1
NETMASK=255.255.255.0
IPADDR=192.168.137.20
重啓網絡環境
[root@localhost network-scripts]# service network restart
Restarting network (via systemctl): [ 確定 ]
測試
使用ping測試下:
[root@localhost ~]# ping csdn.net
PING csdn.net (47.95.164.112) 56(84) bytes of data.
64 bytes from 47.95.164.112: icmp_seq=1 ttl=90 time=46.4 ms
64 bytes from 47.95.164.112: icmp_seq=2 ttl=90 time=13.4 ms
64 bytes from 47.95.164.112: icmp_seq=3 ttl=90 time=13.2 ms
64 bytes from 47.95.164.112: icmp_seq=4 ttl=90 time=12.9 ms
64 bytes from 47.95.164.112: icmp_seq=5 ttl=90 time=14.4 ms
^C64 bytes from 47.95.164.112: icmp_seq=6 ttl=90 time=54.4 ms
如果無法ping通,嘗試配置下DNS再試:
[root@localhost network-scripts]# cat /etc/resolv.conf
# Generated by NetworkManager
search workgroup
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 140.207.198.6