Is the host localhost always available for the own system?

∥☆過路亽.° 提交于 2019-12-22 09:57:45

问题


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?


回答1:


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.




回答2:


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



回答3:


No. For a start localhost is a convention rather than a rule. Mostly it's set by default, but there's nothing to mandate it.

Secondly, there's nothing to say that you can always ping 127.0.0.1. As an example (on a unix system) try the following:

sudo ifconfig lo down ping 127.0.0.1

As cruizer said, 127.0.0.1 (if it exists) is defined to be the local machine. But it doesn't have to exist.




回答4:


The pedantic answer (sorry, Greg :), is to read RFC 3330:

   127.0.0.0/8 - This block is assigned for use as the Internet host
   loopback address.  A datagram sent by a higher level protocol to an
   address anywhere within this block should loop back inside the host.
   This is ordinarily implemented using only 127.0.0.1/32 for loopback,
   but no addresses within this block should ever appear on any network
   anywhere [RFC1700, page 5].

(The "ordinarily" above should probably be read as "often" - most current operating systems support using all of 127.0.0.0/8 as loopback.)

With regards to whether "localhost" always resolves to 127.0.0.1 - he is correct, it's generally the same, but technically implementation specific:

~> dig localhost.t...e.org

...

;; ANSWER SECTION:
localhost.t...e.org. 86400 IN    A       127.0.0.2



回答5:


If the DNS servers your client is connected to is following rfc1912 then yes, localhost should resolve to 127.0.0.1.

RFC1912
4.1
...
   Certain zones should **always be present** in nameserver configurations:
           primary         localhost               localhost
           primary         0.0.127.in-addr.arpa    127.0
...
   The "localhost" address is a "special" address which always refers to
   the local host.  It should contain the following line:

           localhost.      IN      A       127.0.0.1

   The "127.0" file should contain the line:

           1    PTR     localhost.



回答6:


I think localhost pretty much resolves to 127.0.0.1 for most platforms but all IPs that start with 127...* resolve to localhost as well. Try pinging 127.255.255.254 and it'll still respond.




回答7:


In theory, there are cases where it might not exist. In practice, it's always there.




回答8:


Decent firewalls allow you to filter access on the loopback interfaces too. So, it's possible to set up a firewall rule that drops icmp ping packets going to localhost (127.0.0.1). Also, as everyone else has already mentioned, even the existence of the localhost or 127.0.0.1 address and the loopback interface isn't guaranteed.




回答9:


The answer is:

127.0.0.1, often referred to as the "loopback", is required. Although your computer might let you do silly things, like disable it, or configure that range on a physical interface, these are all invalid.

"localhost" is just a hostname, which by convention, should be 127.0.0.1 As a system administrator or hostmaster, you should avoid configurations that allow localhost to point to other addresses.

You should not edit your hosts file to change the address of "localhost". You should configure your domains to have a localhost. and localhost.domain.com entry that points to 127.0.0.1.

You should not let your proxy servers respond to "localhost" or any FQDN that starts with localhost.




回答10:


Ok.

The reason why it resolves it is record in %WINDOWS_DIR%\System32\drivers\etc\hosts file like this:

127.0.0.1 localhost



来源:https://stackoverflow.com/questions/113293/is-the-host-localhost-always-available-for-the-own-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!