Localhost#Loopback

{{short description|Standard hostname for a networked device's loopback interface}}

{{pp-protected|small=yes}}

{{for|the domain name label|.localhost}}

{{More citations needed|date=June 2020}}

{{Lowercase title}}

{{Network science}}

{{OS}}

In computer networking, localhost is a hostname that refers to the current computer used to access it. The name localhost is reserved for loopback purposes.{{Ref RFC|6761}}

It is used to access the network services that are running on the host via the loopback network interface. Using the loopback interface bypasses any local network interface hardware.

Loopback

{{main article|Loopback}}

The local loopback mechanism may be used to run a network service on a host without requiring a physical network interface, or without making the service accessible from the networks the computer may be connected to. For example, a locally installed website may be accessed from a Web browser by the URL http://localhost to display its home page.

IPv4 network standards reserve the entire address block {{IPaddr|127.0.0.0|8}} (more than 16 million addresses) for loopback purposes.{{Ref RFC|6890}} That means any packet sent to any of those addresses is looped back. The address {{IPaddr|127.0.0.1}} is the standard address for IPv4 loopback traffic; the rest are not supported by all operating systems. However, they can be used to set up multiple server applications on the host, all listening on the same port number. In the IPv6 addressing architecture{{Ref RFC|4291}} there is only a single address assigned for loopback: {{IPaddr|::1}}. The standard precludes the assignment of that address to any physical interface, as well as its use as the source or destination address in any packet sent to remote hosts.

Name resolution

{{Anchor|Name resolution}}

The name localhost normally resolves to the IPv4 loopback address {{IPaddr|127.0.0.1}}, and to the IPv6 loopback address {{IPaddr|::1}}.

This resolution is normally configured by the following lines in the operating system's hosts file:

127.0.0.1 localhost

::1 localhost

The name may also be resolved by Domain Name System (DNS) servers, but there are special considerations{{Ref RFC|6761}} governing the use of this name:

  • An IPv4 or IPv6 address query for the name localhost must always resolve to the respective loopback address.
  • Applications may resolve the name to a loopback address themselves, or pass it to the local name resolver mechanisms.
  • When a name resolver receives an address (A or AAAA) query for localhost, it should return the appropriate loopback addresses, and negative responses for any other requested record types. Queries for localhost should not be sent to caching name servers.
  • To avoid burdening the Domain Name System root servers with traffic, caching name servers should never request name server records for localhost, or forward resolution to authoritative name servers.
  • When authoritative name servers receive queries for 'localhost' in spite of the provisions mentioned above, they should resolve them appropriately.

In addition to the mapping of localhost to the loopback addresses ({{IPaddr|127.0.0.1}} and {{IPaddr|::1}}), localhost may also be mapped to other IPv4 (loopback) addresses and it is also possible to assign other, or additional, names to any loopback address. The mapping of localhost to addresses other than the designated loopback address range in the hosts file or in DNS is not guaranteed to have the desired effect, as applications may map the name internally.

In the Domain Name System, the name .localhost is reserved as a top-level domain name, originally set aside to avoid confusion with the hostname localhost.{{Ref RFC|2606}} Domain name registrars are precluded from delegating domain names in the top-level .localhost domain.{{Ref RFC|6761}}

Historical notes

In 1981, the block {{IPaddr|127.0.0.0|8}} got a 'reserved' status,{{Ref RFC|790}} as not to assign it as a general purpose class A IP network.

This block was officially assigned for loopback purposes in 1986.{{Ref RFC|990}}

Its purpose as a Special Use IPv4 Address block was confirmed in 1994,{{Ref RFC|1700}}, 2002{{Ref RFC|3330}}, 2010,{{Ref RFC|5735}}, and last in 2013.{{Ref RFC|6890}}

From the outset, in 1995, the single IPv6 loopback address {{IPaddr|::1}} was defined.{{Ref RFC|1884}} Its purpose and definition was unchanged in 1998,{{Ref RFC|2373}}, 2003,{{Ref RFC|3513}}, and up to the current definition, in 2006.{{Ref RFC|4291}}

Packet processing

The processing of any packet sent to a loopback address, is implemented in the link layer of the TCP/IP stack. Such packets are never passed to any network interface controller (NIC) or hardware device driver and must not appear outside of a computing system, or be routed by any router. This permits software testing and local services, even in the absence of any hardware network interfaces.

Looped-back packets are distinguished from any other packets traversing the TCP/IP stack only by the special IP address they were addressed to. Thus, the services that ultimately receive them respond according to the specified destination. For example, an HTTP service could route packets addressed to {{IPaddr|127.0.0.99:80}} and {{IPaddr|127.0.0.100:80}} to different Web servers, or to a single server that returns different web pages. To simplify such testing, the hosts file may be configured to provide appropriate names for each address.

Packets received on a non-loopback interface with a loopback source or destination address must be dropped. Such packets are sometimes referred to as Martian packets.{{cite web|author=Raymond, Eric S.|title=The Jargon File|url=http://www.catb.org/~esr/jargon/html/M/martian.html}} As with any other bogus packets, they may be malicious and any problems they might cause can be avoided by applying bogon filtering.

Special cases

The releases of the MySQL database differentiate between the use of the hostname localhost and the use of the addresses {{IPaddr|127.0.0.1}} and {{IPaddr|::1}}.{{cite web|url=http://dev.mysql.com/doc/refman/5.5/en/programs-overview.html|title=MySQL :: MySQL 5.5 Reference Manual :: 4.1 Overview of MySQL Programs}} When using localhost as the destination in a client connector interface of an application, the MySQL application programming interface connects to the database using a Unix domain socket, while a TCP connection via the loopback interface requires the direct use of the explicit address.

One notable exception to the use of the {{IPaddr|127.0.0.0|8}} addresses is their use in Multiprotocol Label Switching (MPLS) traceroute error detection, in which their property of not being routable provides a convenient means to avoid delivery of faulty packets to end users.

See also

References

{{reflist}}

{{Operating System}}

{{Computer science}}

{{Authority control}}

Category:Internet architecture

Category:IP addresses