[wplug] DNS problems (SOLVED)

Vance Kochenderfer vkochend at nyx.net
Sat Feb 19 17:07:20 EST 2005


Just putting this out there in case anyone else has had similar problems.

My parents began having problems with their dialup service - there was
a five second delay when trying to reach any remote host.  After much
searching, I finally found that the reason was that the PPP server gave
them a bogus address for the primary DNS nameserver.  So each time they
tried to connect to a host, it had to wait for the first name lookup to
time out before going to the secondary nameserver, which is valid.

To work around this, I developed a script to put into /etc/ppp/ip-up.local
which comments out any bogus nameservers from /etc/resolv.conf.  This is
for Mandrake 10.1 but ought to work on most Linux distributions (it uses
some GNUisms, so may take some modification to work on BSD).

Suggestions for improvement are appreciated.  Without further ado, here
it is:

#!/bin/bash
#
##########################
# Weed out bad DNS entries from resolv.conf

sleep 2
export resolv=/etc/resolv.conf
unset baddns
unset dnsadd
unset testadd

# extract DNS addresses from resolv.conf
export dnsadd=`grep -o \
 "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" $resolv | sort | \
 uniq | tr '\n' ' '`

for testadd in $dnsadd
  do
# bad DNS entry if we do not get at least 2 pings back within 5 seconds
  ping -w 5 -c 2 -n $testadd &>/dev/null || export baddns="$baddns $testadd"
  done

for testadd in $baddns
  do
# comment out lines in resolv.conf with bad addresses
  sed -i "/$testadd/ s/^/# /" $resolv
  done


Vance Kochenderfer        |  "Get me out of these ropes and into a
vkochend at nyx.net          |   good belt of Scotch"    -Nick Danger


More information about the wplug mailing list