I have setup a new MacBook Pro retina, things were going well but now I cannot access localhost.

$ ping localhost
ping: cannot resolve localhost: Unknown host

My /etc/hosts file is fine, or at least untouched.

I have tried flushing the DNS cache, and dig localhost spits out

; <<>> DiG 9.8.3-P1 <<>> localhost
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 50562
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;localhost.         IN  A

.           1551    IN  SOA a.root-servers.net. nstld.verisign-grs.com. 2013030800 1800 900 604800 86400

;; Query time: 31 msec
;; WHEN: Fri Mar  8 14:53:09 2013
;; MSG SIZE  rcvd: 102

I am at a loss what to try next! I have even run OnyX to clean all cache etc...

  • can you ping
    – bispymusic
    Mar 8, 2013 at 15:30
  • Yep that works fine
    – user44649
    Mar 8, 2013 at 15:47
  • do you use firewalls like little snitch?
    – Eir Nym
    Mar 9, 2013 at 22:40

2 Answers 2


Maybe your host file got mangled. Open a terminal, and read your hosts file:

vim /private/etc/hosts

This should contain a line that maps localhost to   localhost

It could be this file does not exist at all, or the line I gave above is not present. To be able to edit it you need to be superuser, i.e.:

sudo vim /private/etc/hosts

or you can use any other editor besides vim.

  • It seems /private/etc/hosts just opens up /etc/hosts, which contains localhost etc... as you would expect
    – user44649
    Mar 8, 2013 at 19:33

Searching man ...

  • hosts (/etc/hosts), I see that

The hosts file is read by mDNSResponder(8) and used to supply results for calls to getaddrinfo(3), getnameinfo(3), etc. in addition to results obtained from multicast and unicast DNS.

  • dig & host, only mention /etc/resolv.conf, and contain no mention of etc or hosts.

/etc/resolv.conf says it's not used for most DNS lookups on the system (system networking library calls), and suggests scutil --dns and to SEE ALSO dns-sd(1), scutil(8).

I'm stuck with the same weird issue that I can't get ICMP replies from localhost nor the IP on en0, the local Wi-Fi LAN interface.

Perhaps it's something in firewall settings. Or hopefully not, other system security permissions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .