The Question

SuperUser reader Sagnik Sarkar wants to know what the difference between 127.0.0.1 and 0.0.0.0 is:

I understand that 127.0.0.1 points to localhost and that 0.0.0.0 also does as well (correct me if I am wrong). So, what is the difference between 127.0.0.1 and 0.0.0.0?

What is the difference between 127.0.0.1 and 0.0.0.0?

The Answer

SuperUser contributor DavidPostill has the answer for us:

What is the Difference Between 127.0.0.1 and 0.0.0.0?

  • 127.0.0.1 is the loopback address (also known as localhost).
  • 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non-applicable target (a ‘no particular address’ place holder).

In the context of a route entry, it usually means the default route.

In the context of servers, 0.0.0.0 means 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 listens on 0.0.0.0, it will be reachable at both of those IPs.

What is the IP Address 127.0.0.1?

127.0.0.1 is the loopback Internet protocol (IP) address also referred to as the localhost. The address is used to establish an IP connection to the same machine or computer being used by the end-user.

The same convention is defined for computers that support IPv6 addressing using the connotation of ::1. Establishing a connection using the address 127.0.0.1 is the most common practice; however, using any IP address in the range of 127…* will function in the same or a similar manner. The loopback construct gives a computer or device capable of networking the capability to validate or establish the IP stack on the machine.

Source: 127.0.0.1 – What Are its Uses and Why is it Important?

Special Addresses

The class A network number 127 is assigned the loopback function, that is, a datagram sent by a higher level protocol to a network 127 address should loop back inside the host. No datagram sent to a network 127 address should ever appear on any network anywhere.

Source: Network Numbers

If it is Whole Class A, What is the Point of Other Arbitrary Values for the Last Three Octets?

The purpose of the loopback range is testing of the TCP/IP protocol implementation on a host. Since the lower layers are short-circuited, sending to a loopback address allows the higher layers (IP and above) to be effectively tested without the chance of problems at the lower layers manifesting themselves. 127.0.0.1 is the address most commonly used for testing purposes.

Source: IP Reserved, Loopback and Private Addresses

For more information see the Ask Ubuntu question: What is the Loopback Device and How do I Use it?

What is the IP Address 0.0.0.0?

0.0.0.0 is a valid address syntax. So it should parse as valid wherever an IP address in traditional dotted-decimal notation is expected. Once parsed and converted to workable numeric form, then its value determines what happens next.

The all-zero value does have a special meaning. So it is valid, but has a meaning that may not be appropriate (and thus treated as not valid) for particular circumstances. It is basically the ‘no particular address’ placeholder. For things like address binding of network connections, the result can be to assign an appropriate interface address to the connection. If you are using it to configure an interface, it can instead remove an address from the interface. It depends on the context of use to determine what ‘no particular address’ really does.

In the context of a route entry, it usually means the default route. That happens as a result more of the address mask, which selects the bits to compare. A mask of 0.0.0.0 selects no bits, so the comparison will always succeed. So when such a route is configured, there is always somewhere for packets to go (if configured with a valid destination).

In some cases, merely ‘0’ will also work and have the same effect. But this is not guaranteed. The 0.0.0.0 form is the standard way to say ‘no particular address’ (in IPv6 that is ::0 or just ::).

Source: What is the Meaning of the IP Address 0.0.0.0?

In 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. To give a special meaning to an otherwise invalid piece of data is an application of in-band signaling.

In the context of servers, 0.0.0.0 means 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 listens on 0.0.0.0, it will be reachable at both of those IPs (Note: This particular text is repeated from above as part of the overall answer).

In the context of routing, 0.0.0.0 usually means the default route, i.e. the route which leads to ‘the rest of’ the Internet instead of somewhere on the local network.

Uses Include:

  • 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 an 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 specify any IPv4-host at all. It is used in this way when specifying a default route.
  • A way to explicitly specify that the target is unavailable. Source: 127.0.0.1 – What Are its Uses and Why is it Important?
  • 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.]

