大网数据广告活动
服务器运维问答

What is the difference between 0.0.0.0/0 and 0.0.0.0/1?

· 52CE 我爱测

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 ?

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-05-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。