解決linux ping: unknown host www.baidu.com

來源:互聯網
上載者:User
解決linux ping: unknown host www.baidu.com轉自 http://www.cnblogs.com/happyhotty/articles/2539951.html

"ping: unknown host www.baidu.com" 
解決方案: 
   如果某台Linux伺服器ping不通網域名稱, 如下提示: 

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

首先確定已經串連上路由器,並且路由器能夠訪問外網,可以通過訪問網關進行確定

[root@localhost ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.75 ms

如果確定網路沒問題的情況下, 可以通過如下步驟尋找解決辦法: 
1) 確定設定了網域名稱伺服器, 沒有的話, 建議設定Google的公用DNS服務, 它應該不會出問題的 


[root@localhost ~]# cat /etc/resolv.conf

search localdomain

因為我的DNS沒有設定所以導致了ping外網ping不通。將dns添加到該檔案中

[root@localhost ~]# vi /etc/resolv.conf

search localdomain
nameserver 202.98.96.68
nameserver 61.139.2.69
~

2) 確保網關已設定 

# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg* 
------------------------------------------------------------------- 
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1 
------------------------------------------------------------------- 

如果未設定, 則通過如下方式增加網關: 

# route add default gw 192.168.40.1 

或者手工編寫/etc/sysconfig/network-scripts/ifcfg*檔案後, 重啟network服務: 

# service network restart 

3) 確保可用dns解析 

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

如果以上哪個有問題, 修正後, 再測試, 應該就沒問題了: 

#ping -c 3 www.baidu.com 
PING www.a.shifen.com (220.181.6.175) 56(84) bytes of data. 
64 bytes from 220.181.6.175: icmp_seq=0 ttl=50 time=9.51 ms 
64 bytes from 220.181.6.175: icmp_seq=1 ttl=50 time=8.45 ms 
64 bytes from 220.181.6.175: icmp_seq=2 ttl=50 time=8.97 ms 
--- www.a.shifen.com ping statistics --- 
3 packets transmitted, 3 received, 0% packet loss, time 2002ms 
rtt min/avg/max/mdev = 8.450/8.977/9.511/0.446 ms, pipe 2 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.