forget leases

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

forget leases

richard lucassen
Is it somehow possible to create a pool that "forgets" which ip address
had been assigned to a particular host once the max-lease-time has
expired?

Goal: I want to have a pool from:

192.168.65.128 to 192.168.65.254

The first host gets 128, the 2nd 129 etc. The max-lease-time is 300s. I
switch off the two hosts. After 10 minutes I take two different hosts.
Now I would like that dhcpd assigns ip 128 and 129 again to the new
machines.

R.

--
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
+------------------------------------------------------------------+
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Simon Hobson
richard lucassen <[hidden email]> wrote:

> Is it somehow possible to create a pool that "forgets" which ip address
> had been assigned to a particular host once the max-lease-time has
> expired?
>
> Goal: I want to have a pool from:
>
> 192.168.65.128 to 192.168.65.254
>
> The first host gets 128, the 2nd 129 etc. The max-lease-time is 300s. I
> switch off the two hosts. After 10 minutes I take two different hosts.
> Now I would like that dhcpd assigns ip 128 and 129 again to the new
> machines.


Config/testing bench ?

No, you'd need to do some external work to make that happen. BTW - is the goal that a "new" machine will get .128, or that the "old" machine will get a different address - it makes a difference to ways of achieving it, and one is harder than the other ?

BTW - The ISC server will not allocate the address like that anyway. At present, due to the way if uses hashed lists it will allocate addresses "top down" - so .254 will get allocated first, then .253, and so on. But that is not documented, nor is guaranteed to remain the same.



_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

richard lucassen
On Thu, 23 Jul 2015 09:46:07 +0100
Simon Hobson <[hidden email]> wrote:

> > Goal: I want to have a pool from:
> >
> > 192.168.65.128 to 192.168.65.254
> >
> > The first host gets 128, the 2nd 129 etc. The max-lease-time is
> > 300s. I switch off the two hosts. After 10 minutes I take two
> > different hosts. Now I would like that dhcpd assigns ip 128 and 129
> > again to the new machines.
>
> Config/testing bench ?

yep

> No, you'd need to do some external work to make that happen. BTW - is
> the goal that a "new" machine will get .128, or that the "old"
> machine will get a different address - it makes a difference to ways
> of achieving it, and one is harder than the other ?

When using the test network, I'd like to have all hosts start from 128
(or, as you say from 254, that behaviour changed a few years ago AFAIK)

In fact, it's a /24 network and some hosts regularely come back. The
problem is now that I always have to nmap the /24 in order to find the
hosts that populate this network. And as I use clusterssh to manage
these hosts, each time I need to find out the correct command as
dhcpd reassigns the ip that it once assigned in the past ;-)

I was looking for an option "remove-expired-entries-from-leases-file"
or something like that :)

I agree: I'm terribly lazy :)

R.

--
+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
+------------------------------------------------------------------+
--
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
+------------------------------------------------------------------+
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Sten Carlsen


On 23/07/15 13:44, richard lucassen wrote:
On Thu, 23 Jul 2015 09:46:07 +0100
Simon Hobson [hidden email] wrote:

Goal: I want to have a pool from:

192.168.65.128 to 192.168.65.254

The first host gets 128, the 2nd 129 etc. The max-lease-time is
300s. I switch off the two hosts. After 10 minutes I take two
different hosts. Now I would like that dhcpd assigns ip 128 and 129
again to the new machines.
Config/testing bench ?
yep

No, you'd need to do some external work to make that happen. BTW - is
the goal that a "new" machine will get .128, or that the "old"
machine will get a different address - it makes a difference to ways
of achieving it, and one is harder than the other ?
When using the test network, I'd like to have all hosts start from 128
(or, as you say from 254, that behaviour changed a few years ago AFAIK)

