Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a voyage 2.6.38 machine running DNSMASQ for a DHCP server and I would like to get the hostnames of the clients that acquire DHCP leases. How would I go about doing this?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

If the host sends its name you can retrieve it from DNS. If you know its IP address you just do a reverse lookup on the IP address. One of these commands should work (use the host's IP address in place of 192.0.32.10):

host 192.0.32.10
nslookup 192.0.32.10 

You can retrieve a list of all leases including the name provided if any from your dhcp.leases file. Its location will vary depending on the distribution you use. Ubuntu uses /var/lib/misc/dnsmasq.leases while OpenWrt uses /tmp/dhcp.leases. If you have a man page for dnsmasq, then the command man dnsmasq should mention the location of leases file at the end of the document. You can override this location by specifying the dhcp-leasefile option in your configuration or command line. The command line options -l or --dhcp-leasfile= options can be used to do this.

The fields in the leasefile are timestamp, mac address, ip address, hostname, and client id. The client is not required to send a hostname or client id.

If logging has been enabled, you can look at the syslog to see which leases have been negotiated. All DHCP negotiations should be logged. If you have long lease times, the negotiations will be not be frequent. Clients should start negotiating a renewal at half the lease time. It is best to set the lease time at least twice the period you can reasonably expect your DHCP server to be down.

share|improve this answer
    
/var/tmp/dnsmasq.leases was what I was after, thanks! –  DanielGibbs Nov 7 '11 at 21:20
add comment

It's upto the client whether it wants to send them. In the initial request it can be configured to send the hostname. Most desktop/server DHCP clients do this embedded one often do not.

share|improve this answer
    
That's fine with me, but if the client did send their hostname, whereabouts could I find it? In some logs? Or some other file somewhere? –  DanielGibbs Nov 7 '11 at 2:23
    
That would depend on what DHCP server software you are running, ISC DHCPd? –  ewanm89 Nov 7 '11 at 2:34
    
I am running DNSMASQ, sorry, I'll update the question with that information. –  DanielGibbs Nov 7 '11 at 2:46
    
okay, the manual is a bit sketchy on what it logs for the DHCP part of it (it's a DNS resolver daemon really). However you could turn on the logging and see? –  ewanm89 Nov 7 '11 at 3:10
    
It looks like it logs the hostname with each DHCPACK in /var/log/daemon.log. Thanks! Care to edit that into your answer? –  DanielGibbs Nov 7 '11 at 3:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.