VirtualBox虚拟机网络配置
VirtualBox虚拟机网络配置
创建虚拟网络
一般按照VirtualBox之后默认有会有,ip:192.168.56.1
没有的话自行创建一个。
注意:与VirtualBox里面的虚拟网络ip保持一致。
这时候还不能访问以太网的,我们还需要将本机网络共享给VirtualBox虚拟网络。
设置虚拟机网络
- 连接方式选择:
host-only
- 界面名称选择:我们上一步创建的虚拟网络
修改虚拟机内的网络配置文件
Centos7.5 网络配置文件
路径:/etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=1c7f559e-1b58-4336-920d-5286d22cc86e
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.56.111
NETMASK=255.255.255.0
GATEWAY=192.168.56.1
#DNS1=8.8.8.8
#DNS2=114.114.114.114
重启网络
systemctl restart network
测试网络联通性
ping 192.168.56.1
ping www.baidu.com
[root@localhost network-scripts]# ping 192.168.56.1
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=0.223 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=0.392 ms
^C
--- 192.168.56.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.223/0.307/0.392/0.086 ms
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data.
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=52 time=43.7 ms
64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=52 time=44.8 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 43.705/44.283/44.862/0.615 ms
此时,说明网络已经联通