John Gardner's Weblog
Dhcp info
I have a number of times that (while using DHCP) when I first boot up that DNS isn't working. The resolv.conf file is missing or has the wrong values and I hate having to fix things by hand, so i decided to scipt the DNS setup using the information from DHCP (via the dhcpinfo command.)
#!/bin/ksh
IFDEV=`ifconfig -a|grep ":"|grep -v lo0|cut -f1 -d:|grep -v "ip.tun"|grep -v "inet6"|cut -f1`
GATEWAY=`/sbin/dhcpinfo -i $IFDEV router`
DNSSERVER=`/sbin/dhcpinfo -i $IFDEV DNSserv`
DOMAIN=`/sbin/dhcpinfo -i $IFDEV DNSdmain`
MASK=`/sbin/dhcpinfo -i $IFDEV 1`
echo dev=$IFDEV gateway=$GATEWAY domain=$DOMAIN mask=$MASK
cp /etc/nsswitch.dns /etc/nsswitch.conf
echo "nameserver $DNSSERVER" >/etc/resolv.conf
if [ "$DOMAIN" != "localdomain" ]
then
echo "domain $DOMAIN" >>/etc/resolv.conf
echo "search $DOMAIN" >>/etc/resolv.conf
fi
The logic for figuring which interface to use isn't very robust, but it works in all the setups I use.
Posted at 10:53AM Jul 27, 2007 by oz in Solaris X86 |
Comments:
Friday Jul 27, 2007