When you need to ensure a specific device always receives the same IP address from your DHCP server, you'll want to create a static lease (sometimes called a DHCP reservation). This is particularly useful for servers, network devices, or any equipment that requires consistent IP addressing while still benefiting from DHCP management.
The basic structure in dhcpd.conf should look like this:
host client-hostname {
hardware ethernet 00:1a:2b:3c:4d:5e;
fixed-address 192.168.1.100;
}
If your static lease isn't working, check these aspects:
- The MAC address format must use lowercase letters and colons (00:1a:2b...)
- The IP address must be outside your dynamic pool range
- Run
dhcpd -t
to test configuration before restarting - Check logs with
journalctl -u isc-dhcp-server
ortail -f /var/log/syslog
Here's a full dhcpd.conf snippet showing both dynamic and static configurations:
option domain-name "example.com";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.199;
option routers 192.168.1.1;
# Static lease for NAS device
host nas {
hardware ethernet 00:1a:2b:3c:4d:5e;
fixed-address 192.168.1.10;
}
# Static lease for printer
host office-printer {
hardware ethernet 00:1c:42:a7:b3:21;
fixed-address 192.168.1.20;
}
}
You can extend static leases with additional parameters:
host security-camera {
hardware ethernet 00:0d:b9:45:fc:2a;
fixed-address 192.168.1.30;
option host-name "front-gate-cam";
option domain-name "security.example.com";
default-lease-time 86400; # 24 hours
}
If your device still receives random IPs:
- Verify the MAC address is correct with
ip link
orifconfig
- Ensure there are no duplicate host declarations
- Check for conflicting fixed-address assignments
- Restart both DHCP server and client:
systemctl restart isc-dhcp-server
- On client:
dhclient -r && dhclient
In ISC DHCP server (dhcpd), the proper way to assign a fixed IP address based on MAC address requires several configuration elements:
host workstation1 {
hardware ethernet 00:1a:2b:3c:4d:5e; # Client's MAC address
fixed-address 192.168.1.100; # The static IP to assign
option host-name "dev-pc1"; # Optional hostname assignment
}
Several factors could cause your static assignment to fail:
# Incorrect example that might not work:
host blah {
hardware ethernet ;
fixed-address ;
# Missing closing semicolon or wrong subnet declaration
}
Here's a full dhcpd.conf snippet that works:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.150;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
host developer-pc {
hardware ethernet 00:1a:2b:3c:4d:5e;
fixed-address 192.168.1.42;
option host-name "dev-machine";
}
}
After making changes:
- Run
sudo dhcpd -t
to test configuration - Check logs:
journalctl -u isc-dhcp-server -f
- Verify lease file:
/var/lib/dhcp/dhcpd.leases
You can extend this with additional DHCP options:
host voip-phone {
hardware ethernet 00:24:01:ab:cd:ef;
fixed-address 192.168.1.200;
option tftp-server-name "192.168.1.10";
option bootfile-name "pxelinux.0";
}