如何拒绝 OpenVPN 服务器推送的路由?

mba*_*off 35 networking routing openvpn

当我通过 Internet 建立到我们公司 OpenVPN 服务器的 OpenVPN 客户端连接时,它会推送几个静态路由。不幸的是,这些路由在我的本地网络环境中破坏了一些连接,因为它们与我自己的路由相冲突。我如何拒绝这些路线?

Cri*_*gie 43

时代在变,从 2017 年(OpenVPN 2.4)开始,这可以通过

pull-filter accept "route 192.168."
pull-filter ignore "route 172."
pull-filter accept "route 1"
pull-filter ignore "route "
Run Code Online (Sandbox Code Playgroud)

这(人为的示例)将允许学习以 192.168 开头的路由,忽略所有 172. 路由,允许其他路由到 1.anything,然后忽略所有其他路由。

要忽略,redirect-gateway您可以:

pull-filter ignore redirect-gateway
Run Code Online (Sandbox Code Playgroud)

这些命令会添加到您的客户端配置文件中。

同样,您可以使用关键字reject告诉 VPN 服务器它不被接受。不确定这个的用途。

最后,您也可以过滤其他配置选项。我用它来忽略提供的 DNS 服务器,因为 DNS 由本地服务器为我处理。

  • 要忽略 DNS 服务器,请使用 `pull-filterignore "dhcp-option DNS"` (4认同)
  • 请注意,这仅适用于 OpenVPN 2.4.x。 (3认同)

mba*_*off 29

经过对openvpn手册的广泛研究,我找到了我的问题的答案:

如果您不希望路线自动执行,而是由您自己的工具处理,请使用以下选项:

   --route-noexec
          Don't add or remove routes automatically.  Instead pass routes to --route-up script using environmental variables.
Run Code Online (Sandbox Code Playgroud)

如果您接受服务器推送的除路由之外的所有内容,请使用以下选项:

  --route-nopull
          When used with --client or --pull, accept options pushed by server EXCEPT for routes.
          When used on the client, this option effectively bars the server from adding routes to the client's routing table, however note that
          this option still allows the server to set the TCP/IP properties of the client's TUN/TAP interface.
Run Code Online (Sandbox Code Playgroud)

  • 仅供参考,您还可以在 .opvn 配置文件中使用 `route-nopull`:http://stackoverflow.com/questions/35698215/not-route-all-traffic-through-the-vpn-how-to-change-ovpn -文件/35700325#35700325 (3认同)