Localhost
   HOME

TheInfoList



OR:

In
computer networking A computer network is a set of computers sharing resources located on or provided by network nodes. The computers use common communication protocols over digital interconnections to communicate with each other. These interconnections are ...
, localhost is a
hostname In computer networking, a hostname (archaically nodename) is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication, such as the World Wide Web. Hos ...
that refers to the current device used to access it. It is used to access the network services that are running on the host via the
loopback Loopback (also written loop-back) is the routing of electronic signals or digital data streams back to their source without intentional processing or modification. It is primarily a means of testing the communications infrastructure. There are m ...
network interface. Using the loopback interface bypasses any local network interface hardware.


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 A website (also written as a web site) is a collection of web pages and related content that is identified by a common domain name and published on at least one web server. Examples of notable websites are Google, Facebook, Amazon, and Wi ...
may be accessed from a Web browser by the URL it is mainly used for web development purposes ''http://localhost'' to display its home page. The name ''localhost'' normally resolves to the IPv4 loopback
address An address is a collection of information, presented in a mostly fixed format, used to give the location of a building, apartment, or other structure or a plot of land, generally using political boundaries and street names as references, along ...
, and to the
IPv6 Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. IPv ...
loopback address .


Name resolution

IPv4 network standards
reserve Reserve or reserves may refer to: Places * Reserve, Kansas, a US city * Reserve, Louisiana, a census-designated place in St. John the Baptist Parish * Reserve, Montana, a census-designated place in Sheridan County * Reserve, New Mexico, a US vi ...
the entire address block 127.0.0.0/8 (more than 16 million addresses) for loopback purposes. Updated by RFC 8190. That means any packet sent to any of those addresses is looped back. The address 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. The
IPv6 Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. IPv ...
standard assigns only a single address for loopback: . The resolution of the name ''localhost'' to one or more
IP address An Internet Protocol address (IP address) is a numerical label such as that is connected to a computer network that uses the Internet Protocol for communication.. Updated by . An IP address serves two main functions: network interface ident ...
es is normally configured by the following lines in the operating system's
hosts file The computer file hosts is an operating system file that maps hostnames to IP addresses. It is a plain text file. Originally a file named HOSTS.TXT was manually maintained and made available via file sharing by Stanford Research Institute for the ...
:
127.0.0.1    localhost
::1          localhost
The name may also be resolved by
Domain Name System The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned t ...
(DNS) servers, but queries for this name should be resolved locally, and should not be forwarded to remote name servers. In addition to the mapping of ''localhost'' to the loopback addresses ( and ), ''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 A domain name is a string that identifies a realm of administrative autonomy, authority or control within the Internet. Domain names are often used to identify services provided through the Internet, such as websites, email services and more. As ...
, originally set aside to avoid confusion with the hostname used for loopback purposes. IETF standards prohibit domain name registrars from assigning the name ''localhost''.


IETF standards

The name ''localhost'' is reserved for loopback purposes by RFC 6761 (''Special-Use Domain Names''), which achieved the
Proposed Standard In computer network A computer network is a set of computers sharing resources located on or provided by network nodes. The computers use common communication protocols over digital interconnections to communicate with each other. The ...
maturity level in February 2013. The standard sets forth a number of special considerations governing the use of the name in the
Domain Name System The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned t ...
: * An IPv4 or
IPv6 Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. IPv ...
address query for the name localhost must always resolve to the respective loopback address, which is specified in a separate standard. * 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 The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned t ...
root servers with traffic, caching name servers should never request name server records for ''localhost'', or forward resolution to authoritative name servers. * DNS registrars are precluded from delegating domain names in the top-level domain ''localhost''. * When authoritative name servers receive queries for 'localhost' in spite of the provisions mentioned resolve them appropriately. The IPv4 loopback addresses are reserved within the IPv4 address space by the IETF "Special Use IPv4 Addresses" standard (RFC 5735). The reservation can be traced back to the November 1986 "Assigned Numbers" standard (RFC 990). In contrast, the IETF "IP Version 6 Addressing Architecture" standard (RFC 4291) reserves the single IPv6 loopback address within the IPv6 address space. 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. Any such packet that is erroneously transmitted is not supposed to be routed, and should be dropped by all routers or hosts that receive it.


Packet processing

The processing of any packet sent to a loopback address is implemented in the link layer of the
TCP/IP stack The Internet protocol suite, commonly known as TCP/IP, is a framework for organizing the set of communication protocols used in the Internet and similar computer networks according to functional criteria. The foundational protocols in the suit ...
. Such packets are never passed to any
network interface controller A network interface controller (NIC, also known as a network interface card, network adapter, LAN adapter or physical network interface, and by similar terms) is a computer hardware component that connects a computer to a computer network. Ear ...
(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 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 and 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 packet A Martian packet is an IP packet seen on the public Internet that contains a source or destination address that is reserved for special-use by Internet Assigned Numbers Authority (IANA) as defined in , Appendix B Glossary (Martian Address Filter ...
s. As with any other bogus packets, they may be malicious and any problems they might cause can be avoided by applying
bogon filtering Bogon filtering is the practice of filtering bogons, which are bogus (fake) IP addresses of a computer network. Bogons include IP packets on the public Internet that contain addresses that are not in any range allocated or delegated by the Intern ...
.


Special cases

The releases of the
MySQL MySQL () is an open-source relational database management system (RDBMS). Its name is a combination of "My", the name of co-founder Michael Widenius's daughter My, and "SQL", the acronym for Structured Query Language. A relational database ...
database differentiate between the use of the hostname ''localhost'' and the use of the addresses and . 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 A Unix domain socket aka UDS or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system. It is also referred to by its address family AF_UN ...
, while a TCP connection via the loopback interface requires the direct use of the explicit address. One notable exception to the use of the addresses is their use in
Multiprotocol Label Switching Multiprotocol Label Switching (MPLS) is a routing technique in telecommunications networks that directs data from one node to the next based on labels rather than network addresses. Whereas network addresses identify endpoints the labels identif ...
(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

*
Private network In Internet networking, a private network is a computer network that uses a private address space of IP addresses. These addresses are commonly used for local area networks (LANs) in residential, office, and enterprise environments. Both the IP ...
* Reserved IP addresses *
0.0.0.0 In the Internet Protocol Version 4, the address is a non-routable meta-address used to designate an invalid, unknown or non-applicable target. This address is assigned specific meanings in a number of contexts, such as on clients or on servers. ...


References

{{reflist IP addresses