In fact, it's a /24 network and some hosts regularely come back. The
problem is now that I always have to nmap the /24 in order to find the
hosts that populate this network. And as I use clusterssh to manage
these hosts, each time I need to find out the correct command as
dhcpd reassigns the ip that it once assigned in the past ;-)
I wonder if "on commit" might be a help?

I was looking for an option "remove-expired-entries-from-leases-file"
or something like that :)

I agree: I'm terribly lazy :)

R.


-- 
Best regards

Sten Carlsen

No improvements come from shouting:

       "MALE BOVINE MANURE!!!" 

_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Simon Hobson
In reply to this post by richard lucassen
richard lucassen <[hidden email]> wrote:

> The
> problem is now that I always have to nmap the /24 in order to find the
> hosts that populate this network. And as I use clusterssh to manage
> these hosts, each time I need to find out the correct command as
> dhcpd reassigns the ip that it once assigned in the past ;-)

A few things that come to mind :

- Write a script that tail the log (or uses on-commit) and shows the IP address and what it's been assigned to on a console screen.

- Write (or adapt) a script that parses the leases file and tells you what's using what address that you can run as required.

- Write a script that tails the log (or uses on-cmmit) to detect expired leases - and use OMAPI to delete the lease, or do a stop-blast-start sequence to clear the leases file completely.

