Linux 系统连接 OpenVPN 无法获取推送 DNS 服务器的解决

resolvconf 

话说上周我们安装好了 OpenVPN,并且也启用了 MySQL 验证用户名和密码,结果没用几天又遇到问题了。。。还是 @cnkang 同学,反映在 Android 手机上连接成功后,没有收到服务器端推送过来的 Google DNS。

因为我实在懒得和 Android 较劲,于是在一台 Ubuntu 10.04 Desktop 机器上安装了 OpenVPN 试验,结果果然如此,完全没有理会服务器

push "dhcp-option DNS 8.8.8.8"

这条配置。还是 Google 后找到了答案。

原来 Linux 系统确实有这个问题,OpenVPN 也提供了现成的解决方案,那就是 /etc/openvpn/update-resolv-conf 这个脚本。在客户端配置文件 client.conf 后面加上如下三行:

script-security 2

up ./update-resolv-conf
down ./update-resolv-conf

这样在连接成功后,脚本会自动修改 /etc/resolv.conf ,将 OpenVPN 服务器推送过来的 DNS 服务器地址填入。断开连接后,又会自动清空 /etc/resolv.conf。如果你没有别的程序要修改 /etc/resolv.conf 的话,用这个脚本还是很方便的。

注意使用前需要检查下系统里面有没有 resolvconf 这个软件包,没有的话编译或者 APT 装一个就行了。还要注意 update-resolv-conf 有没有执行权限,没有的话 chmod +x update-resolv-conf 搞一下。另外我这里默认 update-resolv-conf 脚本和配置文件处于同一目录,不是这样的话请自己添加完整路径。

@cnkang 等同学重新下载我的 OpenVPN 配置文件包,里面已经包含了 update-resolv-conf 脚本,在 Linux 下用的话只需要将 conf 文件调用脚本的三行取消注释就可以了。

This entry was posted in 我的慵懒生活, 电脑相关 and tagged , , , , , . Bookmark the permalink.

3 Responses to Linux 系统连接 OpenVPN 无法获取推送 DNS 服务器的解决

  1. Pingback: Tweets that mention Linux 系统连接 OpenVPN 无法获取推送 DNS 服务器的解决 | gkp's post -- Topsy.com

  2. musiXboy says:

    脑残的android这样设置都不行。。。

  3. 任平生 says:

    script-security 2 system
    route-up “setprop net.dns1 8.8.8.8”

Leave a Reply

Your email address will not be published.