Solving DNS problems with OpenVPN on Ubuntu box

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

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

4. Run openvpn with the following flags (as root):

openvpn --script-security 2 --config youropenvpnconfig.ovpn

That should do it.

15 responses on “Solving DNS problems with OpenVPN on Ubuntu box

  1. Anon June 25, 2011 at 1:31 pm

    thanks a lot! this worked flawless for ubuntu Meerkat.

  2. Anon January 31, 2012 at 8:50 pm

    Worked flawlessly for me on Ubuntu Desktop 11.10 x32

  3. wojtas March 21, 2012 at 7:58 pm

    It really works. Thanks a lot.

  4. dani September 13, 2012 at 6:09 pm

    Just perfect! you are the man!

  5. Satrapes December 21, 2013 at 2:28 am

    You sir are a lifesaver. Thank you very much with all my heart.

  6. MrSavage January 28, 2015 at 2:20 am

    Really helped me out, thanks!

  7. Andrew Dick March 6, 2015 at 1:24 pm

    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]

  8. Sarath May 13, 2015 at 1:27 am

    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.

  9. Muthu May 29, 2015 at 10:19 pm

    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.

    from India

  10. Muthu May 29, 2015 at 10:21 pm

    One more think, Your contact form is not working. I got error while trying,,

  11. anon August 10, 2015 at 2:43 pm

    No exist /etc/resolvconf/run/resolv.conf

  12. ritesh December 29, 2016 at 9:03 am

    Doesn’t work for me. Internet also stopped working after using this.

  13. artur January 11, 2017 at 12:25 pm

    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

  14. Gowri Sankar November 7, 2017 at 9:11 pm

    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.

Leave a Reply

Related Posts

    No Releated Posts