4

I am using OpenVPN 2.3.11 i686-pc-linux-gnu to connect to a remote VPN server.

I would like to connect to the VPN server, load the DNS nameservers from the VPN server.

Once disconnecting from the VPN server, the DNS settings should be reverted to to the original one.

Currently I am able to connect and get the DNS settings from the OpenVPN server so I can resolve names over the VPN's name servers. However, upon disconnecting from VPN, the original DNS servers which I get from local DHCP server are not being set.

I am using resolvconf and openresolv, and I have added to the standard OpenVPN config file config.ovpn the following entries:

...
up /etc/openvpn/update-resolv-conf.sh
down /etc/openvpn/update-resolv-conf.sh
...

When I start openvpn, I am able to receive the proper DNS servers, and /etc/resolv.conf file gets updated where A.A.A.A and B.B.B.B are the nameservers from openvpn tunnel:

 cat /etc/resolv.conf
 # Generated by resolvconf    
 nameserver A.A.A.A                                                  
 nameserver B.B.B.B

Now when I disconnect openvpn (CTRL-C), and attempt to restart networking services, the /etc/resolv.conf does not update to my original DNS settings. I have tried the following commands in different order but I am unable to revert /etc/resolv.conf to my original DHCP settings but without any success:

service networking restart
dhclient -r eth0
dhclient eth0

Any ideas on how to resolve this will be greatly appreciated.

PS: As a workaround I am rewriting /etc/resolv.conf file with original DNS server which is not elegant and does not seem like the write solution.

migrated from stackoverflow.com Nov 26 '16 at 21:19

This question came from our site for professional and enthusiast programmers.

  • Thanks kaylum.. it has moved to Unix/Linux Stackexchange now. – John Nov 26 '16 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.