ping域名提示 unknown host,ping IP正常,nslookup解析域名正常怎么解决?

碰一个问题,linux机器可以ping通IP,但是ping域名直接报错【ping: unknown host baidu.com】

问题现象: ping 域名时不能解析域名,ping IP可以,初步看机器网络是正常的

  1. root@BJ-CentOS7 ~ # ping baidu.com
  2. ping: unknown host baidu.com
  3. root@BJ-CentOS7 ~ # ping -c 2 8.8.8.8
  4. PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
  5. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=251 time=96.6 ms
  6. 64 bytes from 8.8.8.8: icmp_seq=2 ttl=251 time=100 ms
  7. --- 8.8.8.8 ping statistics ---
  8. 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
  9. rtt min/avg/max/mdev = 96.635/98.431/100.227/1.796 ms

问题分析: 从问题现象看,这里我们怀疑是不是 DNS 配置有问题呢?于是测试发现nslookup可以正常解析域名,DNS配置是没错的

  1. root@BJ-CentOS7 ~ # nslookup baidu.com
  2. Server: 183.60.83.19
  3. Address: 183.60.83.19#53
  4. Non-authoritative answer:
  5. Name: baidu.com
  6. Address: 123.125.115.110
  7. Name: baidu.com
  8. Address: 220.181.57.216
  9. root@BJ-CentOS7 ~ # grep nameserver /etc/resolv.conf
  10. nameserver 183.60.83.19
  11. nameserver 183.60.82.98

这里从网上了解到,原来 ping 程序解析域名依赖于C库中的函数 gethostbyname() 和 gethostbyaddr(),而这里对应的配置文件 /etc/nsswitch.conf 中的hosts 配置项: files 表示使用 /etc/hosts 和 /etc/network 配置文件 dns 表示使用 /etc/resolv.conf 文件中的 DNS解析地址 nis 表示查询NIS系统的配置信息

  1. root@BJ-CentOS7 ~ # grep hosts /etc/nsswitch.conf
  2. #hosts: db files nisplus nis dns
  3. hosts: files
  4. root@BJ-CentOS7 ~ # cat /etc/hosts
  5. 127.0.0.1 localhost localhost.localdomain VM_1_10_centos
  6. root@BJ-CentOS7 ~ # ping -c 2 localhost
  7. PING localhost (127.0.0.1) 56(84) bytes of data.
  8. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.023 ms
  9. 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.035 ms
  10. --- localhost ping statistics ---
  11. 2 packets transmitted, 2 received, 0% packet loss, time 999ms
  12. rtt min/avg/max/mdev = 0.023/0.029/0.035/0.006 ms

验证发现果然写在 hosts 文件中的地址可以正常被 ping 程序解析,问题基本清楚,nslookup 是直接使用 /etc/resolv.conf 中的 DNS 服务器解析域名,而 ping 程序在没有在 /etc/nsswitch.conf 中的 hosts: dns 选项,所以无法解析 /etc/hosts 文件中不存在的解析记录

解决方案: 在 /etc/nsswitch.conf 文件的 hosts 配置项中添加 dns 选项,则可以使用 /etc/resolv.conf 中的 DNS 服务器解析域名,再次测试,可以正常解析域名了

  1. root@BJ-CentOS7 ~ # grep hosts /etc/nsswitch.conf
  2. #hosts: db files nisplus nis dns
  3. hosts: files dns
  4. root@BJ-CentOS7 ~ # ping -c 2 baidu.com
  5. PING baidu.com (220.181.57.216) 56(84) bytes of data.
  6. 64 bytes from 220.181.57.216: icmp_seq=1 ttl=250 time=9.05 ms
  7. 64 bytes from 220.181.57.216: icmp_seq=2 ttl=250 time=9.06 ms
  8. --- baidu.com ping statistics ---
  9. 2 packets transmitted, 2 received, 0% packet loss, time 1001ms
  10. rtt min/avg/max/mdev = 9.051/9.057/9.063/0.006 ms

未经允许不得转载(声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:net-net@foxmail.com进行举报,并提供相关证据,工作人员会在10个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。):策信智库资讯网 » ping域名提示 unknown host,ping IP正常,nslookup解析域名正常怎么解决?

赞 (0)
indian school girls porn videos tubexo.mobi school girls xvideo broken marriage vow march 22 full episode thepinoytv.net abot kamay na pangarap episode today افلام سكس هندي arabicpornmovies.com بنات محجبات سكس شاب ينكح اخته arabianporns.com قصص سكس سعودي سكس في الطيارة muarab.net سكس عربى واجنبى girls fucking videos freshpornclips.mobi xxx free download سكس بكارة porndot.info موقع افلام اباحية bengali sexy sex teenpornvideo.mobi chella kutty كسه 24pornos.com سكس قرد مع بنت punjabi randi sex nudevista.pro mia khalifa naked ashima bhalla bigassporntrends.com www.indianxx nude b grade indiananalfuck.com you pron xxx hinde vedio tubeofporn.mobi iwink tv kolkata girls need sex pornhindimovies.com indian xxx vidio saxy bf download pornborn.mobi co xxx