Slight modification to the contrib client.up script: DNS in server order
I had an issue come up where the clients were getting DNS entries in the reverse order the server sends them when using the client.up contrib script. Since the DNS servers on our system are in order from closest->farthest network wise from the VPN server, having them backwards caused some performance issues.
I've attached a patch that puts the DNS entries in the correct order that the server sends them. Can this be updated in the next release?
Signature · 4 lines
Richard Monk ([email protected]...) - Security Analyst Red Hat - Centennial Office: Raleigh, NC USA +1 (919) 890 8501 GPG Key ID: 0x1EBEF129
client.up renamed from client.up.orig +10 -3
@@ -7,6 +7,9 @@ # someone at boldandbusted dink com # http://www.boldandbusted.com/ +# Edit by Richard Monk <[email protected]> Apr 21, 2010 +# Load DNS entries in the same order the openVPN server provides them + # PURPOSE: This script automatically sets the proper /etc/resolv.conf entries # as pulled down from an OpenVPN server.
@@ -43,6 +46,8 @@ unset dns unset opt +resolvConf="/etc/resolv.conf" + # Convert ENVs to an array while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do
@@ -61,14 +66,16 @@ # Now, do the work +i=1 if [ -n "${dns[*]}" ]; then - for i in "${dns[@]}"; do - sed -i -e "1,1 i nameserver ${i}" /etc/resolv.conf || die + for dnsServer in "${dns[@]}"; do + sed -i -e "${i} i nameserver ${dnsServer}" "${resolvConf}" || die + let i++ done fi if [ -n "${domain}" ]; then - sed -i -e "$j,1 i search ${domain}" /etc/resolv.conf || die + sed -i -e "$j,1 i search ${domain}" "${resolvConf}" || die fi # all done...
Quoted 5 lines · Richard Monk
I had an issue come up where the clients were getting DNS entries in the reverse order the server sends them when using the client.up contrib script. Since the DNS servers on our system are in order from
closest->farthestnetwork wise from the VPN server, having them backwards caused some performance issues.
Have you considered a local caching DNS with forwarding?
--Toby
Quoted 16 lines
I've attached a patch that puts the DNS entries in the correct order that the server sends them. Can this be updated in the next release?
Signature · 5 lines
Richard Monk ([email protected]...) - Security Analyst Red Hat - Centennial Office: Raleigh, NC USA +1 (919) 890 8501 GPG Key ID: 0x1EBEF129 <dns-order-client.up.patchQuoted 1 line
------------------------------------------------------------------------------
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Quoted 6 lines · Toby Thain
Quoted 1 line · Richard Monk
I had an issue come up where the clients were getting DNS entries
in
Quoted 8 lines
Quoted 2 lines
the
reverse order the server sends them when using the client.upcontrib
Quoted 3 lines
script. Since the DNS servers on our system are in order from
closest->farthestnetwork wise from the VPN server, having them backwards caused some performance issues.Have you considered a local caching DNS with forwarding?
I don't see how this will solve the problem.
What if the closest _is_ a local caching DNS with forwarding to the next farthest out? You still want all the DNS servers available in case one is down for some reason.
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein
Quoted 6 lines · Karl O. Pinc
Quoted 1 line
Have you considered a local caching DNS with forwarding?
I don't see how this will solve the problem.
What if the closest _is_ a local caching DNS with forwarding to the next farthest out? You still want all the DNS servers available in case one is down for some reason.
Correct, and since NetworkManager adds them in the order the server gives them, having the two methods (native vs NM) operate differently is confusing and troublesome. I decided that the server order should be followed by all clients.
Signature · 4 lines
Richard Monk ([email protected]...) - Security Analyst Red Hat - Centennial Office: Raleigh, NC USA +1 (919) 890 8501 GPG Key ID: 0x1EBEF129
Quoted 8 lines · On Wednesday 21 Apr 2010 14:49:13 Richard Monk wrote:
I had an issue come up where the clients were getting DNS entries in the reverse order the server sends them when using the client.up contrib script. Since the DNS servers on our system are in order from
closest->farthestnetwork wise from the VPN server, having them backwards caused some performance issues.I've attached a patch that puts the DNS entries in the correct order that the server sends them. Can this be updated in the next release?
Hi Richard,
as a matter of fact, there's a new version of that script (and client.down as well) in the git testing tree, which should fix your problem as it just uses the DNS servers in the order they're sent from the server. See here for more details:
http://article.gmane.org/gmane.network.openvpn.devel/3343
and try the attached patch (which is the same that has been merged).
Signature · 1 line
D.
contrib/pull-resolv-conf/client.up +56 -31
@@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Copyright (c) 2005-2009 OpenVPN Technologies, Inc. # Licensed under the GPL version 2
@@ -14,7 +14,6 @@ # Place this in /etc/openvpn/client.up # Then, add the following to your /etc/openvpn/<clientconfig>.conf: # client -# pull dhcp-options # up /etc/openvpn/client.up # Next, "chmod a+x /etc/openvpn/client.up"
@@ -22,8 +21,8 @@ # Note that this script is best served with the companion "client.down" # script. -# Only tested on Gentoo Linux 2005.0 with OpenVPN 2.0 -# It should work with any GNU/Linux with /etc/resolv.conf +# Tested under Debian lenny with OpenVPN 2.1_rc11 +# It should work with any UNIX with a POSIX sh, /etc/resolv.conf or resolvconf # This runs with the context of the OpenVPN UID/GID # at the time of execution. This generally means that
@@ -38,38 +37,64 @@ # init variables i=1 -j=1 -unset fopt -unset dns -unset opt - -# Convert ENVs to an array - -while fopt=foreign_option_$i; [ -n "${!fopt}" ]; do -{ - opt[i-1]=${!fopt} - case ${opt[i-1]} in - *DOMAIN* ) domain=`echo ${opt[i-1]} | \ - sed -e 's/dhcp-option DOMAIN //g'` ;; - *DNS* ) dns[j-1]=`echo ${opt[i-1]} | \ - sed -e 's/dhcp-option DNS //g'` - let j++ ;; +domains= +fopt= +ndoms=0 +nns=0 +nl=' +' + +# $foreign_option_<n> is something like +# "dhcp-option DOMAIN example.com" (multiple allowed) +# or +# "dhcp-option DNS 10.10.10.10" (multiple allowed) + +# each DNS option becomes a "nameserver" option in resolv.con +# if we get one DOMAIN, that becomes "domain" in resolv.conf +# if we get multiple DOMAINS, those become "search" lines in resolv.conf + +while true; do + eval fopt=\$foreign_option_${i} + [ -z "${fopt}" ] && break + + case ${fopt} in + dhcp-option\ DOMAIN\ *) + ndoms=$((ndoms + 1)) + domains="${domains} ${fopt#dhcp-option DOMAIN }" + ;; + dhcp-option\ DNS\ *) + nns=$((nns + 1)) + if [ $nns -le 3 ]; then + dns="${dns}${dns:+$nl}nameserver ${fopt#dhcp-option DNS }" + else + printf "%s\n" "Too many nameservers - ignoring after third" >&2 + fi + ;; + *) + printf "%s\n" "Unknown option \"${fopt}\" - ignored" >&2 + ;; esac - let i++ -} + i=$((i + 1)) done -# Now, do the work - -if [ -n "${dns[*]}" ]; then - for i in "${dns[@]}"; do - sed -i -e "1,1 i nameserver ${i}" /etc/resolv.conf || die - done +ds=domain +if [ $ndoms -gt 1 ]; then + ds=search fi -if [ -n "${domain}" ]; then - sed -i -e "$j,1 i search ${domain}" /etc/resolv.conf || die +# This is the complete file - "$domains" has a leading space already +out="# resolv.conf autogenerated by ${0} (${1})${nl}${dns}${nl}${ds}${domains}" + +# use resolvconf if it's available +if [ -x /sbin/resolvconf ] ; then + printf "%s\n" "${out}" | /sbin/resolvconf -a "${1}" +else + # Preserve the existing resolv.conf + if [ -e /etc/resolv.conf ] ; then + cp /etc/resolv.conf /etc/resolv.conf.ovpnsave + fi + printf "%s\n" "${out}" > /etc/resolv.conf + chmod 644 /etc/resolv.conf fi -# all done... exit 0
contrib/pull-resolv-conf/client.down +8 -38
64 lines not on this page · raw message
Quoted 8 lines · Davide Brini
as a matter of fact, there's a new version of that script (and client.down as well) in the git testing tree, which should fix your problem as it just uses the DNS servers in the order they're sent from the server. See here for more details:
http://article.gmane.org/gmane.network.openvpn.devel/3343
and try the attached patch (which is the same that has been merged).
Ha, perfect! My first attempt was using this style (single variable, add entries, send to resolv) so either actual method works.
Any idea if this will make it into the next point release?
Signature · 4 lines
Richard Monk ([email protected]...) - Security Analyst Red Hat - Centennial Office: Raleigh, NC USA +1 (919) 890 8501 GPG Key ID: 0x1EBEF129
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 6 lines · Richard Monk
Quoted 5 lines · Davide Brini
as a matter of fact, there's a new version of that script (and client.down as well) in the git testing tree, which should fix your problem as it just uses the DNS servers in the order they're sent from the server. See here for more details:
Quoted 8 lines
Quoted 3 lines
http://article.gmane.org/gmane.network.openvpn.devel/3343
and try the attached patch (which is the same that has been merged).
Ha, perfect! My first attempt was using this style (single variable, add entries, send to resolv) so either actual method works.
Any idea if this will make it into the next point release?
Depending on how comfortable James is with it, it might come in the next release. It all depends on how critical he is to patches in the contrib/ directory. If not the first next release, then definitely a future release. It seems to work fine, but I'm going to test it out even further to be absolutely sure it is stable.
kind regards,
David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iEYEARECAAYFAkvPIyYACgkQDC186MBRfrp2AgCfVh2xPYjTUCTQOBjkPwNQF/M5 LBgAnjaLDkuWGMCK9zK1iVoOIWiBBb4R
=ezjS
-----END PGP SIGNATURE-----
Quoted 14 lines · Karl O. Pinc
Quoted 13 lines · Toby Thain
Quoted 1 line · Richard Monk
I had an issue come up where the clients were getting DNS entries
in
Quoted 2 lines
the
reverse order the server sends them when using the client.upcontrib
Quoted 3 lines
script. Since the DNS servers on our system are in order from
closest->farthestnetwork wise from the VPN server, having them backwards caused some performance issues.
Quoted 6 lines
Quoted 1 line
Have you considered a local caching DNS with forwarding?
I don't see how this will solve the problem.
What if the closest _is_ a local caching DNS with forwarding to the next farthest out? You still want all the DNS servers available in case one is down for some reason.
I got the impression his problem was *latency*, not availability; changing the order of name servers cannot help with the latter. A local caching DNS may have considerably less latency than the closest forwarder...
--Toby
Quoted 12 lines
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein------------------------------------------------------------------------------
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
Quoted 14 lines · Karl O. Pinc
Quoted 13 lines · Toby Thain
Quoted 1 line · Richard Monk
I had an issue come up where the clients were getting DNS entries
in
Quoted 2 lines
the
reverse order the server sends them when using the client.upcontrib
Quoted 3 lines
script. Since the DNS servers on our system are in order from
closest->farthestnetwork wise from the VPN server, having them backwards caused some performance issues.
Quoted 6 lines
Quoted 1 line
Have you considered a local caching DNS with forwarding?
I don't see how this will solve the problem.
What if the closest _is_ a local caching DNS with forwarding to the next farthest out? You still want all the DNS servers available in case one is down for some reason.
Multiple forwarders achieves that, afaics.
--Toby
Quoted 12 lines
Karl <[email protected]...>
Free Software: "You don't pay back, you pay forward."
-- Robert A. Heinlein------------------------------------------------------------------------------
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel