windows OpenVPN:路由除本地网络之外的所有网络

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16302138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:28:43  来源:igfitidea点击:

OpenVPN: route all except local network

windowsproxyroutingopenvpn

提问by mixaill

So, I have a OpenVPN proxy and this configuration file:

所以,我有一个 OpenVPN 代理和这个配置文件:

dev tun0 
proto tcp 
remote 0.1.2.3 443 
client 
nobind 
tun-mtu 1500 
tun-mtu-extra 32 
ca ca.crt 
cert user.crt 
key user.key 
tls-client 
tls-auth ta.key 1 
auth MD5 
cipher BF-CBC 
ns-cert-type server 
comp-lzo yes 
auth-user-pass 
persist-key 
persist-tun 
verb 3 
route-method exe 
route-delay 2 
route-metric 512 
route 0.0.0.0 0.0.0.0 

How to route all traffic through OpenVPN except 192.168.x.x and 10.x.x.x?

如何通过 OpenVPN 路由除 192.168.xx 和 10.xxx 之外的所有流量?

采纳答案by CyberTech

The information you seek is here:

您要找的信息在这里:

http://openvpn.net/index.php/open-source/documentation/howto.html#redirect

http://openvpn.net/index.php/open-source/documentation/howto.html#redirect

This describes how to setup openvpn so that all traffic is routed thru the vpn -- the redirect-gateway command creates a static route to your gateway, deletes your default route, then adds a new default gateway that routes thru the vpn. See also

这描述了如何设置 openvpn 以便所有流量都通过 vpn 路由——redirect-gateway 命令创建到您的网关的静态路由,删除您的默认路由,然后添加一个通过 vpn 路由的新默认网关。也可以看看

The only steps you're missing from that is to add route to 192.168.x.x/etc which routes out your local interface. You can do this one of several ways, two of which are:

您缺少的唯一步骤是将路由添加到 192.168.xx/etc 路由出您的本地接口。您可以通过以下几种方式之一执行此操作,其中两种方式是:

  1. route network/IP [netmask] [gateway] [metric] (see the openvpn manual for more info) -- using this in openvpn config will have it set the routes for your rfc1918 addresses at vpn connect time

  2. Using your os route command, add a static route to the routing table to tell it where to route rfc1918 addresses to. "route -p ADD 10.1.1.0 MASK 255.255.255.0 192.168.1.8". The -p command makes the static route persistent across reboots... if it's a non-windows OS, then setting the routes is done via several ways, and making it persistent across reboots is also done in several different distro-specific ways, so just check google for "create static route on " and you'll find the answer there.

  1. 路由网络/IP [网络掩码] [网关] [度量标准](有关更多信息,请参阅 openvpn 手册)--在 openvpn 配置中使用它会在 vpn 连接时为您的 rfc1918 地址设置路由

  2. 使用您的 os route 命令,将静态路由添加到路由表中,以告诉它将 rfc1918 地址路由到何处。“路由 -p 添加 10.1.1.0 掩码 255.255.255.0 192.168.1.8”。-p 命令使静态路由在重新启动后保持不变......如果它是非 Windows 操作系统,则设置路由通过多种方式完成,并且在重新启动时保持持久性也可以通过几种不同的发行版特定方式完成,因此只需检查谷歌“创建静态路由”,你就会在那里找到答案。

Remember that more specific routing tables win over less specific, so adding a route for 192.168.x.x wins over a route to 0.0.0.0.

请记住,更具体的路由表胜过不太具体的路由表,因此添加 192.168.xx 的路由会胜过指向 0.0.0.0 的路由。