- Barcode (if it's not already) the MAC address on each bit of gear. Have a scanner that'll read the barcode and assign a fixed address (or let you pick one) before quickly re-configuring the DHCP server.

- Hack the code. Remove the code that does all the "least recently used" stuff, and simply pick the first address that's not currently in use.



Simon Hobson


_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Niall O'Reilly
In reply to this post by richard lucassen
On Thu, 23 Jul 2015 09:30:56 +0100,
richard lucassen wrote:

>
> Is it somehow possible to create a pool that "forgets" which ip address
> had been assigned to a particular host once the max-lease-time has
> expired?
>
> Goal: I want to have a pool from:
>
> 192.168.65.128 to 192.168.65.254
>
> The first host gets 128, the 2nd 129 etc. The max-lease-time is 300s. I
> switch off the two hosts. After 10 minutes I take two different hosts.
> Now I would like that dhcpd assigns ip 128 and 129 again to the new
> machines.

  IIUC, your goal is not compatible with the usual reading of the
  following extract from RFC2131.

2.2 Dynamic allocation of network addresses

   The second service provided by DHCP is the allocation of temporary or
   permanent network (IP) addresses to clients.  The basic mechanism for
   the dynamic allocation of network addresses is simple: a client
   requests the use of an address for some period of time.  The
   allocation mechanism (the collection of DHCP servers) guarantees not
   to reallocate that address within the requested time and attempts to
   return the same network address each time the client requests an
   address.

  The second part of the last sentence ("and attempts to return
  the same network address ...") is key.  Until the pool is exhausted,
  the server meets this requirement by leasing a fresh, unused address.


  Best regards,
  Niall O'Reilly
 
 
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

glenn.satchell
In reply to this post by Simon Hobson
On Thu, July 23, 2015 10:36 pm, Simon Hobson wrote:

> richard lucassen <[hidden email]> wrote:
>
>> The
>> problem is now that I always have to nmap the /24 in order to find the
>> hosts that populate this network. And as I use clusterssh to manage
>> these hosts, each time I need to find out the correct command as
>> dhcpd reassigns the ip that it once assigned in the past ;-)
>
> A few things that come to mind :
>
> - Write a script that tail the log (or uses on-commit) and shows the IP
> address and what it's been assigned to on a console screen.
>
> - Write (or adapt) a script that parses the leases file and tells you
> what's using what address that you can run as required.
>
> - Write a script that tails the log (or uses on-cmmit) to detect expired
> leases - and use OMAPI to delete the lease, or do a stop-blast-start
> sequence to clear the leases file completely.
>
> - Barcode (if it's not already) the MAC address on each bit of gear. Have
> a scanner that'll read the barcode and assign a fixed address (or let you
> pick one) before quickly re-configuring the DHCP server.
>
> - Hack the code. Remove the code that does all the "least recently used"
> stuff, and simply pick the first address that's not currently in use.
>
> Simon Hobson

Use DNS and call things by name rather than ip in your scripts.

regards,
-glenn

_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Simon Hobson
In reply to this post by Niall O'Reilly
Niall O'Reilly <[hidden email]> wrote:

>  The second part of the last sentence ("and attempts to return
>  the same network address ...") is key.  Until the pool is exhausted,
>  the server meets this requirement by leasing a fresh, unused address.


While that is true, I think this situation is an example where that isn't actually the desired operation.


Glenn Satchell <[hidden email]> wrote:

> Use DNS and call things by name rather than ip in your scripts.

That may work if your devices all provide a known and reliable host name - otherwise, how do you configure the DNS and/or find out what names to use ?

_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

richard lucassen
In reply to this post by Sten Carlsen
On Thu, 23 Jul 2015 14:11:49 +0200
Sten Carlsen <[hidden email]> wrote:

> I wonder if "on commit" might be a help?
> >
> > I was looking for an option
> > "remove-expired-entries-from-leases-file" or something like that :)

Ok, thnx everyone, I'll write a nice shell script that parses the leases
file and outputs a "cssh -l root <host> <host>" command. Unfortunately
it is not possible using a "pool" config. No problem, it's stated
clearly in RFC as pointed out.

R.

--
___________________________________________________________________
It is better to remain silent and be thought a fool, than to speak
aloud and remove all doubt.

+------------------------------------------------------------------+
| Richard Lucassen, Utrecht                                        |
+------------------------------------------------------------------+
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Mark Sandrock
In reply to this post by Niall O'Reilly
In the Infoblox product, which is based on
ISC DHCP, expired leases can be scavenged,
after a specified time has elapsed.

Setting scavenging to be done immediately
would seem compatible with what the OP
is wanting.

I have no connection with Infoblox other
than working with their DDI product, and
hope it's okay to mention them.

Mark

> On Jul 23, 2015, at 8:25 AM, Niall O'Reilly <[hidden email]> wrote:
>
> On Thu, 23 Jul 2015 09:30:56 +0100,
> richard lucassen wrote:
>>
>> Is it somehow possible to create a pool that "forgets" which ip address
>> had been assigned to a particular host once the max-lease-time has
>> expired?
>>
>> Goal: I want to have a pool from:
>>
>> 192.168.65.128 to 192.168.65.254
>>
>> The first host gets 128, the 2nd 129 etc. The max-lease-time is 300s. I
>> switch off the two hosts. After 10 minutes I take two different hosts.
>> Now I would like that dhcpd assigns ip 128 and 129 again to the new
>> machines.
>
>  IIUC, your goal is not compatible with the usual reading of the
>  following extract from RFC2131.
>
> 2.2 Dynamic allocation of network addresses
>
>   The second service provided by DHCP is the allocation of temporary or
>   permanent network (IP) addresses to clients.  The basic mechanism for
>   the dynamic allocation of network addresses is simple: a client
>   requests the use of an address for some period of time.  The
>   allocation mechanism (the collection of DHCP servers) guarantees not
>   to reallocate that address within the requested time and attempts to
>   return the same network address each time the client requests an
>   address.
>
>  The second part of the last sentence ("and attempts to return
>  the same network address ...") is key.  Until the pool is exhausted,
>  the server meets this requirement by leasing a fresh, unused address.
>
>
>  Best regards,
>  Niall O'Reilly
>
>
> _______________________________________________
> dhcp-users mailing list
> [hidden email]
> https://lists.isc.org/mailman/listinfo/dhcp-users
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Shawn Routhier
In reply to this post by richard lucassen

> On Jul 23, 2015, at 7:59 AM, richard lucassen <[hidden email]> wrote:
>
> On Thu, 23 Jul 2015 14:11:49 +0200
> Sten Carlsen <[hidden email]> wrote:
>
>> I wonder if "on commit" might be a help?
>>>
>>> I was looking for an option
>>> "remove-expired-entries-from-leases-file" or something like that :)
>
> Ok, thnx everyone, I'll write a nice shell script that parses the leases
> file and outputs a "cssh -l root <host> <host>" command. Unfortunately
> it is not possible using a "pool" config. No problem, it's stated
> clearly in RFC as pointed out.
>
> R.

You may want to look at the script in
DHCP/contrib/dhcp-lease-list.pl
it provides a perl script to do some things to the lease file.

It probably won’t be exactly what you want but it may provide a
starting point.

Shawn

_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Mike-2
In reply to this post by richard lucassen
On 7/23/2015 10:59 AM, richard lucassen wrote:
> Ok, thnx everyone, I'll write a nice shell script that parses the leases
> file ...

If it's any help to get you started, below is my script that displays
the IPv4 leases for my setup (I run it on FreeBSD 10.1)...  :)

