-
-
Save pklaus/5084036e9a4b4206e074 to your computer and use it in GitHub Desktop.
Setting DNS Servers as pushed by an OpenVPN Server. Uses resolvconf.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# script for OpenVPN to set dns servers pushed by the server using resolvconf on the client. | |
# <http://openvpn.net/archive/openvpn-users/2006-10/msg00218.html> | |
# up down script for client.ovpn configuration files (to be set using:) | |
# up ./client.sh | |
# down ./client.sh | |
UPORDOWN=$1 | |
DEV=$2 | |
case $UPORDOWN in | |
up) | |
set | | |
sed -n "s/^foreign_option_.* DNS \(.*\)'/nameserver \1/; T next; p; | |
:next; s/^foreign_option_.* DOMAIN \(.*\)'/domain \1/; T; p;" | | |
resolvconf -a $DEV && resolvconf -u ;; | |
down) | |
resolvconf -d $DEV && resolvconf -u ;; | |
*) echo das war wohl nichts ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script, it helped out some time ago.
Nowadays it on the one hand does not work with recent versions of OpenVPN anymore, it is superseeded by /etc/openvpn/update-resolv-conf which ships with openvpn. From version 2.3.2-5, it plays very nicely with resolvconf, even up to that it plays fairly nice.
On the other hand, the script "client.sh" at least has the design flaw that it depends on "foreign_option_.* DNS " appearing at the beginning of a line of the output of 'set', which is expensive and subject to break: Just reg a function that uses "cat<<EOF" and outputs a string that matches and your resolv.conf will be severely broken in cases.
So, you might consider removing this or pointing out the limitations, don't you feel so?
With kind regards,
Rob