I am working on a distributed application written in Node.js, where the public-facing server receives messages from the client over HTTP from time to time. On receipt, the messages are turned into the following JSON structure:
{
"message": {
// The actual message's content
},
"metadata": {
"client": {
"ip": "192.168.0.1",
"user": {
"token": {
"sub": "jane.doe@example.com"
}
}
}
}
}
As every connection is authenticated using OpenID Connect, I add the token sent by the client to the metadata section, as well as the IP address of the client that sent the message. So far, this works great.
Now, one of the non-public-facing servers is also able to send messages, but it doesn't go over the HTTP wire for that. Instead, it sends a message via a message queue (in my case RabbitMQ, but that isn't of relevance here). The public-facing server uses this queue as a second incoming channel for messages.
I would like the messages to have the same structure, whether they have been received via HTTP from the client or via the queue from an internal server. The internal server has a token, so this is not a problem. And of course it could use its own IP address as source, but that doesn't make too much sense.
What I would like to achieve is to provide an IP address which is formally correct, but basically says I am a placeholder, do not take me for real.
I have seen that in IPv6 there is the address ::
from address block ::/128
, which Wikipedia calls unspecified address
. Actually, this pretty much sounds like what I am looking for, but I don't need it as IPv6, but as IPv4.
Now the question is: What is the equivalent of this in IPv4? Is it 0.0.0.0
? Am I fine to use this address for my purpose, or does this have a semantically different meaning in networking?
I think it is totally fine to use the IPv4 address 0.0.0.0
for this purpose.
The IANA reservation for the block 0.0.0.0/8
cites RFC 1122 with the description "This host on this network," which matches nicely the use in your application.
Additionally, the address 0.0.0.0
has various similar uses, e.g. as a source address in the DHCP protocol by hosts not having an address yet, or as a wildcard address for a server process, meaning "run on all local IPv4 source addresses."
A more detailed answer can be found to the question "What's the difference between 127.0.0.1 and 0.0.0.0?" on superuser.