1

Why does 0.0.0.0 resolve to the loopback device?

$ curl --verbose 0.0.0.0
* Rebuilt URL to: 0.0.0.0/
* Hostname was NOT found in DNS cache
*   Trying 0.0.0.0...
* Connected to 0.0.0.0 (127.0.0.1) port 80 (#0)
Daniel
  • 121
  • 5

1 Answers1

3

It follows from an RFC requirement. RFC 5735 says:

  1. Global and Other Specialized Address Blocks

0.0.0.0/8 - Addresses in this block refer to source hosts on "this" network. Address 0.0.0.0/32 may be used as a source address for this host on this network; other addresses within 0.0.0.0/8 may be used to refer to specified hosts on this network

That given, the only rational thing to do with 0.0.0.0 as a destination is to treat it likewise. You can't route it anywhere else, because return packets would violate the RFC; you can't say it's invalid, because it's not when used as a source; the only sane thing to do with it when used as a destination is map it to localhost as well.

One of my old colleagues used to use telnet 0 22 as a real timesaver for telnet localhost 22.

MadHatter
  • 79,770
  • 20
  • 184
  • 232