[ale] Setting domain name from DHCP?

Michael B. Trausch mike at trausch.us
Wed Mar 19 08:37:36 EDT 2008


On Tue, 2008-03-18 at 23:15 -0400, Jim Kinney wrote:

> You will need to have a host section for each machine identifiable by
> MAC address. In that section you can spec a host name to be applied.
> For example, I want my inkjet to always have the following settings:
> 
> host HP_1100 {
>   hardware ethernet 00:01:e6:6a:89:ff;
>   fixed-address 192.168.0.3;
>   option host-name "HP Inkjet 1100";
> }
> 
> It will get the domain name from the earlier setting.


I had tried that (because a few of the devices on my network require
static IP addresses), but the farthest this seems to go is the DNS
server.

It seems that if I want the domain name to actually be applied to the
clients, I have to use a shell script as a hook into the DHCP client on
the workstations.  The following DHCP script seems to have done it,
though it's probably slightly buggy:

#
# Update the system's domain name when a new DHCP lease is received.  This
# is probably specific to Ubuntu (and maybe Debian) systems that use 127.0.1.1
# for the system's hostname/domainname.
#
# Install this file in /etc/dhcp3/dhclient-exit-hooks.d for it to become
# effective.
#
# Copyright (c) 2008 Michael B. Trausch <mike at trausch.us>, Released under the
# terms of the GNU GPL v3.
#

set_system_domain_name() {
    NDN="$new_domain_name"
    HN=`hostname`
    NEW="127.0.1.1 $HN.$NDN $HN \\# Updated by SSDN"

    sed "s|.*127.0.1.1.*|$NEW|g;" -i /etc/hosts 
    return 0
}

release_system_domain_name() {
    HN=`hostname`
    NEW="127.0.1.1 $HN"

    sed "s|.*127.0.1.1.*|$NEW|g;" -i /etc/hosts 
    return 0
}

case $reason in
    BOUND|RENEW|REBIND|REBOOT)
        set_system_domain_name
        ;;
    EXPIRE|FAIL|RELEASE|STOP)
        release_system_domain_name
        ;;
esac

When I have a valid lease, this gives me the following in my /etc/hosts
file:

127.0.0.1 localhost
127.0.1.1 sage.spicerack sage # Updated by SSDN

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

This seems to be doing the trick, though I am sure to find that I have
missed a couple of final details.  It seems that the system relies on
the /etc/hosts file for finding its domain name, though.  I haven't
found a way to make the system derive its domain name from the DNS
system or anything as of yet, though that would really be nice on my
little network.

    --- Mike

-- 
Michael B. Trausch                                   mike at trausch.us
home: 404-592-5746, 1                                 www.trausch.us
cell: 678-522-7934                       im: mike at trausch.us, jabber
Ubuntu Unofficial Backports Project:    http://backports.trausch.us/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20080319/d10bb85b/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.ale.org/pipermail/ale/attachments/20080319/d10bb85b/attachment-0001.bin 


More information about the Ale mailing list