In IPv6, the all-zeros-address is written as ::

Source: 0.0.0.0 [Wikipedia]

DHCP Discovery/Request

When a client boots up for the first time, it is said to be in the initializing state, and transmits a DHCPDISCOVER message on its local physical subnet over User Datagram Protocol (UDP) port 67 (BootP server). Since the client has no way of knowing the subnet to which it belongs, the DHCPDISCOVER is an all subnets broadcast (destination IP address of 255.255.255.255), with a source IP address of 0.0.0.0. The source IP address is 0.0.0.0 since the client does not have a configured IP address.

If a DHCP server exists on this local subnet and is configured and operating correctly, the DHCP server will hear the broadcast and respond with a DHCPOFFER message. If a DHCP server does not exist on the local subnet, there must be a DHCP/BootP Relay Agent on this local subnet to forward the DHCPDISCOVER message to a subnet that contains a DHCP server.

This relay agent can either be a dedicated host (Microsoft Windows Server, for example) or a router (a Cisco router configured with interface level IP helper statements, for example).

After the client receives a DHCPOFFER, it responds with a DHCPREQUEST message, indicating its intent to accept the parameters in the DHCPOFFER, and moves into the requesting state. The client may receive multiple DHCPOFFER messages, one from each DHCP server that received the original DHCPDISCOVER message. The client chooses one DHCPOFFER and responds to that DHCP server only, implicitly declining all other DHCPOFFER messages. The client identifies the selected server by populating the Server Identifier option field with the DHCP server’s IP address.

The DHCPREQUEST is also a broadcast, so all DHCP servers that sent a DHCPOFFER will see the DHCPREQUEST, and each will know whether its DHCPOFFER was accepted or declined. Any additional configuration options that the client requires will be included in the options field of the DHCPREQUEST message. Even though the client has been offered an IP address, it will send the DHCPREQUEST message with a source IP address of 0.0.0.0. At this time, the client has not yet received verification that it is clear to use the IP address.

Client-server conversation for a client obtaining a DHCP address where the client and DHCP server reside on same subnet:

Source: Understanding and Troubleshooting DHCP in Catalyst Switch or Enterprise Networks

Default Route

This document explains how to configure a default route or gateway of last resort. These IP commands are used:

  • ip default-gateway
  • ip default-network
  • ip route 0.0.0.0 0.0.0.0

IP Route 0.0.0.0 0.0.0.0

Creating a static route to the network 0.0.0.0 0.0.0.0 is another way to set the gateway of last resort on a router. As with the ip default-network command, using the static route to 0.0.0.0 is not dependent on any routing protocols. However, IP routing must be enabled on the router.

Note: IGRP does not understand a route to 0.0.0.0. Therefore, it cannot propagate default routes created using the ip route 0.0.0.0 0.0.0.0 command. Use the ip default-networkcommand to have IGRP propagate a default route.

Source: Configuring a Gateway of Last Resort Using IP Commands


Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

