OpenVPN on Ubuntu / resolvconf

First, install openvpn and resolvconf which in turn will be used by openvpn client in order to maintain /etc/resolv.conf and put proper nameservers into it.

# apt-get install openvpn resolvconf

Now edit the openvpn client.conf and add the following two lines:

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

Now start/invoke openvpn client using ‘script-security 2’ parameter, which will enable openvpn to execute external scripts upon connection:

# sudo openvpn --config path/to/client.conf --script-security 2 

Example output:

Thu May 21 00:50:39 2009 /sbin/ifconfig tun0 pointopoint mtu 1500
Thu May 21 00:50:39 2009 /etc/openvpn/update-resolv-conf tun0 1500 1542 init
dhcp-option DNS
dhcp-option WINS
Thu May 21 00:50:39 2009 Initialization Sequence Completed