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 10.3.1.30 pointopoint 10.3.1.29 mtu 1500
Thu May 21 00:50:39 2009 /etc/openvpn/update-resolv-conf tun0 1500 1542 10.3.1.30 10.3.1.29 init
dhcp-option DNS 10.2.2.10
dhcp-option WINS 10.2.2.14
...
...
Thu May 21 00:50:39 2009 Initialization Sequence Completed
...