目录
问题描述:虚拟机不能ping通百度等网站,但是可以ping通当前主机或者其他虚拟机,ping百度提示“ng: unknown host www.baidu.com”
[yiduoyun@localhost ~]$ service network restart
Restarting network (via systemctl): [ 确定 ]
[yiduoyun@localhost ~]$ ping www.baidu.com
ping: unknown host www.baidu.com
[yiduoyun@localhost ~]$ ping 192.168.11.252
PING 192.168.11.252 (192.168.11.252) 56(84) bytes of data.
64 bytes from 192.168.11.252: icmp_seq=1 ttl=64 time=0.949 ms
64 bytes from 192.168.11.252: icmp_seq=2 ttl=64 time=1.52 ms
^Z
[1]+ 已停止 ping 192.168.11.252
[yiduoyun@localhost ~]$ ping 192.168.11.250
PING 192.168.11.250 (192.168.11.250) 56(84) bytes of data.
From 192.168.11.101 icmp_seq=1 Destination Host Unreachable
From 192.168.11.101 icmp_seq=2 Destination Host Unreachable
From 192.168.11.101 icmp_seq=3 Destination Host Unreachable
From 192.168.11.101 icmp_seq=4 Destination Host Unreachable
^Z
[2]+ 已停止 ping 192.168.11.250
解决办法(已解决)
在/etc/resolv.conf 文件中添加 nameserver xxx.xxx.xxx.xxx。
如8.8.8.8或者4.4.4.4,保存退出
[yiduoyun@localhost etc]$ vim resolv.conf
[yiduoyun@localhost etc]$ su
密码:
[root@localhost etc]# vim resolv.conf
[root@localhost etc]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@localhost etc]# ping www.baidu.com
PING www.wshifen.com (103.235.46.40) 56(84) bytes of data.
64 bytes from 103.235.46.40: icmp_seq=3 ttl=128 time=82.0 ms
64 bytes from 103.235.46.40: icmp_seq=4 ttl=128 time=112 ms
^Z
[1]+ 已停止 ping www.baidu.com
[root@localhost etc]#
新的问题: /etc/resolv.conf配置文件重启失效
当配置好之后,可以ping通网络。
但是重启之后,发现又不能ping通百度了。
查看配置文件,配置的内容不见了。oh~~
-_-
[yiduoyun@#localhost ~]$ ping www.baidu.com
ping: unknown host www.baidu.com
[yiduoyun@#localhost ~]$ cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain
hadoop1
# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com
[yiduoyun@#localhost ~]$
结果办法是在“/etc/sysconfig/network-scripts/ifcfg-eno16777736”进行配置,并重启网卡。
所以要确保配置是正确的(以下是我输入错误了)
以及要注意"ONBOOT=yes",这样才能每次开机自动配置。
正确的“/etc/sysconfig/network-scripts/ifcfg-eno16777736"配置文件
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=aba554d6-f4d0-4eda-a017-4bbf3636f902
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.131.10
NETMASK=255.255.255.0
GATEWAY=192.168.11.2
DNS2=223.5.5.5
DNS1=8.8.8.8
DNS3=192.168.11.1
重启网卡
service network restart
再次尝试ping百度,成功
[root@#localhost yiduoyun]# ping www.baidu.comPING www.a.shifen.com (120.232.145.185) 56(84) bytes of data.
64 bytes from 120.232.145.185: icmp_seq=1 ttl=128 time=56.3 ms
64 bytes from 120.232.145.185: icmp_seq=2 ttl=128 time=83.0 ms
^Z
[1]+ 已停止 ping www.baidu.com