0.0.0.0 & 127.0.0.1 & Localhost

0.0.0.0

In the Internet Protocol Version 4, the address 0.0.0.0 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.

在IPv4中乘寒,地址0.0.0.0是一個不可路由的(non-routable)元地址(meta-address)陪捷,它用于指定無效讶请,未知或不適用的目標(biāo)。這個地址在不同的上下文中被賦予了特殊的意義青灼。

As a host address

Uses includes:

  • A way to specify any IPv4 address at all. It is used in this way when configuring servers (i.e. when binding listening sockets). This is known to TCP programmers as INADDR_ANY. (bind(2) binds to addresses, not interfaces.)
  • The address a host claims as its own when it has not yet been assigned an address. Such as when sending the initial DHCPDISCOVER packet when using DHCP.
  • The address a host assigns to itself when address request via DHCP has failed, provided the host's IP stack supports this. This usage has been replaced with the APIPA mechanism in modern operating systems.
  • A way to explicitly specify that the target is unavailable.

In the context of servers, 0.0.0.0 can mean all IPv4 addresses on the local machine. If a host has two IP addresses, 192.168.1.1 and 10.1.2.1, and a server running on the host is configured to listen on 0.0.0.0, it will be reachable at both of those IP addresses.

As a default route

In the context of routing, 0.0.0.0 is usually used with a network mask of zero as the network address of the default route. This will often be expressed as 0.0.0.0/0 or 0.0.0.0 0.0.0.0.

This matches all addresses in the IPv4 address space and is present on most hosts, directed towards a local router.

In IPv6

In IPv6, the all-zeros address is typically represented by ::.

Localhost & 127.0.0.1

In computer networking, localhost is a hostname that means this computer. 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

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.

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

Name resolution

IPv4 network standards reserve the entire 127.0.0.0/8 address block (total: more than 16 million addresses) for loopback purposes. That means any packet sent to any of those addresses (127.0.0.1 through 127.255.255.255) is looped back. The address 127.0.0.1 is the standard address normally used for IPv4 loopback traffic; the rest are not supported on all operating systems (and most people don't know of their existence). However, they can be used to set up multiple servers on the local machine, all listening on the same port. The IPv6 standard assigns only a single address for loopback: ::1.

The resolution of the name localhost to one or more IP addresses 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 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 (127.0.0.1 and ::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 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),[3] which achieved the Proposed Standard 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:

  • An IPv4 or IPv6 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 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 above, they should 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 ::1 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. 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 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 127.0.0.99:80 and 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. 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 127.0.0.1 and ::1. 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 127.0.0.0/8 network 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.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市仗岸,隨后出現(xiàn)的幾起案子耿焊,更是在濱河造成了極大的恐慌,老刑警劉巖奕坟,帶你破解...
    沈念sama閱讀 222,252評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件祥款,死亡現(xiàn)場離奇詭異,居然都是意外死亡月杉,警方通過查閱死者的電腦和手機刃跛,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,886評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來苛萎,“玉大人桨昙,你說我怎么就攤上這事‰缜福” “怎么了蛙酪?”我有些...
    開封第一講書人閱讀 168,814評論 0 361
  • 文/不壞的土叔 我叫張陵,是天一觀的道長翘盖。 經(jīng)常有香客問我桂塞,道長,這世上最難降的妖魔是什么馍驯? 我笑而不...
    開封第一講書人閱讀 59,869評論 1 299
  • 正文 為了忘掉前任阁危,我火速辦了婚禮玛痊,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘狂打。我一直安慰自己擂煞,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 68,888評論 6 398
  • 文/花漫 我一把揭開白布趴乡。 她就那樣靜靜地躺著对省,像睡著了一般。 火紅的嫁衣襯著肌膚如雪晾捏。 梳的紋絲不亂的頭發(fā)上官辽,一...
    開封第一講書人閱讀 52,475評論 1 312
  • 那天,我揣著相機與錄音粟瞬,去河邊找鬼同仆。 笑死,一個胖子當(dāng)著我的面吹牛裙品,可吹牛的內(nèi)容都是我干的俗批。 我是一名探鬼主播,決...
    沈念sama閱讀 41,010評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼市怎,長吁一口氣:“原來是場噩夢啊……” “哼岁忘!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起区匠,我...
    開封第一講書人閱讀 39,924評論 0 277
  • 序言:老撾萬榮一對情侶失蹤干像,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后驰弄,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體麻汰,經(jīng)...
    沈念sama閱讀 46,469評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,552評論 3 342
  • 正文 我和宋清朗相戀三年戚篙,在試婚紗的時候發(fā)現(xiàn)自己被綠了五鲫。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,680評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡岔擂,死狀恐怖位喂,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情乱灵,我是刑警寧澤塑崖,帶...
    沈念sama閱讀 36,362評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站痛倚,受9級特大地震影響规婆,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,037評論 3 335
  • 文/蒙蒙 一聋呢、第九天 我趴在偏房一處隱蔽的房頂上張望苗踪。 院中可真熱鬧颠区,春花似錦削锰、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,519評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至朋截,卻和暖如春蛹稍,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背部服。 一陣腳步聲響...
    開封第一講書人閱讀 33,621評論 1 274
  • 我被黑心中介騙來泰國打工唆姐, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人廓八。 一個月前我還...
    沈念sama閱讀 49,099評論 3 378
  • 正文 我出身青樓奉芦,卻偏偏與公主長得像,于是被迫代替她去往敵國和親剧蹂。 傳聞我的和親對象是個殘疾皇子声功,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,691評論 2 361

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,346評論 0 10
  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,874評論 0 0
  • 墨菲定律:如果事情有變壞的可能,不管這種可能性有多小宠叼,它總會發(fā)生先巴。 既然麻煩很難避免,那有沒有解決麻煩的萬能鑰匙呢...
    日更飄閱讀 347評論 0 0
  • 這個系列主要是以 門票/小票/車票/……各種票為主要內(nèi)容記錄出門在外的樁樁件件冒冬,伴以介紹手帳制作過程用到的材...
    pipibear閱讀 334評論 0 4
  • 我今天想跟你分享的是偶爾有同學(xué)會問我的一個問題:作為一個新人伸蚯,如何在職場中快速成長? 首先我們來看一看對于職場快速...
    DingZhang閱讀 744評論 0 0