I am using DHCP server on centOS 6.5, I reserved an IP for specific MAC address
my config file /etc/dhcp/dhcpd.conf
option domain-name-servers 192.168.1.5, 8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.90 192.168.1.250; option routers 192.168.1.1;
}
host specialPC { hardware ethernet 00:16:3e:8a:30:f1; fixed-address 192.168.1.90;
}My problem is when specialPC is shutdown the DHCP server uses it's IP "192.168.1.90" I mean if a device connect to the network the DHCP server sometime gives the reserved IP "192.168.1.90" to the device and, when this scenario happens, the specialPC when startup it can't get its IP from DHCP.
Is that normal? I think there is something wrong.
32 Answers
The behavior you are seeing is expected.
The subnet declaration with its range specifies a range which the DHCP server is free to handle as it pleases. See the documentation, page 21, Subnets.
The host declaration specifies a host that should have specific settings (IP address, in this case).
The easy fix is to change either the dynamic range or the IP address for specialPC such that they do not overlap. Changing the start of the range to .91 rather than .90 should do this nicely, and prevent conflicts.
I believe, but cannot find this in the documentation, that you can also put the host declaration inside the subnet declaration, which should prevent conflicts.
I beg to differ from Michael Kjörling. The Linux manual for the dhcpd.conf file explicitly states:
Reserved Leases
It's often useful to allocate a single address to a single client, in approximate perpetuity. Host statements with fixed-address clauses exist to a certain extent to serve this purpose, but because host statements are intended to approximate 'static configuration', they suffer from not being referenced in a littany of other Server Services, such as dynamic DNS, failover, 'on events' and so forth.
If a standard dynamic lease, as from any range statement, is marked 'reserved', then the server will only allocate this lease to the client it is identified by (be that by client identifier or hardware address).
In practice, this means that the lease follows the normal state engine, enters ACTIVE state when the client is bound to it, expires, or is released, and any events or services that would normally be supplied during these events are processed normally, as with any other dynamic lease. The only difference is that failover servers treat reserved leases as special when they enter the FREE or BACKUP states - each server applies the lease into the state it may allocate from - and the leases are not placed on the queue for allocation to other clients. Instead they may only be 'found' by client identity. The result is that the lease is only offered to the returning client.
The key point is at the end, let me repeat it:
...and the leases are not placed on the queue for allocation to other clients. Instead they may only be 'found' by client identity. The result is that the lease is only offered to the returning client.
Thus I believe there is indeed something wrong with the situation described by motaz, for exactly what he said in the comment to Michael Kjörling's answer. Speaking out of experience, I have several pcs, with reserved addresses within the lease range, but I have never experienced such problems as those denounced by motaz.
So, now my suggestion to motaz:
Add this line
infinite-is-reserved on;
to the configuration file;
change your host declaration as
host SpecialPC { hardware ethernet 00:16:3e:8a:30:f1; fixed-address 192.168.1.90; min-lease-time 2147483647 ; max-lease-time 2147483647 ; }
This just follows the above-mentioned manual, which states:
4The infinite-is-reserved statement
infinite-is-reserved flag;
ISC DHCP now supports 'reserved' leases. See the section on RESERVED LEASES below. If this flag is on, the server will automatically reserve leases allocated to clients which requested an infinite (0xffffffff) lease-time.
The default is off.