Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Parses DHCP options from openvpn to update resolv.conf
- # To use set as 'up' and 'down' script in your openvpn config file:
- # script-security 2
- # up /etc/openvpn/update-resolv-conf
- # down /etc/openvpn/update-resolv-conf
- # down-pre
- [ "$script_type" ] || exit 0
- [ "$dev" ] || exit 0
- split_into_parts()
- {
- part1="$1"
- part2="$2"
- part3="$3"
- }
- case "$script_type" in
- up)
- NMSRVRS=""
- SRCHS=""
- for optionvarname in ${!foreign_option_*} ; do
- option="${!optionvarname}"
- split_into_parts $option
- if [ "$part1" = "dhcp-option" ] ; then
- if [ "$part2" = "DNS" ] ; then
- NMSRVRS="${NMSRVRS:+$NMSRVRS }$part3"
- elif [ "$part2" = "DOMAIN" ] ; then
- SRCHS="${SRCHS:+$SRCHS }$part3"
- fi
- fi
- done
- if [ -z "$NMSRVRS" ]; then
- exit 0
- fi
- mv /etc/resolv.conf /etc/resolv.conf.bak
- for NS in $NMSRVRS ; do
- echo "nameserver $NS" >> /etc/resolv.conf
- done
- for SEARCH in $SRCHS ; do
- echo "search $SEARCH" >> /etc/resolv.conf
- done
- ;;
- down)
- mv /etc/resolv.conf.bak /etc/resolv.conf
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement