Openvpn push DNS to linux client -笔记

如题,OPENVPN SERVER 只能通过push语句,将DNS推送给windows 客户端,但是面对linux确无能为力,所以就找方法解决之。

一、客户端下创建clientup.sh 及clientdown.sh(目录随意)

clientup.sh内容

#! /bin/bash

dns=dns
for opt in ${!foreign_option_*}
do
   eval "dns=\${$opt#dhcp-option DNS }"
   if [ "$dns" != "dns" ]
       then
          echo ";; created by openvpn --up ${0} " >/tmp/resolv.conf
          echo "nameserver 2001:4860:4860::8888">>/tmp/resolv.conf#我自己添加的,用来添加谷歌ipv6 dns
          grep search /etc/resolv.conf >>/tmp/resolv.conf
          echo "nameserver $dns" >>/tmp/resolv.conf
          if [[ ! -e resolv.conf ]]
          then
                mv /etc/resolv.conf ./resolv.conf
          fi
          mv -f /tmp/resolv.conf /etc 
          exit 0
       fi
done


clientdown.sh内容如下

#! /bin/bash

mv -f resolv.conf /etc

第二步:给clientup.sh clientdown.sh赋予可执行权限

sudo chmod 777 client*.sh

第三步:编辑client配置文件

添加三行

script-security 2
up /etc/openvpn/clientup.sh
down /etc/openvpn/clientdown.sh

分享到:更多 ()