问题原文
原帖链接 · Arakis · CC BY-SA 4.0
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?
社区高分解答
原帖链接 · Peter Green · CC BY-SA 4.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
