Skip to content

Instantly share code, notes, and snippets.

@Hexcles
Created March 24, 2012 12:41
Show Gist options
  • Save Hexcles/2182248 to your computer and use it in GitHub Desktop.
Save Hexcles/2182248 to your computer and use it in GitHub Desktop.
Setting up DNS according to OpenVPN dhcp-option (used with openvpn --up)
#!/bin/sh
# Setting up DNS according to OpenVPN dhcp-option
# used with openvpn --up
mv /etc/resolv.conf /etc/resolv.conf.old
for (( i=1; 1; i++))
do
optname="foreign_option_$i"
option=${!optname}
[ -n "$option" ] || break
if [ -n `echo $option | grep DOMAIN` ] || [ -n `echo $option | grep DNS` ]
then
echo $option | sed -e 's/dhcp-option DOMAIN/search/g' -e 's/dhcp-option DNS/nameserver/g' >> /etc/resolv.conf
fi
done
if [ -f /etc/resolv.conf ]
then
cat /etc/resolv.conf
else
mv /etc/resolv.conf.old /etc/resolv.conf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment