Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Parses DHCP options from openvpn to update resolv.conf
  4. # To use set as 'up' and 'down' script in your openvpn config file:
  5. # script-security 2
  6. # up /etc/openvpn/update-resolv-conf
  7. # down /etc/openvpn/update-resolv-conf
  8. # down-pre
  9.  
  10. [ "$script_type" ] || exit 0
  11. [ "$dev" ] || exit 0
  12.  
  13. split_into_parts()
  14. {
  15. part1="$1"
  16. part2="$2"
  17. part3="$3"
  18. }
  19.  
  20. case "$script_type" in
  21. up)
  22. NMSRVRS=""
  23. SRCHS=""
  24. for optionvarname in ${!foreign_option_*} ; do
  25. option="${!optionvarname}"
  26. split_into_parts $option
  27. if [ "$part1" = "dhcp-option" ] ; then
  28. if [ "$part2" = "DNS" ] ; then
  29. NMSRVRS="${NMSRVRS:+$NMSRVRS }$part3"
  30. elif [ "$part2" = "DOMAIN" ] ; then
  31. SRCHS="${SRCHS:+$SRCHS }$part3"
  32. fi
  33. fi
  34. done
  35. if [ -z "$NMSRVRS" ]; then
  36. exit 0
  37. fi
  38. mv /etc/resolv.conf /etc/resolv.conf.bak
  39. for NS in $NMSRVRS ; do
  40. echo "nameserver $NS" >> /etc/resolv.conf
  41. done
  42. for SEARCH in $SRCHS ; do
  43. echo "search $SEARCH" >> /etc/resolv.conf
  44. done
  45. ;;
  46. down)
  47. mv /etc/resolv.conf.bak /etc/resolv.conf
  48. ;;
  49. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement