允许 OpenVPN 客户端推送它自己的 DNS 服务器,而不管 OpenVPN 服务器的推送 dns 吗?

Dim*_*imi 11 domain-name-system linux vpn openvpn linux-networking

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

推送“dhcp-option 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
Run Code Online (Sandbox Code Playgroud)

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

Cri*_*gie 21

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

pull-filter ignore "dhcp-option DNS"
Run Code Online (Sandbox Code Playgroud)

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

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

这三个动作关键字acceptignorereject。我还没有发现reject.


Dam*_*lli 4

在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.
[...]
Run Code Online (Sandbox Code Playgroud)

不幸的是,除了您所要求的之外,这还会产生禁用您的配置提供的重定向网关的副作用,这对于您的情况来说可能是一个问题。

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

正如您明确提到的:“我的目标是自动将默认的 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.
Run Code Online (Sandbox Code Playgroud)

因此,对于主要配置,您应该删除

  [**** to be removed from the main config***]
  push "dhcp-option DNS 8.8.8.8"
  push "dhcp-option DNS 8.8.4.4"
Run Code Online (Sandbox Code Playgroud)

添加对/etc/openvpn/userconf目录的引用(作为示例。随意选择您喜欢的目录):

 [**** to be ADDED to the main config***]
 client-config-dir /etc/openvpn/userconf
Run Code Online (Sandbox Code Playgroud)

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

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

最后一点,您可能也对ccd-exclusive参数感兴趣。