Here's something I threw together to make sure the /etc/resolv.conf points to a working nameserver. I run this once a minute. It checks to see what name servers are up and creates /etc/resolv.conf. As you all know SA and mail servers need the first nameserver to always be working.

#!/bin/bash

# This program is run once a minute and automatically generates the /etc/resolv.conf file

DEFAULTSERVERS="65.49.42.30 65.49.42.31 65.49.42.33 69.50.231.141"

# If default isn't optimum then read /etc/sysconfig/local-servers for list

[ -f /etc/sysconfig/local-nameservers ] && . /etc/sysconfig/local-nameservers

echo "# Automatically generated by $0" > /etc/resolv.tmp
echo >> /etc/resolv.tmp
echo "domain ctyme.com" >> /etc/resolv.tmp
echo >> /etc/resolv.tmp

for ns in $LOCALNAMESERVERS $DEFAULTSERVERS; do
/usr/bin/nc -w 3 -z $ns 53 | cut -d \ -f 3 | sed -e 's/^.*$/nameserver \0/' >> /etc/resolv.tmp
done

# resolv.conf only allows 3 nameservers so truncate list to 7 lines

head -n 7 /etc/resolv.tmp > /etc/resolv.conf
rm /etc/resolv.tmp

Reply via email to