
由於某種原因,兩天前我的主機檔案開始被忽略。
我正在使用帶有 Sierra OSx 的 Mac。這是 /etc/hosts 檔案的目前內容
##
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhostage
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 localkur.com
Ping localkur.com 返回
ping: cannot resolve localkur.com: Unknown host
我已重新啟動系統,使用這些命令清理緩存
sudo killall -HUP mDNSResponder;
sudo discoveryutil mdnsflushcache;
sudo discoveryutil udnsflushcaches;
在不同的文字編輯程式、vm、sublime 等中重新開啟檔案
。
還可以使用此指令監視文件
sudo fs_usage | grep "/etc/hosts"
刷新瀏覽器或用 sublime 儲存時得到結果
12:23:35 open private/etc/hosts 0.000019 Google Chrom
12:23:36 open private/etc/hosts 0.000019 Google Chrom
12:23:41 stat64 /private/etc/hosts 0.000022 Sublime Text
12:23:43 stat64 /private/etc/hosts 0.000019 Sublime Text
12:23:45 stat64 /private/etc/hosts 0.000019 Sublime Text
12:23:45 open /private/etc/hosts 0.000019 Sublime Text
我缺什麼?
為什麼這個文件被忽略?
如何再次啟用它?
答案1
該檔案可能已損壞/損壞,它必須是 ASCII 檔案。你應該重新創建它:
- 移動舊文件
mv -f /etc/hosts /etc/oldhosts
- 建立一個新文件
nano
- 用舊文件的值填充它
- 另存為
/etc/hosts
應該可以做到這一點。
答案2
查看系統偏好設定 -> 網路
如果目前活動的“位置”列出了一個或多個 DNS 伺服器,則系統將建立檔案“/etc/resolv.conf”,該檔案將列出這些名稱伺服器作為解析位置,完全繞過 /etc/hosts
resolv.conf 由「網路」首選項動態創建,並根據當前活動「位置」的「DNS 伺服器」欄位進行覆蓋,如果該欄位為空,則將其刪除
答案3
這肯定是一個舊線程,但我今天遇到了同樣的問題,並且找到了解決方案。把它留在這裡以防其他人需要它。
sudo dscacheutil -flushcache
在我的例子中,刷新 DNS 快取就達到了目的。
答案4
可以使用 TAB 代替 SPACE。就我而言。修得很好!