写Java web作业时突然显示Safari无法连接localhost,找了半天是因为etc下的hosts文件不见了,下面是如何恢复:
打开终端,输入:
sudo -s
然后将下面的全输入进去,回车
cat <<EOF > /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 localhost
255.255.255.255 broadcasthost
::1 localhost
EOF
然后
sudo chown root:wheel /etc/hosts; sudo chmod 644 /etc/hosts
最后关闭终端,就能看到hosts文件了