Reserving ip address on DHCP Server

Bennahon

New Member
Credits
29
Hi All,
I have dhcp server based on CentOs 8 and i have a ansible server also based on CentOs 8.
When the dhcp server recognize new client he send notify to Ansible server.
Then the ansible server starting playbook for new client.
One of the tasks is to configure currently date and time.
But after the set new date and time, the dhcp server set new ip address to client.
Just happening because the "max-lease-time" is over.

There is anyway to reserving ip address without enter the mac address?

Because the all point for this configuration is to do it automatically.

Many thanks,
Ben
 
Last edited:


dos2unix

Well-Known Member
Credits
3,006
Which dhcp server are you using? dhcpd? dnsmasq?

How many servers are you trying to do at once?

Ideas... make the dhcp lease time very long. dhcpd lets you set this for up to 135 years.
Usually the lease will get give out the same address as the last lease had for that MAC.

If you aren't doing many servers at once, you can make the dhcp range very small, even 1 single IP
that way it will always hand out the same IP no matter what the date and time are.
(the downside is you can only do one server at a time).

How are you building these servers? If you are using kickstart, you can give static IPs at build time.

You could make them unique based on MAC, or you could always build them with a static IP, and they will all have the same IP until you are done running ansible on them. Better yet make an inventory file in ansible and have it assign static IPs based on hostname or MAC or just about anything.
(Again the down side, is you can only do one at a time)

However once you get the "real" IPs on everything, it would be easy to build an inventory list.

If your network Admin is agreeable, run fping or nmap -sP X.X.X.0/24 against your network.
It will tell you all the IPs and MACs of every device.
 

Bennahon

New Member
Credits
29
Which dhcp server are you using? dhcpd? dnsmasq?

How many servers are you trying to do at once?

Ideas... make the dhcp lease time very long. dhcpd lets you set this for up to 135 years.
Usually the lease will get give out the same address as the last lease had for that MAC.

If you aren't doing many servers at once, you can make the dhcp range very small, even 1 single IP
that way it will always hand out the same IP no matter what the date and time are.
(the downside is you can only do one server at a time).

How are you building these servers? If you are using kickstart, you can give static IPs at build time.

You could make them unique based on MAC, or you could always build them with a static IP, and they will all have the same IP until you are done running ansible on them. Better yet make an inventory file in ansible and have it assign static IPs based on hostname or MAC or just about anything.
(Again the down side, is you can only do one at a time)

However once you get the "real" IPs on everything, it would be easy to build an inventory list.

If your network Admin is agreeable, run fping or nmap -sP X.X.X.0/24 against your network.
It will tell you all the IPs and MACs of every device.

Thank you for your comments and suggestions.
I will try to be more detailed.

The DHCP server is basically a PXE server,
Each client that receives an IP address automatically boot to CentOs 8 PXE.

Which dhcp server are you using? dhcpd? dnsmasq?
dhcpd

How many servers are you trying to do at once?
This is random, I have no control over the amount of clients that connect at the same time.
It can be 2 clients and also can be 40 clients.
 

dos2unix

Well-Known Member
Credits
3,006
In this case, if the clients are out of your control, I would set the lease time to a pretty long time.

In your dhcpd.conf file you have something that looks like this...

# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

......................

You probably have a lot more than this, this is just a partial snippet.
But you can change the default-lease-time and max-lease-time.

It sounds like the date and time are off on these servers. So when you set the correct time
the dhcp lease is timing out. (The computer thinks it is a month later, or a year later, or whatever)
so set your lease timeout to something like 5 years or 10 years.

default-lease-time 315360000;
max-lease time 315360000;

So even if the computer thinks a few years have gone by, you're still in the lease.
 

Bennahon

New Member
Credits
29
In this case, if the clients are out of your control, I would set the lease time to a pretty long time.

In your dhcpd.conf file you have something that looks like this...

# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

......................

You probably have a lot more than this, this is just a partial snippet.
But you can change the default-lease-time and max-lease-time.

It sounds like the date and time are off on these servers. So when you set the correct time
the dhcp lease is timing out. (The computer thinks it is a month later, or a year later, or whatever)
so set your lease timeout to something like 5 years or 10 years.

default-lease-time 315360000;
max-lease time 315360000;

So even if the computer thinks a few years have gone by, you're still in the lease.
I also thought of this solution.
But what happened if i run out of addresses..?
There is any option to release the addresses when the test is done?
 

dos2unix

Well-Known Member
Credits
3,006
There are a couple of ways to do this.
The easiest would be to delete the /var/lib/dhcpd/dhcpd.leases file
from time to time. Then do a restart of the dhcpd service.
 


Staff online

Members online


Top