John Gardner's Weblog

pageicon Friday Jul 27, 2007

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.

Comments:

Post a Comment:
Comments are closed for this entry.

« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

Feeds

Search this blog

Links

Weblog menu

Today's referrers

Today's Page Hits: 128

Support Software Freedom Day
Change your world on September 19, 2009. Find an event near you.» Join Now