(version without line-wrapping is available here:
  https://archive.mgm51.com/kea-show-leases.zip )


===============================

#!/bin/sh


set -e
#set -xv

LeaseFile=/var/db/kea/kea-leases4.csv
Tmp1File=$(mktemp /tmp/show-lease.XXXXXX)

PrintFormat="%-15s %-17s %7s %-15s %-15s %-15s %-15s\n"

# renew halfway through the lease
RenewFactor=2


NumRecsToShow=45
test $1x = allx && NumRecsToShow=999999


# kea lease record
#
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
# 10.20.2.131,00:30:f4:c1:02:1e,01:00:30:f4:c1:02:1e,80000,1429363284,1,0,0,

tail -n +2 /var/db/kea/kea-leases4.csv | tail -r > ${Tmp1File}


printf "${PrintFormat}" "IPAddr" "HWAddr" "Lease" "Start" "Renew"
"Expire" "Hostname"

RecCount=0
while IFS=, read IPAddr HWAddr ClientID LeaseLenSecs ExpireSecs SubnetID
FQDNFwd FQDNRev HostName
do
        StartSecs=$((${ExpireSecs} - ${LeaseLenSecs}))
        RenewLenSecs=$((${LeaseLenSecs} / ${RenewFactor}))
        RenewSecs=$((${ExpireSecs} - ${RenewLenSecs}))
        StartDate=$(date -j -r ${StartSecs} +%Y%m%dT%H%M%S)
        RenewDate=$(date -j -r ${RenewSecs} +%Y%m%dT%H%M%S)
        ExpireDate=$(date -j -r ${ExpireSecs} +%Y%m%dT%H%M%S)
        printf "${PrintFormat}" \
           ${IPAddr} ${HWAddr} ${LeaseLenSecs} ${StartDate} ${RenewDate}
${ExpireDate} ${HostName}
        RecCount=$((${RecCount} + 1))
        test ${RecCount} -ge ${NumRecsToShow} && break
done < ${Tmp1File}


test ${Tmp1File} && rm ${Tmp1File}

=========================================
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users
Reply | Threaded
Open this post in threaded view
|

Re: forget leases

Niall O'Reilly
In reply to this post by Simon Hobson
On Thu, 23 Jul 2015 13:36:19 +0100,
Simon Hobson wrote:
>
> - Write (or adapt) a script that parses the leases file and tells you what's using what address that you can run as required.
>
> - Write a script that tails the log (or uses on-cmmit) to detect expired leases - and use OMAPI to delete the lease,

  I'ld use the result of parsing the leases file to drive
  scavenging with OMAPI.

> or do a stop-blast-start sequence to clear the leases file completely.

  Or this.

  Best regards,
  Niall O'Reilly
 
_______________________________________________
dhcp-users mailing list
[hidden email]
https://lists.isc.org/mailman/listinfo/dhcp-users