[Dnsmasq-discuss] Automatic DHCP client naming

Ferenc Wagner wferi at niif.hu
Sat Apr 17 11:20:49 BST 2010


Simon Kelley <simon at thekelleys.org.uk> writes:

> Ferenc Wagner wrote:
>
>> Simon Kelley <simon at thekelleys.org.uk> writes:
>> 
>>> Ferenc Wagner wrote:
>>>
>>>> Is there any way in dnsmasq to push a hostname to a DHCP client
>>>> even if it didn't report (or ask for) one?  I'd like to
>>>> automatically name my clients based on their MAC addresses, like
>>>> 00:11:22:33:44:55 should get the hostname
>>>> 00-11-22-33-44-55.domain.tld.  Currently, I can get this effect
>>>> only if the client sends its hostname in the DHCP request; then
>>>> dnsmasq adds the correct domain, registers the name in its DNS
>>>> database and sends back the fully qualified address.  Good.  But
>>>> I'd like to avoid generating the ?hostname on the clients before
>>>> starting DHCP.
>>>
>>> It would be possible to add that functionality, probably with
>>> something like dhcp-ignore-names, say "dhcp-mac-as-name", but only
>>> for a fixed name format (should there be a prefix?)
>> 
>> Hmm, I'd rather extend the wildcarding already present in dhcp-mac with
>> something like
>> 
>> dhcp-mac=*:*:*:*:*:*,PREFIX*-*-*-*-*-*SUFFIX
>> 
>> or
>> 
>> dhcp-mac=*,PREFIX*SUFFIX
>> 
>> with the replacement of colons implied.  On the other hand, I've found
>> http://thread.gmane.org/gmane.network.dns.dnsmasq.general/3774/focus=3778
>> just now...  Well, managing a registry from dhcp-script is almost
>> acceptable, apart from the first run.  Here is another idea: why not let
>> dhcp-script write back the hostname to dnsmasq?  That way no separate
>> registry nor daemon restarts would be needed.
>
> Restart aren't needed: it's possible to re-read dhcp-host  lines on
> SIGHUP is they are kept in a separate file.

I fail to see how this could work reliably: the query may have been
answered by the time the asynchronous dhcp-script gets around to signal
dnsmasq to read the updated host data.

> Getting data back from the dhcp-script is very difficult: it executes
> somewhat asynchronously so that the daemon can't ever be blocked waiting
> for a script to finish.

I can recall reading some warnings about long-running dhcp-scripts, that
they block dnsmasq.  Did this change?

Anyway, wouldn't synchronous scripts be a worthy option, especially if
given the possibility to communicate data back to dnsmasq?  It's also
easy to fork off an async worker from a sync helper, if needed.

A built-in solution (maybe in dhcp-generate-names) would be safer and
more efficient, but somewhat cumbersome, because one may want to use the
hardware address, the IP address, the client ID, the client provided
hostname etc. as a source.  For my purposes, something like

dhcp-ignore-names
dhcp-generate-names=hwaddr:y/:/-/

would be enough, and dnsmasq already has some regex machinery included,
but I'm not sure this scheme is general enough, or whether the extra
safety and efficiency is worth it.  Just brainstorming...
-- 
Cheers,
Feri.



More information about the Dnsmasq-discuss mailing list