2013-11-01 166 views
-1
127.0.0.1 localhost 
255.255.255.255 broadcasthost 
::1 localhost 
fe80::1%lo0 localhost 

這是我的/ etc/hosts文件,但它真的很奇怪ping失敗並且無法解析localhostping:無法解析本地主機:未知主機OS X

它做工精良,如ping gonjay當我添加

127.0.0.1 gonjay 

我的hosts文件。

+0

不是一個編程問題 - 嘗試http://unix.stackexchange.com? –

回答

5

我固定它通過確保hosts文件中使用Unix行結尾(我用這個崇高文本)

+0

爲我完美工作!也使用Sublime Text。 –

0

可能會幫助那些誰不知道如何讓Unix行結尾

brew install dos2unix 
sudo dos2unix -c mac /private/etc/hosts 

這將轉換你完美的主機文件到UNIX編碼。

1

我已經恢復我的Hosts文件(裏面是空的)解決了這個問題:

但在此之前,你必須檢查你的主機文件。

貓/ etc/hosts中

如果沒有顯示,這意味着你的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 localhost 
255.255.255.255 broadcasthost 
::1 localhost 
fe80::1%lo0 localhost 

如果您的主機文件不是空的,您可以嘗試刪除它並用此行重新添加它。