• CentOS ping: unknown host 解决方法


    如果ping命令返回如下错误,那主要的可能性就是系统的DNS设置有误

    [root@CentOS5 ~]# ping www.sina.com.cn  
    ping: unknown host www.sina.com.cn  
    

     

    可以通过如下方法来解决,此方法已经在linux和solaris系统下通过验证。
    1) 确定设置了域名服务器
    没有的话, 建议设置电信的DNS服务

    # cat /etc/resolv.conf  
    -------------------------------------------------------------------  
    nameserver 114.114.114.114  
    -------------------------------------------------------------------  
    

    2) 在网卡里配置 DNS 和 GATEWAY

    DNS1=114.114.114.114
    GATEWAY=192.168.22.254
    

    3) 确保路由表正常

    [root@CentOS5 ~]# netstat -rn  
    Kernel IP routing table  
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface  
    192.168.128.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0  
    169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0  
    0.0.0.0         192.168.128.2   0.0.0.0         UG        0 0          0 eth0  
    

    如果未设置, 则通过如下方式增加网关:

    # route add default gw 192.168.22.254
    

    3) 确保可用dns解析(这步常忘了)

    # grep hosts /etc/nsswitch.conf  
    -------------------------------------------------------------------  
    hosts:      files dns  
    -------------------------------------------------------------------   
    

    注意,上面的配置要加上dns。
    以下是dns的配置,备忘。
    hosts: dns files
    表示只在DNS失效时候才使用/etc/hosts文件

    hosts: dns 
    表示只用DNS解析主机

    host: files 
    表示只用/etc/hosts文件解析主机

    hosts: files dns
    将使用/etc/hosts文件解析主机,表示如果无法解析主机名将使用DNS。

    转自:http://blog.csdn.net/huang_xw/article/details/8710888#

     

  • 相关阅读:
    Python学习第75天(js历史和引入,模块复习)
    Python学习第74天(抽屉习题笔记)
    Python学习第73天(shelve模块、习题练习)
    Js查漏补缺02-各种数据类型
    Js查漏补缺01-js学习笔记
    开篇
    小小python欢乐多
    阅读笔记09 个人对于三年来软件工程的一点心得
    14周周博客
    软件杯第二阶段
  • 原文地址:https://www.cnblogs.com/yorkyang/p/7359558.html
Copyright © 2020-2023  润新知