[root@www ~]# ping www.baidu.com
ping: www.baidu.com: Name or service not known
[root@www ~]#
1. View the network configuration
Remember the three items of subnet IP, subnet mask, and gateway IP in the NAT settings. The next configuration file is mainly these three items.
2. Edit the network configuration file in Linux
vi /etc/sysconfig/network-scripts/ifcfg-ens33 #Note that the name of the network configuration file may be different. When entering ifcfg, you can press the tab key twice to get a prompt. For example, my machine is ifcfg-ens33
The content is replaced as follows:
TYPE=”Ethernet”
BOOTPROTO=”static” #Static connection
NAME=”ens33”
UUID=”1f093d71-07de-4ca5-a424-98e13b4e9532”
DEVICE=”ens33”
ONBOOT=”yes” #Network device boot
IPADDR=”192.168 .0.101” #192.168.59.x, x is 3~255.
NETMASK=”255.255.255.0” #Subnet mask
GATEWAY=”192.168.66.2” #Gateway IPDNS1= 8.8.8.8
DNS2=8.8.8.4
3. View the network configuration
4. Restart the network service
service network restart
5. Test effect
Ping 192.168.66.2
ping 115.239.210.27 (A certain IP of Baidu, if you ping www.baidu.com directly, there will be a problem with domain name resolution. You can configure it after ensuring network connectivity)
6、DNS文件配置
vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
7、测试
OK 搞定正常上网!
注明:转载自https://www.cnblogs.com/maowenqiang/articles/7727910.html