3 # Copyright (c) 2005 by OpenVPN Solutions LLC
4 # Licensed under the GPL version 2
6 # First version by Jesse Adelman
7 # someone at boldandbusted dink com
8 # http://www.boldandbusted.com/
10 # PURPOSE: This script automatically removes the /etc/resolv.conf entries previously
11 # set by the companion script "client.up".
14 # Place this in /etc/openvpn/client.down
15 # Then, add the following to your /etc/openvpn/<clientconfig>.conf:
18 # up /etc/openvpn/client.up
19 # down /etc/openvpn/client.down
20 # Next, "chmod a+x /etc/openvpn/client.down"
23 # Note that this script is best served with the companion "client.up"
26 # Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0
27 # It should work with any GNU/Linux with /etc/resolv.conf
29 # This runs with the context of the OpenVPN UID/GID
30 # at the time of execution. This generally means that
31 # the client "up" script will run fine, but the "down" script
32 # will require the use of the OpenVPN "down-root" plugin
33 # which is in the plugins/ directory of the OpenVPN source tree
35 # A horrid work around, from a security perspective,
36 # is to run OpenVPN as root. THIS IS NOT RECOMMENDED. You have
47 # Convert ENVs to an array
49 while fopt
=foreign_option_
$i; [ -n "${!fopt}" ]; do
53 *DOMAIN
* ) domain
=`echo ${opt[i-1]} | \
54 sed -e 's/dhcp-option DOMAIN //g'` ;;
55 *DNS
* ) dns
[j-1
]=`echo ${opt[i-1]} | \
56 sed -e 's/dhcp-option DNS //g'`
65 if [ -n "${dns[*]}" ]; then
66 for i
in "${dns[@]}"; do
67 sed -i -e "/nameserver ${i}/D" /etc
/resolv.conf || die
71 if [ -n "${domain}" ]; then
72 sed -i -e "/search ${domain}/D" /etc
/resolv.conf || die