How does 0.0.0.0 binding happen in linux?

4

2

A ping to 0.0.0.0 responds from 127.0.0.1. However, if I shutdown the localhost loopback and keep another interface up with another ip, then ping 0.0.0.0 gives an error

$ping 0.0.0.0 connect: Invalid argument

Isn't 0.0.0.0 supposed to listen to all interfaces? So basically, how exactly does a 0.0.0.0 binding work from network perspective? how does ping 0.0.0.0 work only for loop-back and not for other interface?

  • Update I have read it elsewhere and got similar answer here (you cannot ping 0.0.0.0).
[anshup@s2 ~]$ ping 0.0.0.0 PING 0.0.0.0 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.010 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.009 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.009 ms
^C
--- 0.0.0.0 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2551ms
rtt min/avg/max/mdev =
0.009/0.009/0.010/0.002 ms

So what exactly is happening here if we cannot ping 0.0.0.0? and re-iterating the question, why does 0.0.0.0 response back only from loop-back and not any other interface on the host?

Anshu Prateek

Posted 2013-05-07T12:58:32.373

Reputation: 248

Answers

17

0.0.0.0/0 is not an address but an network Identity (used for routing, and means 'All Networks'). as such you cannot ping it. if you wanted to ping every system you would use 255.255.255.255. Every network has two special addresses, the Identity, and the Broadcast, usually at .0 and .255 respectively.

for instance on the network 192.168.5.0/24, the Identity = 192.168.5.0, and the broadcast = 192.168.5.255. the first host is 192.168.5.1, and the last is 192.168.5.254. note that no host may use the Identity or the Broadcast address as their own IP address.

the host default gateway is by definition the route you utilize to reach all unknown networks, so 0.0.0.0/0 is just a reference to All Networks.

Edit: The reason the loopback is responding is 'undefined' behavior not specified in RFC1700. Per the RFC, an address starting with 0 (when expressed in Decimal) is never allowed as a destination (only as the source of a broadcast packet), so the author of your network stack choose to have the loopback respond.

When I attempt to ping 0.0.0.0 from a Win7/powershell prompt, I simply get the message 'PING: transmit failed. General failure.' so this is clearly behavior specific to a given OS stack, or perhaps even driver-specific. If you provide your OS, we might be able to find more, but it would answer no meaningful questions since its implementation specific behavior not governed by networking standards. My guess is your OS is simply aliasing all invalid addresses as 127.x.y.z addresses.

Frank Thomas

Posted 2013-05-07T12:58:32.373

Reputation: 29 039

@frank: Thanks for answering. Updating the question to add more info in view of your answer. – Anshu Prateek – 2013-05-08T12:02:30.700

@Frank: Thanks for the update/edit answer. That helps. Am on fedora 17. Will check into its implementation. – Anshu Prateek – 2013-05-09T02:52:57.003

1

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.

Flukas88

Posted 2013-05-07T12:58:32.373

Reputation: 11