1   localhost broadcasthost
 ::1             localhost

This is my /etc/hosts configuration. I can use ip address to open a loopback, but 'localhost' fails.... I have read these two posts:El Capitan Safari Can't open localhost and El Capitan Safari Can't open localhost, but none of the cases fits my problem.

The error message I got from Safari is

Safari can’t open the page “‎localhost” because the server unexpectedly dropped the connection. This sometimes occurs when the server is busy. Wait for a few minutes, and then try again.

I also tried the localhost on Chrome, it gave me similar message... Is there something wrong with setting alias?

  • If you try to connect to localhost with a browser, you should at least include in your answer which kind of server is running...
    – klanomath
    Sep 13, 2016 at 7:34

3 Answers 3


After reading this post https://stackoverflow.com/questions/20345132/127-0-0-1-is-working-but-localhost-not-working

I figured it out that I only need to comment out ::1 localhost then everything works fine


I don't know the theory behind why this would work , but for your IPv6 try



  • Please don't do that: etc-hosts file maps ip addresses to hostnames, eg. see wikipedia - hosts file
    – huch
    Dec 21, 2018 at 13:26
  • @ThomasKettenbach - I know the theory, but that's how I persuaded mine to behave when IPv6 was introduced. I still don't have a connection that can use it, so it can stay semi-redundant until my ISP gets around to rolling it out.
    – Tetsujin
    Dec 21, 2018 at 13:47

Had a similar issue here. I'm running a local server and try to connect via curl, eg, the following does not work:

curl localhost 8080

but this:

curl 8080


File: /etc/hosts

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##   localhost broadcasthost
::1             localhost

My server only binds to ipv4, that's why i have to tell curl to use ipv4 stack:

curl -4 localhost:8080


You must log in to answer this question.

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