Results 1 to 4 of 4
hi. is there a way (a script or a command or a file) to check how many free leases i have in my dhcp? /var/lib/dhcp/dhcpd.leases has 2086 when all i ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-10-2010 #1
- Join Date
- Aug 2010
a way to check free lease left on dhcp
is there a way (a script or a command or a file) to check how many free leases i have in my dhcp?
/var/lib/dhcp/dhcpd.leases has 2086 when all i have is less then 150 ips in my dhcp, so i cannot use it to check active and conclude what is left...
BTW i have implemented nagios server which basically tells me that the dhcp server still have 1 more and emails me when there is no free leases, but i cannot find how many are left, this is for statistic/new dhcp implementation research.
- 08-10-2010 #2
You would have to find out the subnet of all possible ip's and then do a simple subtract. I.e. when you have configured a subnet 192.168.1.0/24, you know that there can be 254 possible clients. The configuration itself depends on the dhcp server used and the distribution, thus you'll have to see if you find a neat solution that works for you. Maybe your server has some command line arguments that can retrieve you the information you want without the need to parse the configuration files manually?
PS: if you want to e-mail you when you are running low on IP's, it would be far better to raise an alarm when you go below a certain percentage like 10%, don't you think? when you have no ip's left, it can be rather late to react.
PPS: another option would be to parse the /var/log/messages for leases and their expiry ..
- 08-10-2010 #3
- Join Date
- Aug 2010
this is not the typical dhcp setup. i have only a part of a subnet set to the dhcp, and since it is for testing parts, the lease time is only 60 second so there is a cycle of the ips.
it is a gentoo linux, and i cannot find a command line util.
and as for checking messeges log, as i have told above, since here ar hundreds of parts test each day the log and lease file are not reliable. what i am looking for is a way to comunicate with the server directly to know how many leases are free.
- 08-12-2010 #4
Regarding the amount of IP leases that can exist: A subnet is a subnet. If you have only a small amount of IPs in your subnet, it is still a subnet (for example 192.168.4.6/29 has only 7 IPs available under the assumption that your router is within that subnet). Extract that information from the configuration files and you're settled.
And for the leasetime: you won't mind how long a leasetime is. If you get a new line in the messages log telling you that you granted a dhcp lease until T, you know that this IP is leased until the time expires or the client calls a dhcp release ip (which should also show up in the messages log).
So a script could tail -f the messages log and parse for lease and release messages, subtract the resulting active leases from the available leases and offer the final result somehow to others (may it be a file, socket, ..).
As a last note, there should exists dhcp servers with a database backend (possibly not exlicit / by default, but configurable). Querying a database could ease a lot the parse and bookkeeping efforts. EDIT: as an example, take a look at the ldap backend for dhcp3.
Last edited by Kloschüssel; 08-12-2010 at 09:57 AM.