Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Our Linux Ubuntu configuration does have a DNS server (Bind 9).
And resolv.conf has its


When using openvpn client on that Linux, the nameserver is not changed (by the VPN server) but I would like to set it - only during the VPN session - to another specific DNS server x.y.z.t, by changing the openvpn client config.

Then, when the openvpn session ends, nameserver should be back to

Is there a "clean" way (ie a line in the openvpn client config file) to do that?

(Note: The VPN server config cannot be changed)

share|improve this question
up vote 9 down vote accepted

After more googling, could find the answer - below if it can help someone.

  • install resolvconf which can save and restore the resolv.conf config file
  • add a script to be run by openvpn, in /usr/share/openvpn, named update-resolv-conf. The script determines what should be the new resolv.conf, and how to restore it (see link below)
  • add

these lines

  script-security 2
  up /usr/share/openvpn/update-resolv-conf
  down /usr/share/openvpn/update-resolv-conf

in the openvpn client config file.

Read on this wiki for more information.

share|improve this answer

Consider using route-up / route-down scripts on your client to alter your configuration on connection setup as you see fit. See the OpenVPN docs on details for how to set this up and which variables you might use in these scripts.

share|improve this answer
+1, interesting and useful. The resolvconf solution via up and down (above or below dep. on rating..) is however more to the point, and, imo, cleaner. – ringø Apr 23 '14 at 6:31
@ring0 I would advise using route-up instead of up to minimize race conditions. When the up script is executed, the connection is not yet set up and you have no chance to query the remote resolver you're setting. If you start the OpenVPN client in a situation where the connection setup would not complete, you are putting your resolver into a possibly non-functional state for a prolonged period of time. See the "Script Order of Execution" section in the OpenVPN man page for details. – the-wabbit Apr 23 '14 at 8:11
I did a few tests, and the up script is called right when "Initialization Sequence Completed" is reached, not before. Btw cannot find "route-down" in the man. – ringø Apr 23 '14 at 15:19

echo "nameserver=w.x.y.z" > /etc/resolv.conf
echo "nameserver=" >> /etc/resolv.conf

share|improve this answer
That seems inexact (think about the DNS search path, and the persistence of the VPN nameserver), but it's also unclear where you want him to put this. – Falcon Momot Aug 18 '14 at 6:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.