[Dnsmasq-discuss] generating hostname on the fly, base on mac address,

Simon Kelley simon at thekelleys.org.uk
Fri Mar 5 14:23:05 GMT 2010


Sébastien G wrote:
> hi folks,
> 
> Dnsmasq is a great software, I use it everywhere I can!   Now, I'm
> facing an issue when automating the installation process of
> Ubuntu/Debian.  To make everything follow, I want to configure dnsmasq
> to provide to a new host being installed a generated hostname.
> (something like pc<XX-XX-XX-XX-XX-XX> (the mac adress of the host)
> 
> I know about the /etc/ethers where I can assign hostname and ip to a
> specific mac address.  The problem of using the /etc/ethers method is
> that I need know the mac adress *before* doing the installation processs
> and add it to the config file. This is not very pratical for us when
> doing a lot of installations.
> 
> So far, I've found that the dhcp-script could be helpful here. This is a
> little script I've encounter, that has the basic idea of what I want to do.
> ----------------
> /usr/bin/add_new_host.sh*:
> #!/bin/bash
> if [ "$1" -eq "del" ]; then
>   exit
> fi
> isnew_mac=$(cat /etc/dnsmasq.conf|grep -v "^#"|grep "dhcp-host"|grep
> "$2")
> 
> if [ -z "$isnew_mac" ]; then
>   echo dhcp-host=$2,$3 >> /etc/dnsmasq.conf
>   /etc/init.d/dnsmasq restart
> fi
> 
> ref:
> http://linuca.org/pipermail/linuxcantabria/2006-June/007314.html
> ----------------
> 
> Doing a restart of the service in this script doesn't sound "right" to
> me. but well...
> 
>

You could put the name/MAC mappings in a separate file, and load it
using dhcp-hostsfile. You can re-load the contents of that without
having to restart dnsmasq by sending SIGHUP to the process.

Cheers,

Simon.



More information about the Dnsmasq-discuss mailing list