[Dnsmasq-discuss] client name via DHCP
Simon Kelley
simon at thekelleys.org.uk
Fri Feb 11 10:40:58 GMT 2011
Helmut Hullen wrote:
> Hallo, Simon,
>
> Du meintest am 10.02.11:
>
>>>>>>> when I use the ISC DHCP, then I can see the name of the Windows
>>>>>>> client in "/var/state/dhcp/dhcp.leases".
>>>>>>>
>>>>>>> With dnsmasq as DNS and DHCP server I haven't found this feature
>>>>>>> - is it somewhere hidden?
>
>>> [...]
>
>>> The client's own name is "KB-PC", dnsmasq reads "Client-A60" from a
>>> list on the server (which is completely independent from the "real"
>>> client's name).
>>>
>>> I want to see the "real" client's name, it's a better help for
>>> guessing who's the owner of the machine.
>>>
>
>> So you want the hostname the client sends to the DHCP server, which
>> is not used by dnsmasq because it's overridden by on-the-server
>> configuration? That is available: it's set in the environment
>> variable DNSMASQ_SUPPLIED_HOSTNAME given to the lease-change script.
>> (All the environment variables are prefixed with DNSMASQ_, it really
>> is the client's idea of the hostname, not dnsmasq's.
>
>> Writing a little script which logs this and the dnsmasq hostname, MAC
>> address, IP address or anything else useful should give you a file
>> which can be searched.
>
> Sounds simple ... but when can I (or my script) see
> "DNSMASQ_SUPPLIED_HOSTNAME"?
>
> If I've understood managing environment variables right then this
> variable is only valid within (and under) "dnsmasq".
>
> ISC-DHCP tells "client-hostname" in many log lines:
>
> Feb 11 11:05:01 Arktur dhcpd: DHCPOFFER on 192.168.0.186 to
> 00:21:97:10:9c:16 (WPR-PC) via eth0
> Feb 11 11:05:04 Arktur dhcpd: DHCPDISCOVER from 00:21:97:10:9c:16 (WPR-PC) via
> eth0KB-PC
> Feb 11 11:05:04 Arktur dhcpd: DHCPOFFER on 192.168.0.186 to 00:21:97:10:9c:16
> (WPR-PC) via eth0
> Feb 11 11:05:12 Arktur dhcpd: DHCPDISCOVER from 00:21:97:10:9c:16 (WPR-PC) via
> eth0
> Feb 11 11:05:12 Arktur dhcpd: DHCPOFFER on 192.168.0.186 to 00:21:97:10:9c:16
> (WPR-PC) via eth0
> Feb 11 11:05:12 Arktur dhcpd: DHCPREQUEST for 192.168.0.186 (192.168.0.1) from
> 00:21:97:10:9c:16 (WPR-PC) via eth0
> Feb 11 11:05:12 Arktur dhcpd: DHCPACK on 192.168.0.186 to 00:21:97:10:9c:16 (WPR-PC) via eth0
>
> ----------------
>
> I'd be pleased if/when "dnsmasq" tells the client's hostname at least in
> one of its log messages.
>
> Viele Gruesse!
> Helmut
>
> _______________________________________________
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss at lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
>
This is probably the simplest script:
#!/bin/sh
if [ ! x$DNSMASQ_SUPPLIED_HOSTNAME = x ]; then
echo $2 is $DNSMASQ_SUPPLIED_HOSTNAME >>/var/log/dnsmasq_aliases
fi
Put that in a file somewhere and make sure it's executable
chmod a+x path/to/script
then add
dhcp-script=/path/to/script
to /etc/dnsmasq.conf
restart dnsmasq and you should have a file at /var/log/dnsmasq_aliases
full of lines like
11:22:33:44:55:66 is KB-PC
which will be added to as new hosts appear.
HTH
Simon.
More information about the Dnsmasq-discuss
mailing list