In the history, I mostly used 0.0.0.0/0
for "match every IP address". Recently, I saw a 0.0.0.0/1
subnet filter.
What is the difference between 0.0.0.0/0
and 0.0.0.0/1
and what's the practical use of 0.0.0.0/1
?
In the history, I mostly used 0.0.0.0/0
for "match every IP address". Recently, I saw a 0.0.0.0/1
subnet filter.
What is the difference between 0.0.0.0/0
and 0.0.0.0/1
and what's the practical use of 0.0.0.0/1
?
The 0.0.0.0/0
matches every IP address, whereas 0.0.0.0/1
only matches half of them (0.0.0.0-127.255.255.255
) and requires 128.0.0.0/1
as its pair to match the rest (128.0.0.0-255.255.255.255
).
In basic routing, the smallest available subnet containing the IP address takes precedence. This rule comes from RFC 4632, 5.1. It is typical there will be overlapping networks as, for example, 192.168.1.0/24
is part of 192.168.0.0/16
, which is – just like any IP address – part of 0.0.0.0/0
.
Therefore, by splitting the 0.0.0.0/0
into smaller chunks one can constrain the interface to take precedence over any other interface that has default route 0.0.0.0/0
, without playing with metric values. This is a common technique with VPNs that would not want data to bypass the tunnel. The same logic is the reason you could still use resources from your local subnet (e.g., /24
) while the VPN is on – if no other methods are used to enforce everything gets tunneled.
Likewise, the entire IPv4 address space could be divided into even smaller subnets, e.g. in four chunks:
0.0.0.0/2
(0.0.0.0-63.255.255.255
)64.0.0.0/2
(64.0.0.0-127.255.255.255
)128.0.0.0/2
(128.0.0.0-191.255.255.255
)192.0.0.0/2
(192.0.0.0-255.255.255.255
)Or eight with 0.0.0.0/3
, 32.0.0.0/3
, 64.0.0.0/3
, 96.0.0.0/3
, 128.0.0.0/3
, 160.0.0.0/3
, 192.0.0.0/3
& 224.0.0.0/3
, etc., etc.
What is the difference between 0.0.0.0/0 and 0.0.0.0/1
0.0.0.0/0 matches all IPv4 addresses.
0.0.0.0/1 matches the IP range from 0.0.0.0 to 127.255.255.255
IP routing uses a "longest prefix match" rule, so if there are routes in the routing table for both 0.0.0.0/0 and 0.0.0.0/1 and both match the destination then the route for 0.0.0.0/1 will be preferred.
what's the practical use of 0.0.0.0/1?
Openvpn uses it as a trick to override the default route without modifying or removing the existing one. It would not surprise me if other VPN software does too but I haven't seen it.
Removing the exiting default route when the VPN connects and re-adding it when the VPN disconnects has the potential for race conditions with other network control or administration software. It is also likely to leave the system without network access if the VPN client crashes.
It is possible to override a route by using a lower metric, however that doesn't work if the existing route already has the lowest possible metric.
So openvpn's "redirect-gateway" feature has an option called "def1". When this option is enabled it will create routes for 0.0.0.0/1 and 128.0.0.0/1 rather than creating a single route for 0.0.0.0/0. These routes will be preferred over the existing route for 0.0.0.0/0 thanks to the "longest prefix match" rule, so there is no need to remove the existing default route.
The literal meaning: that is just two different networks expressed in CIDR notation.
The practical use of 0.0.0.0/1
: Splitting the IPv4 space by the first bit does not produce particularly meaningful subnets today, outside of history lessons.
It just happens to be the smallest split possible. So spelling out two halves is the shortest method to express "all of IPv4" where 0/0
is not a valid input. A script would not let me configure network topology for which it had not been designed, so I used 0/1
as a workaround (in routing context, prefix length determines preference).
Besides typos, that is the only instance where I ever encountered it.