Networking of virtual machine Centos7

It has troubled me for a long time. In summary,
I use a VM virtual machine to connect to the Internet through NAT.

1. First look at the gateway of the virtual machine,

Insert picture description here
Insert picture description here

2. Modify the file

[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# vim ifcfg-ens33 

Modified file

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #重要
DEFROUTE=static
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=58767061-ebf4-42ef-9f0b-c431905e206d
DEVICE=ens33
ONBOOT=yes #重要
IPV6_PRIVACY=no
IPADDR=192.168.12.1 #最后一位随便弄
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.12.2 #第一步的网关
DNS1=192.168.12.2 #第一步的网关                     

Restart after saving

#重启
[root@localhost network-scripts]# service network restart
Restarting network (via systemctl):                        [  确定  ]
# 然后随便找个网址测试下
[root@localhost network-scripts]# ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=6.55 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=3.26 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=3.50 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=128 time=3.17 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=128 time=3.36 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=6 ttl=128 time=3.51 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=7 ttl=128 time=3.66 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=8 ttl=128 time=3.40 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=9 ttl=128 time=3.48 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=10 ttl=128 time=3.29 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=11 ttl=128 time=3.41 ms

OK, you can go online

Guess you like

Origin blog.csdn.net/yi742891270/article/details/110729434