Set up openvpn to use private VPN service dns server on connect

I just made the update (Debian Strech) , and i will make some tests and some reading on how exaclty i can use openresolv. i wi’ll give it a try…

as @sam_nazarko said about the update,

but after first test its all the same , i have in open ovpn files the lines,

script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

i have installed resolvconf via sudo apt-get install resolvconf

I haven’t changed anything in update-resolv-conf.

I connect and resolv.conf is filled with my vpn’s dns servers, but when i disconnect my resolv.conf is empty and i have no internet connectivity, until i reboot.

last night i found 2 solutions that work somehow…

I tell you from now i am a complete noob when it comes to linux…only last month that i had a goal to setup open vpn with no dns leaks firts of all to learn and second as a personal goal, learnd how to connect through ssh.

Maybe the solutions are weird or funny, but i would like your opinion…

First one, is adding some lines in update-resolv-conf based in logic that resolv.conf is a symbolic link to /etc/resolvconf/run/resolv.conf and thats why

doesn’t help me, because it breaks the link, and after its just a file that copys it self on and on…

I tried:

for NS in $NMSRVRS ; do
R="${R}nameserver $NS
"
done
cp /etc/resolv.conf /etc/resolv.conf.default ← i just make a copy that i will use later that contanes some default dns so i can connect to the internet or reconnect to vpn.
echo -n “$R” | /sbin/resolvconf -a “${dev}.openvpn”
cp -P /etc/resolv.conf.simlink /etc/resolv.conf ← a copy as symlink to see /etc/resolvconf/run/resolv.conf that updates with vpn’s dns

;;
down)
/sbin/resolvconf -d “${dev}.openvpn”
cp -P /etc/resolv.conf /etc/resolv.conf.simlink ← i replace the simple file with symlink file that targets /etc/resolvconf/run/resolv.conf with updates in every connect with vpn’s dns
mv -f /etc/resolv.conf.default /etc/resolv.conf <–and because /etc/resolvconf/run/resolv.conf is always empty i replace it with the backup file so i can have dns to connect
;;
esac

Its like a big loop, it works good but it has a disadvantage , you cannot change dns from My OSMC(dhcp or static) if you want to change dns in resolv.conf you have to ssh → sudo nano it.

And the other is something i found that regenerates resolv.conf after being empty, without reboot system.

is by adding

systemctl restart connman

in

update-resolv-conf , script

done

echo -n “$R” | /sbin/resolvconf -a “${dev}.openvpn”

;;
down)
/sbin/resolvconf -d “${dev}.openvpn”
systemctl restart connman
;;
esac

after down command, so connman restarts and regenarates my resolv.conf with systems dns.

is it safe , wise to restart connman that way or it causes a problem that i haven’t meet until now , or later? does it affect me?

You have something else to suggest now with the changes that update brought?

Maybe stupid ways but i would like some feedback - opinion from someone…

Thanks.