dhcp 过程的更多相关文章

  1. wireshark分析dhcp过程

    ---恢复内容开始--- DHCP DHCP(Dynamic Host Configuration Protocol)是一个用于主机动态获取IP地址的配置解 析,使用UDP报文传送,端口号为67何68 ...

  2. 思科获取DHCP过程

    主机如何获取DHCP的过程? 地址请求: 客户端发布一个DHCP请求信息,该信息会发给网内所有主机,非DHCP服务器会丢弃信息. 地址提供: DHCP服务端收到该信息后,会从地址池内挑选一个未被使用的 ...

  3. DHCP的原理和实现过程

    在DHCP过程中有两个对象DHCP客户端和DHCP服务端,而且DHCP在三层是通过可靠地TCP协议实现,DHCP服务运行在67和68端口. DHCP实现的简单过程,如图1所示, 图1 文字描述: 1. ...

  4. DHCP获取IP地址过程中捕获的报文—三级网络总结(二)

    上一篇文章主要说了一下知识点中的IP地址的考点,这一篇我打算说说DHCP获取IP地址过程中捕获的报文的这个考点,都是自己的理解,有错误欢迎指正. DHCP是应用层协议,UDP是传输层协议,IP是网络层 ...

  5. DHCP完整过程详解及Wireshark抓包分析

    DHCP,Dynamic Host Configuration Protocol,动态主机配置协议,简单来说就是主机获取IP地址的过程,属于应用层协议. DHCP采用UDP的68(客户端)和67(服务 ...

  6. DHCP的若干原理解释

    转自:http://blog.chinaunix.net/uid-22287947-id-1775641.html 搜罗了几种关于dhcp的原理和过程解释 DHCP(Dynamic Host Conf ...

  7. DHCP 工作原理

    DHCP 详解 DHCP 工作原理 一.什么是DHCP? DHCP,动态主机配置协议,前身是BOOTP协议,是一个局域网的网络协议,使用UDP协议工作,常用的2个端口:67(DHCP server), ...

  8. DHCP协议分析(Wireshark)

    一.说明 一是很多时候IP都是设置成通过dhcp动态获取的,但一直不太清楚dhcp的具体交互过程:二是加上前几天有同事问知不知道DHCP具体交互过程:三是这两天正好在分析协议.所以就顺道来看一下. 如 ...

  9. DHCP协议原理及其实现流程

    DHCP(Dynamic Host Configuration Protocol):动态主机配置协议 在常见的小型网络中(例如家庭网络和学生宿舍网),网络管理员都是采用手工分配IP地址的方法,而到了中 ...

随机推荐

  1. DoveCLL and Resistance(湖北省赛)

    题目 构造一个由串联和并联构成的纯电阻电路,使得该电路的等效电阻为p/q,其中(p,q) = 1.要求输出n,表示节点数,m表示电阻个数,m行每行ui,vi,wi,表示ui和vi之间要连上一个电阻为w ...

  2. vue之组件的使用(转载)

    在工程目录/src下的component文件夹下创建一个 firstcomponent.vue并写仿照 App.vue 的格式和前面学到的知识写一个组件. <template> <d ...

  3. css--css选择器,伪类

    前戏 前面我们说过CSS规则由选择器和声明组成,我们要给标签设置属性,那我们就要找到对应的标签,CSS选择器可以帮我们找到我们需要的标签 css选择器有: 标签选择器 类选择器 ID选择器 全局选择器 ...

  4. 文本三剑客之awk

    awk和流编辑器sed在工作原理和用法上有很多类似之处,它们都是检查输入数据中的行是否匹配指定的模式,如果匹配成功就对匹配的行执行相应的操作,重复这个过程直到所有的输入数据都被处理完,因此awk和se ...

  5. 自定义shell脚本

    当脚本需要加入固定的内容时就可以直接使用此文件 1.在用户的家目录下创建.vimrc文件(root用户就在root目录下创建,其他用户就在其他用户家目录下创建这个隐藏文件) 2. 将以下代码写入此文件 ...

  6. 开门人和关门人(结构体+sort)

    每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签 到.签离记录,请根据记录找出当天开门和关门的人.    Input 测试输入的第一行给出记录的总天数N ( > ...

  7. PhotoshopCS6

    download: http://www.playnext.cn/photoshop-cs6.html cracker: http://www.playnext.cn/adobe-cs6-crack. ...

  8. Python+selenium(操作隐藏元素)

    测试过程中,偶尔会碰到一些页面的隐藏元素,如下,是小编举的一个简单的例子: test.html <html> <head></head> <body> ...

  9. nmon分析与详解

    1.命令安装 1.查看liunx版本版本x86_64_14i 目录:cd /nmon/logs/ 版本x86_64_14i [root@localhost u06]# cd / [root@local ...

  10. spring boot学习01【搭建环境、创建第一个spring boot项目】

    1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ...