有一个运行在Debian上的OpenVPN服务器,它会在服务器configuration文件中推送一个DNS:
推“dhcp-option DNS 8.8.8.8”
是否有允许用户更改客户端上的DNS服务器的选项?
这里有个问题,openvpn服务器必须推送一个DNS,否则许多OpenVPN客户端将无法打开网页,直到在系统的networking设置中手动设置DNS服务器。
我的目标是自动将默认的DNS服务器应用于技术不熟练的用户,同时也允许熟练的计算机用户设置自己的DNS服务器。
请注意,在openvpn服务器上激活“push”dhcp-option DNS 8.8.8.8“”选项时,只需更改PC上的DNS设置,什么也不做。 无论本地DNS设置如何,服务器推送的DNS都将保持不变。
有任何想法吗?
OpenVPN服务器configuration:
# 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
截至2017年,这现在是可能的。
添加一行到你的客户端configuration文件
拉filter忽略“dhcp-option DNS”
它将忽略所有以引用文本开头的推送configuration行。
选项自上而下匹配,所以使用第一个匹配。 如果符合您的需求,您可以使用这个来允许一些路线并拒绝其他路线。
三个动作关键字是accept ignore reject 。 我还没有发现拒绝用例。
在官方的OpenVPN文档中,您可以find:
[...] --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. [...]
不幸的是,除了你所要求的之外,这也有禁用你的configuration提供的redirect网关的副作用 ,这可能代表一个问题,你的情况。
我build议的是一个完全不同的方法。
正如你明确提到的那样:“ 我的目标是自动将默认DNS服务器应用于技术不熟练的用户,同时也允许熟练的计算机用户设置自己的DNS服务器。 ”看起来您确切地知道您要提供哪些用户一个DNSconfiguration和你不想提供这样的configuration的用户。
因此,而不是直接在主OpenVpnconfiguration文件中推送你的configuration(…,因此,提供这样的configuration给你的所有用户),你可以实现每个用户的configuration 。 你可以这样做:
--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.
所以,至于主configuration,你应该删除 :
[**** 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 / userconf目录的引用(作为例子,随意select你喜欢的任何东西):
[**** to be ADDED to the main config***] client-config-dir /etc/openvpn/userconf
然后,在这样的userconf目录下,为每个你想提供这样的DNS的用户创build一个文件,包括在这个文件中删除了上面的两行。
显然你可以自由地为每个用户调整openvpnconfiguration,而不是将自定义限制在上面的两行。
作为最后一点,你可能对ccd-exclusive参数感兴趣。
我的问题并不完全一样,但是症状足够类似于这个问题出现在search结果中,所以如果其他人因为相同的原因而在这里结束,
我正在使用Tunnelblick ,一个适用于Mac OS的OpenVPN GUI。 我的OpenVPN服务器没有设置为推送任何DHCP或DNS选项,但客户端仍然使用VPN服务器上的DNS服务器,而不是本地非VPN DNS服务器,我希望它使用。
解决scheme是进入Tunnelblick的configuration→设置选项卡,并更改设置DNS / WINS 不要设置名称服务器 。