為什麼更改 /etc/hosts 沒有用

為什麼更改 /etc/hosts 沒有用

以下是命令:

[17:31:13 root etc]# cat /etc/hosts
127.0.0.1       localhost.localdomain localhost
::1     localhost6.localdomain6 localhost6
127.0.0.2   myweb.com
[17:31:25 root etc]# ping myweb.com
PING myweb.com (184.154.233.2) 56(84) bytes of data.
64 bytes from ns1.siteground278.com (184.154.233.2): icmp_seq=1 ttl=42 time=275 ms
64 bytes from ns1.siteground278.com (184.154.233.2): icmp_seq=2 ttl=42 time=273 ms
64 bytes from ns1.siteground278.com (184.154.233.2): icmp_seq=3 ttl=42 time=281 ms
^C
--- myweb.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 273.625/276.874/281.478/3.346 ms

在沒有網路管理員的機器上 ping myweb.com 將得到 127.0.0.2,但我不確定,有人知道這是怎麼回事嗎?

我使用的是 Fedora 20。

答案1

檢查配置/etc/nsswitch.conf並尋找hosts

hosts:      files dns

看起來像那樣嗎?基本上,這一行告訴系統如何解析主機名稱:預設情況下,在我的 RHEL 上,它會先解析主機名,然後解析 DNS 伺服器。

你緩存 DNS 嗎?通常Linux有NSCD(快取 DNS 的守護程序)預設為停用。無論如何,如果配置正確,主機應始終優先於 DNS。

相關內容