我有一台连接到 VPN 的 Ubuntu 计算机,其 IP 地址为。我想通过 VPN172.16.1.250
隧道传输 的所有请求,但不想做其他事情。如果我尝试使用,我会收到错误消息:172.16.1.*
sudo route -net add 172.16.1.0/24 dev ppp0
netmask 00000fff doesn't make sense with host route
但是,只需为该子网上的一个地址添加一条路由即可。正确的做法是什么?
答案1
您已将参数交换过来,正确的语法是:sudo route add -net 172.16.1.0/24 dev ppp0
答案2
我遇到这个问题是因为我误用-n
了-net
。
这有效:
sudo route add -net 172.19.0.0/16 dev ppp0
这不工作:
$ sudo route add -n 172.19.0.0/16 dev ppp0
route: netmask 0000ffff doesn't make sense with host route
Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If]
inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M]
[netmask N] [mss Mss] [window W] [irtt I]
[mod] [dyn] [reinstate] [[dev] If]
inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject
inet_route [-FC] flush NOT supported
man route
状态:
-n show numerical addresses instead of trying to determine symbolic host names. This is useful if you are trying to determine why the route to
your nameserver has vanished.
...
-net the target is a network.