dhcp-client passing ISP dsn info to dhcpd
fbsd
fbsd at a1poweruser.com
Fri Apr 28 15:17:37 UTC 2006
>That kind of script writing is way above my ability.
>
>Does anybody on this list have such a customized script or is there
>some place where users post such things to share with the public
>that I can search for it?
Here's how I'd go about it using fairly simple scripting techniques.
Note that this might not work for you, no guarantees, YMMV, etc.
In dhcpd.conf comment out the line "option domain-name-servers" and
add
a line
include "/etc/dhcpd.name-servers";
This will include the contents of the named file into dhcpd.conf. It
is
easier to manipulate a small separate file, rather than trying to
manage the whole dhcpd.conf file
There is a OS specific script installed as dhclient-script, so
you'll
need to poke around there to find exactly the right place. Anyway,
in
the function that creates /etc/resolv.conf (make_resolv_conf() on my
version) add lines like this:
make_resolv_conf() {
if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers"
!= x ]; then
echo search $new_domain_name >/etc/resolv.conf
for nameserver in $new_domain_name_servers; do
echo nameserver $nameserver >>/etc/resolv.conf
done
# replace dhcpd.conf include file contents (should be one long
line)
my_domain_name_servers=`echo $new_domain_name_servers | sed -e
's/ /, /g'`
echo "option domain-name-servers $my_domain_name_servers ;" >
/etc/dhcpd.name-servers.tmp
# see if different to existing file
cmp -s /etc/dhcpd.name-servers.tmp /etc/dhcpd.name-servers
if [ $? -gt 0 ]; then
# move the new file into place
mv /etc/dhcpd.name-servers.tmp /etc/dhcpd.name-servers
# restart dhcp using whatever is appropriate for your
platform
service dhcpd restart
fi
# end of changes
fi
}
After renewing the lease on the interface check the contents of
/etc/dhcpd.name-servers to see that it contains valid syntax.
Note however, that your clients on the private lan will only pick up
this change the next time they renew their lease.
Also the overhead of running a caching name server means that any
cached lookups will happen a lot faster. eg if more than one system
looks up, say, www.google.com, etc. It also allows for the future
possibility of running your own internal DNS zones, rather than
using,
say, host files on evey system.
-----Original Message-----
From: dhcp-users-bounce at isc.org [mailto:dhcp-users-bounce at isc.org]On
Behalf Of Glenn Satchell
Sent: Thursday, April 27, 2006 10:52 AM
To: dhcp-users at isc.org
Subject: RE: dhcp-client passing ISP dsn info to dhcpd
I am running FreeBSD OS and the dhclient-script
has no routine named make_resolv_conf.
I has a routine called add_new_resolv_conf which seems to
be using completely different logic than what you posted.
I posted the routine from dhclient-script I think you are talking
about.
I also attached the complete script just in case you need to see the
complete thing.
add_new_resolv_conf() {
# XXX Old code did not create/update resolv.conf unless both
# $new_domain_name and $new_domain_name_servers were provided. PR
# #3135 reported some ISP's only provide $new_domain_name_servers
and
# thus broke the script. This code creates the resolv.conf if
either
# are provided.
rm -f /etc/resolv.conf.std
if [ -n "$new_domain_name" ]; then
echo "search $new_domain_name" >>/etc/resolv.conf.std
fi
if [ -n "$new_domain_name_servers" ]; then
for nameserver in $new_domain_name_servers; do
echo "nameserver $nameserver" >>/etc/resolv.conf.std
done
fi
if [ -f /etc/resolv.conf.std ]; then
if [ -f /etc/resolv.conf.tail ]; then
cat /etc/resolv.conf.tail >>/etc/resolv.conf.std
fi
# When resolv.conf is not changed actually, we don't
# need to update it.
# If /usr is not mounted yet, we cannot use cmp, then
# the following test fails. In such case, we simply
# ignore an error and do update resolv.conf.
if cmp -s /etc/resolv.conf.std /etc/resolv.conf; then
rm -f /etc/resolv.conf.std
return 0
fi 2>/dev/null
# In case (e.g. during OpenBSD installs) /etc/resolv.conf
# is a symbolic link, take care to preserve the link and write
# the new data in the correct location.
if [ -f /etc/resolv.conf ]; then
cat /etc/resolv.conf > /etc/resolv.conf.save
fi
cat /etc/resolv.conf.std > /etc/resolv.conf
rm -f /etc/resolv.conf.std
# Try to ensure correct ownership and permissions.
chown -RL root:wheel /etc/resolv.conf
chmod -RL 644 /etc/resolv.conf
return 0
fi
return 1
}
# after the above code in the script I think add this code.
# I inserted the command I use to restart dhcpd. Don't know what
"service" means
# there are always 2 dns ip addresses from my ISP
update_dhcpd_conf() {
# replace dhcpd.conf include file contents (should be one long
line)
my_domain_name_servers=`echo $new_domain_name_servers | sed -e 's/
/, /g'`
echo "option domain-name-servers $my_domain_name_servers ;" >
/etc/dhcpd.name-servers.tmp
# see if different to existing file
cmp -s /etc/dhcpd.name-servers.tmp /etc/dhcpd.name-servers
if [ $? -gt 0 ]; then
# move the new file into place
mv /etc/dhcpd.name-servers.tmp /etc/dhcpd.name-servers
# restart dhcp using whatever is appropriate for your platform
#service dhcpd restart
/usr/local/etc/rc.d/isc-dhcpd.sh restart -q
fi
rm -f /etc/dhcpd.name-servers.tmp
}
Do I have this in correct place in the script.
I all ready have a /etc/dhclient-exit-hooks for updating zoneedit
with my
dynamic IP address from my ISP if it changes.
Should I place the update_dhcpd_conf() routine there?
More information about the dhcp-users
mailing list