client.down 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # Copyright (c) 2005-2018 OpenVPN Inc
  3. # Licensed under the GPL version 2
  4. # First version by Jesse Adelman
  5. # someone at boldandbusted dink com
  6. # http://www.boldandbusted.com/
  7. # PURPOSE: This script automatically removes the /etc/resolv.conf entries previously
  8. # set by the companion script "client.up".
  9. # INSTALL NOTES:
  10. # Place this in /etc/openvpn/client.down
  11. # Then, add the following to your /etc/openvpn/<clientconfig>.conf:
  12. # client
  13. # up /etc/openvpn/client.up
  14. # down /etc/openvpn/client.down
  15. # Next, "chmod a+x /etc/openvpn/client.down"
  16. # USAGE NOTES:
  17. # Note that this script is best served with the companion "client.up"
  18. # script.
  19. # Tested under Debian lenny with OpenVPN 2.1_rc11
  20. # It should work with any UNIX with a POSIX sh, /etc/resolv.conf or resolvconf
  21. # This runs with the context of the OpenVPN UID/GID
  22. # at the time of execution. This generally means that
  23. # the client "up" script will run fine, but the "down" script
  24. # will require the use of the OpenVPN "down-root" plugin
  25. # which is in the plugins/ directory of the OpenVPN source tree
  26. # The config example above would have to be changed to:
  27. # client
  28. # up /etc/openvpn/client.up
  29. # plugin openvpn-plugin-down-root.so "/etc/openvpn/client.down"
  30. # A horrid work around, from a security perspective,
  31. # is to run OpenVPN as root. THIS IS NOT RECOMMENDED. You have
  32. # been WARNED.
  33. PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
  34. if type resolvconf >/dev/null 2>&1; then
  35. resolvconf -d "${dev}" -f
  36. elif [ -e /etc/resolv.conf.ovpnsave ] ; then
  37. # cp + rm rather than mv in case it's a symlink
  38. cp /etc/resolv.conf.ovpnsave /etc/resolv.conf
  39. rm -f /etc/resolv.conf.ovpnsave
  40. fi
  41. exit 0