Linux使用openvpn时不能自动配置dns问题

一、问题描述

Manjaro gnome自带openvpn命令,sudo openvpn uat.ovpn连接,windows平台下连接正常,内网域名可解析,使用linux平台,dns服务失效。

二、问题排查

1. 定位日志

1
Sun Nov 17 12:10:11 2019 PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 192.168.1.253,dhcp-option DNS 111.111.0.20,route-gateway 10.8.0.1,topology subnet,ping 10,ping-restart 120,ifconfig 10.8.0.10 255.255.255.0,peer-id 0,cipher AES-256-GCM'
2
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: timers and/or timeouts modified
3
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: --ifconfig/up options modified
4
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: route options modified
5
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: route-related options modified
6
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
7
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: peer-id set
8
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: adjusting link_mtu to 1624
9
Sun Nov 17 12:10:11 2019 OPTIONS IMPORT: data channel crypto options modified

dns地址已经探测到,但非win32平台自动配置失败

2. 手动配置/etc/resolv.conf,添加nameserver就可以了到第一个就可以了😒

emmm…

有没有自动配置方案呢?

二、解决方案

1. 下载移动重命名脚本/etc/openvpn/update-resolv-conf.sh

1
git clone http://www.github.com/masterkorp/openvpn-update-resolv-conf

2. 修改配置uat.ovpn文件,在文件末尾追加内容

1
script-security 2
2
up /etc/openvpn/update-resolv-conf.sh
3
down /etc/openvpn/update-resolv-conf.sh

3. 安装openresolv

1
# yum、apt-get、yay均可

4. 启动openvpn客户端

1
sudo openvpn /etc/openvpn/client/uat.ovpn
2
# 输入root密码及私钥后即可连接

5. 浏览器测试dns效果吧