You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Trouble with ping localhost not working.

I'm using a Mac Book Pro running Mountain Lion 10.8.2.


Using Xcode I tried to test my app and found an alert box saying a string 'localhost' was not found. Tried to ping localhost and found that the DNS can't resolve this domain. I don't know if it's related but since a few weeks ago I can't use network printers hosted on Windows computers. OS X sees the workgroup and list computers but when I try to connect it throws an error telling the IP is wrong or the connection is lost.


Even stranger is the fact that ping can resolve localhost. (with the dot at the end).


Any help with either of this two issues??

OS X Mountain Lion (10.8.2)

Posted on Oct 17, 2012 12:08 PM

Reply
13 replies
Sort By: 

Oct 17, 2012 1:25 PM in response to andres.hume

Check the hosts file (/etc/hosts). It should begin with this:


##

# 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

Reply

Oct 17, 2012 2:53 PM in response to Linc Davis

yeap! First of all, thanks for your reply!


It looks just like that but I still have the same problem. Even worse, I've just added a line to the hosts file and it seems like de OS is overriding the changes. For exmaple, I added this line:

190.211.1.1 intranet.somecompany.com.ar


and when I ping this domain....it says it can't be resolved.

Any other clue? I hope there is another way to solve this than having to make a clean installation.


Best regards!

Andres (Andrew)

Reply

Oct 22, 2012 5:43 AM in response to Linc Davis

Sure! here it goes!

The output is:

-rw-rw-rw-@ 1 andreshume staff - 2011 Oct 17 16:58 /etc/hosts

0: group:admin allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity


And the contents of the hosts file are:


##

# 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

# APURAR LOS HOSTS

190.210.142.NN intranet.mycompany.com.ar


I've changed the IP address and the "mycompany" just to preserve this info. If you really need it, I will post it.


Thx again!

Andrés

Reply

Feb 18, 2014 4:25 PM in response to Linc Davis

I am facing the same problem. The output for "file -b /etc/hosts" is "ASCII text".

I really don't know how to change or clean it. The content in the file host is really simple, just numbers, dots and #.

For me, works when I use 127.0.0.1 and "localhost." but "localhost" without the dot doesn't work. Please help me, it is driving me crazy!

Reply

Trouble with ping localhost not working.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.