3

I was recently very surprised to discover that 0.0.0.0 is a valid IP address and actually has a defined "meaning" and use.

IANA allocated 0.0.0.0/32 to mean "This host on this network" as defined by RFC 1122 section 3.2.1.3. While RFC 1122 states it must not be sent in an IP packet as a destination on the network, it does nothing to define how the address should be interpreted inside the host.

Except ... RFC 1122 names it "this host on this network" suggesting a very similar meaning to "localhost".

On Linux attempting to connect to 0.0.0.0 results in a connection to localhost (assuming something is listening). This seems in keeping with the RFC 1122 name. However I don't see it defined in standards (I'm not even sure which standard would cover it since it's internal to the OS).

So my question is: Is Linux's interpretation of connect() to 0.0.0.0 consistent with other operating systems? Are their any notable exceptions in well known OS Kernels (Windows / UNIXs / ...).

I'm particularly interested in this as a destination address because of the rise in DNS servers "incorrectly" using 0.0.0.0 as a black hole, resulting in spurious connections to localhost.

13
  • Have you read en.wikipedia.org/wiki/0.0.0.0 idk exactly how it works, but I'd call it a 'context-sensitive' address.
    – Tetsujin
    Nov 30, 2022 at 12:58
  • 1
    @Tetsujin doesn't seem to discuss actual OS behaviour. And I'm very cautious to believe Wikipedia on this because there is so much misinformation on this tiopic. Case in point the first sentence is not in keeping with either RFC 1122 or Linux's behaviour. the address 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non-applicable target. This seems untrue unless someone can find a standard defining it thus. Nov 30, 2022 at 13:02
  • 3
    It's a really interesting question that I hadn't thought about before. It looks like How does 0.0.0.0 binding happen in linux? covers what you are asking though (including the difference in behavior between OS's in the currently accepted answer). Does that answer it for you? Nov 30, 2022 at 13:08
  • 1
    @NotTheDr01ds network masks are important. Technically 0.0.0.0/32 is a network block (yes), but it a block containing exactly one address. RFC 1122 explicitly describes 0.0.0.0 but cryptically calls it {0,0}. Likewise the problem with the answer you link is it conflates with the IP block 0.0.0.0/0. In that context the text 0.0.0.0 is irrelevant. /0 means that literally 0 bits of that IP address are included in the CIDR block definition. So the answer horribly conflates two very different things that just like a little simiar. Nov 30, 2022 at 14:18
  • 2
    @PhilipCouling Hmm. That quote in my answer (which I got from Wikipedia) now has a Wikipedia reference pointing back to my answer ...
    – DavidPostill
    Nov 30, 2022 at 15:46

2 Answers 2

2

No, one OS that's easy to check is Windows which treats 0.0.0.0 as an invalid address for connection. (Windows in general is strict about address validity, e.g. you cannot use 240.0.0.0/4 on Windows either.)

(On the other hand, most BSDs are likely to handle this the way Linux does, as the Linux source code in fact notes that the Linux behavior is meant to mimic BSD.)

1
  • Easy to check if you happen to have a Windows box at your fingertips 😉. Many thanks for finding this is an exception. Nov 30, 2022 at 22:21
0

0.0.0.0 sees a few uses.

DHCP uses 0.0.0.0 as a source address for packets sent before the client has a proper IP address to use.

Posix defines the "INADDR_ANY" address as a wildcard for listening on "any local address". It doesn't explicitly define the value but it does say "The INADDR_ANY and INADDR_BROADCAST values are byte-order-neutral and thus their byte order is not specified.". In practice I've never heard of any system where this is anything other than 0.0.0.0 and I struggle to see what other value could possiblly be used while remaining endian neutral and avoiding the possibility of conflicting with a real address.

Connecting to 0.0.0.0 on the other hand is non-standard, Linux and BSD seem to support it. Windows does not.

Not the answer you're looking for? Browse other questions tagged or ask your own question.