在linux下,ping域名ping不了,ping ip却可以解决办法

ping域名:

[root@zyy ~]# ping www.baidu.com
ping: unknown host www.baidu.com

ping ip时:

[root@zyy ~]# ping 115.239.211.112
PING 115.239.211.112 (115.239.211.112) 56(84) bytes of data.
64 bytes from 115.239.211.112: icmp_seq=1 ttl=54 time=7.25 ms
64 bytes from 115.239.211.112: icmp_seq=2 ttl=54 time=7.36 ms
64 bytes from 115.239.211.112: icmp_seq=3 ttl=54 time=6.86 ms
64 bytes from 115.239.211.112: icmp_seq=4 ttl=54 time=6.93 ms
64 bytes from 115.239.211.112: icmp_seq=5 ttl=54 time=6.81 ms
64 bytes from 115.239.211.112: icmp_seq=6 ttl=54 time=6.56 ms
--- 115.239.211.112 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5091ms
rtt min/avg/max/mdev = 6.567/6.967/7.368/0.291 ms


最终发现是/etc/resolv.conf中没DNS解析的

解决办法:在/etc/resolv.conf中添加

nameserver 192.168.1.1
search localdomain

结果:

[root@zyy ~]# ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=54 time=6.72 ms
64 bytes from 115.239.210.27: icmp_seq=2 ttl=54 time=6.06 ms
64 bytes from 115.239.210.27: icmp_seq=3 ttl=54 time=6.09 ms
64 bytes from 115.239.210.27: icmp_seq=4 ttl=54 time=6.16 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3963ms
rtt min/avg/max/mdev = 6.067/6.264/6.728/0.281 ms

你可能感兴趣的:(在linux下,ping域名ping不了,ping ip却可以解决办法)