Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the host localhost always available for the own system?

Tags:

localhost

ping

Is it always possible to ping localhost and it resolves to 127.0.0.1?

I know Windows Vista, XP, Ubuntu and Debian do it but does everyone do it?

like image 268
Thomaschaaf Avatar asked Nov 27 '22 08:11

Thomaschaaf


2 Answers

Any correct implementation of TCP/IP will reserve the address 127.0.0.1 to refer to the local machine. However, the mapping of the name "localhost" to that address is generally dependent on the system hosts file. If you were to remove the localhost entry from hosts, then the localhost name may no longer resolve properly at all.

like image 132
Greg Hewgill Avatar answered Dec 28 '22 09:12

Greg Hewgill


127.0.0.1 is reserved in any IP stack for the local host.

"localhost" as a host name is not guaranteed to be there. If the host/DNS settings are misconfigured, localhost will not resolve.

Example on a debian box:

topaz:/root# vi /etc/hosts
[comment out localhost entry]

topaz:/root# ping localhost 
ping: unknown host localhost
like image 21
Thorsten79 Avatar answered Dec 28 '22 10:12

Thorsten79