是否允许 OpenVPN 客户端推送其自己的 DNS 服务器,而不管 OpenVPN 服务器推送的 DNS?

是否允许 OpenVPN 客户端推送其自己的 DNS 服务器,而不管 OpenVPN 服务器推送的 DNS?

有一个在 Debian 上运行的 OpenVPN 服务器,它在服务器配置文件中推送 DNS:

推“dhcp-选项 DNS 8.8.8.8”

是否有一个选项允许用户在客户端更改 DNS 服务器?

问题就在这里,openvpn 服务器必须推送 DNS,否则许多 OpenVPN 客户端将无法打开网页,直到在系统的网络设置中手动设置 DNS 服务器。

我的目标是自动向技术不熟练的用户应用默认 DNS 服务器,同时也允许熟练的计算机用户设置自己的 DNS 服务器。

请注意,当 openvpn 服务器上的“推送“dhcp-option DNS 8.8.8.8””选项处于活动状态时,简单地更改 PC 上的 DNS 设置不会产生任何效果。无论本地 DNS 设置如何,服务器推送的 DNS 都会保留。

有任何想法吗?

OpenVPN 服务器配置:

# cat /etc/openvpn/openvpn.conf
server 10.186.35.0 255.255.255.0
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
ifconfig-pool-persist ipp.txt
#push "route 0.0.0.0 0.0.0.0"
#push "redirect-gateway"
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
keepalive 10 120
comp-lzo
user nobody
group users
persist-key
persist-tun
status openvpn-status.log
verb 3
script-security 3
auth-user-pass-verify /etc/openvpn/auth-chap via-env
client-cert-not-required
duplicate-cn
management 127.0.0.1 5119
script-security 3 system
username-as-common-name
client-connect /etc/openvpn/scripts/clientconnect.sh
client-disconnect /etc/openvpn/scripts/clientdisconnect.sh
log-append /var/log/openvpn.log
log /var/log/openvpn.log

更新:客户端操作系统是 Windows 和 Mac

答案1

从 2017 年 (OpenVPN 2.4) 开始,这已成为可能。将此行添加到您的客户端配置文件中:

pull-filter ignore "dhcp-option DNS"

它将忽略所有以引用文本开头的推送配置行。

选项按自上而下进行匹配,因此将使用第一个匹配项。如果符合您的需要,您可以使用此选项允许某些路由并拒绝其他路由。

这三个动作关键字是accept、、ignorereject。我还没有发现的用例reject

答案2

在官方OpenVPN 文档你可以找到:

[...]
--route-nopull
  When used with --client or --pull, accept options pushed by server EXCEPT for routes and 
  dhcp options like DNS servers.
  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.
[...]

不幸的是,除了你问的问题之外,这个有禁用重定向网关的副作用由您的配置提供,对于您的情况来说,这可能表示一个问题。

我建议的是一种完全不同的方法。

正如您明确提到的:“我的目标是自动向技术不熟练的用户应用默认 DNS 服务器,同时也允许熟练的计算机用户设置自己的 DNS 服务器。“看起来您确切地知道您想要为哪些用户提供 DNS 配置以及您不想为哪些用户提供这样的配置。

因此,您无需直接在主 OpenVpn 配置文件中推送配置(...并将此类配置提供给全部您的用户),您可以实现每个用户的配置。你可以这样做:

--client-config-dir dir
  Specify a directory dir for custom client config files. After a connecting client 
  has been authenticated, OpenVPN will look in this directory for a file having the 
  same name as the client's X509 common name. If a matching file exists, it will be
  opened and parsed for client-specific configuration options. If no matching file is
  found, OpenVPN will instead try to open and parse a default file called "DEFAULT", 
  which may be provided but is not required. Note that the configuration files must 
  be readable by the OpenVPN process after it has dropped it's root privileges.
  This file can specify a fixed IP address for a given client using --ifconfig-push, as 
  well as fixed subnets owned by the client using --iroute.
  One of the useful properties of this option is that it allows client configuration 
  files to be conveniently created, edited, or removed while the server is live, without 
  needing to restart the server.
  The following options are legal in a client-specific context: --push, --push-reset, 
  --iroute, --ifconfig-push, and --config.

因此,对于主要配置,你应该消除

  [**** to be removed from the main config***]
  push "dhcp-option DNS 8.8.8.8"
  push "dhcp-option DNS 8.8.4.4"

添加参考/etc/openvpn/用户配置目录(仅作为示例。请随意选择您喜欢的内容):

 [**** to be ADDED to the main config***]
 client-config-dir /etc/openvpn/userconf

然后,在该 userconf 目录中,为每个您想要提供此类 DNS 的用户创建一个文件,并在该文件中包含上面删除的两行。

显然,您可以自由地为每个用户微调 openvpn 配置,而不将自定义限制在上面两行。

最后,您可能对ccd 专用参数也是如此。

答案3

我的问题并不完全相同,但症状足够相似,以至于这个问题出现在搜索结果中,所以以防其他人因为同样的原因来到这里:

我在用着隧道图,适用于 Mac OS 的 OpenVPN GUI。我的 OpenVPN 服务器未设置为推送任何 DHCP 或 DNS 选项,但客户端仍在使用 VPN 上的 DNS 服务器,而不是我希望它使用的本地非 VPN DNS 服务器。

解决方案是进入 Tunnelblick 的配置 → 设置选项卡并更改设置 DNS/WINS不设置名称服务器

答案4

感谢@aldaviva,它在我的 macOS 10.11 上运行。

附上我的截图。

在此处输入图片描述

相关内容