Solving DNS problems with OpenVPN on Ubuntu box
I want to share some experiences working with VPN from Ubuntu. I had some trouble using OpenVPN as after connecting I couldn’t access any resource referenced by a domain name.
I couldn’t find any solution to this problem but finally after trying a few things out, I have come out with a solution I want to share below.
Assuming you have OpenVPN installed and working ‘.ovpn’ configuration file (but without proper DNS resolving) follow the steps below:
1. Install resolveconf
sudo apt-get install resolvconf
2. Link your auto-generated resolve.conf to existing ‘/etc/resolve.conf’
cd /etc
#backup your original resolve.conf just in case
cp resolv.con resolv.conf.orig
ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
#backup your original resolve.conf just in case
cp resolv.con resolv.conf.orig
ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
3. Add the following lines to the bottom of your ‘.ovpn’ configuration file:
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
4. Run openvpn with the following flags (as root):
openvpn --script-security 2 --config youropenvpnconfig.ovpn
That should do it.
Enjoy
thanks a lot! this worked flawless for ubuntu Meerkat.
Worked flawlessly for me on Ubuntu Desktop 11.10 x32
It really works. Thanks a lot.
Just perfect! you are the man!
You sir are a lifesaver. Thank you very much with all my heart.
Really helped me out, thanks!
This worked perfectly for me. Thank you.
There is a typo in step 2:-
[cp resolv.con resolv.conf.orig] => [cp resolv.CONF resolv.conf.orig]
Worked perfectly. Thank you!
However, I didn’t do the file linking step (there was no /etc/resolvconf/run/resolv.conf file on my system). It nevertheless worked.
Dear Grajek,
First of all i don’t know anything about ubentu. 🙂 I am setting up servers for my start up company. I have made OpenVPN and other servers working fine. Only issue I have is the DNS for the private IPs are not resolving to the clients.
I have seen your tip “Solving DNS issue with OpenVPN” . I am not able to use your comments as as I am getting the following error while trying to execute.
“root@openvpnas2:/etc# cp resolv.CONF resolv.conf.orig
cp: cannot stat ‘resolv.CONF’: No such file or directory
”
”
root@openvpnas2:/etc# ln -s /etc/resolvconf/run/resolv.conf /etc/resolv.conf
ln: failed to create symbolic link ‘/etc/resolv.conf’: File exists
”
I need your help to solve this issue. Please help me. I can set up a quick webex call with you to share my screen and so you can help me to fix this issue. Have a nice day.
Regards,
Muthu
from India
One more think, Your contact form is not working. I got error while trying,,
No exist /etc/resolvconf/run/resolv.conf
Doesn’t work for me. Internet also stopped working after using this.
This tutorial is little bit outdated for newer OS.
On ubuntu 14.04LTS you need to link resolve.conf to different directory:
sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
Everything else works like a charm! Thanks
Thanks a lot, man! This worked perfectly, except I had dnsmasq installed because it was recommended on some other blog/forum. It was messing up the DNS resolution like it works as soon as OpenVPN is up, but when you browse those hosts after a few seconds, it won’t resolve again.
So if you dnsmasq installed, removing it might help you like it did for me.