#linux #dhcp #dhcpserver #lease #leases
*26-07-2025 isc dhcp server will end of life soon. So, the use of #keadhcpserver : [[DHCP Server KEA DHCP]] is recommended.*
### **Viewing Active IP Leases in an ISC DHCP Server**
To check which **IP addresses are currently in use** on an **ISC DHCP Server**, follow these steps:
---
### **1. Locate the DHCP Lease File**
The **ISC DHCP Server** stores lease information in a file. On most systems, this file is located at:
`/var/lib/dhcp/dhcpd.leases`
---
### **2. View the Lease File**
To inspect all recorded leases, run:
`cat /var/lib/dhcp/dhcpd.leases`
This will display **all** lease records, including **expired, released, and active leases**.
---
### **3. Filter Only Active Leases**
To find **only active leases**, use:
`grep "lease " /var/lib/dhcp/dhcpd.leases | grep -B 1 "binding state active"`
- The output will show **IP addresses** and their **status**.
- Each lease includes:
- **IP address**
- **MAC address**
- **Lease times**
- **Binding state (e.g., active)**
---
### **4. Automate the Process with a Script**
If you frequently check for active leases, you can create a simple **Bash script** to automate it.
#### **Example: Script to List Active Leases**
```
#!/bin/bash
echo "Active DHCP Leases:"
grep "lease " /var/lib/dhcp/dhcpd.leases | grep -B 1 "binding state active"
```
Save this as **`check-leases.sh`**, then make it executable:
`chmod +x check-leases.sh`
Run it anytime with:
`./check-leases.sh`
---
### **5. Generate a More Readable Report**
For a **clearer overview**, use **`awk`** to extract **IP addresses and MAC addresses**:
`awk '/lease / {ip=$2} /hardware ethernet/ {print ip, $3}' /var/lib/dhcp/dhcpd.leases`
This will output:
```
192.168.1.100 00:1A:2B:3C:4D:5E
192.168.1.101 11:22:33:44:55:66
```
---
🚀 **With these steps, you can efficiently check which IP addresses are assigned and in use on your DHCP server!**
Zie ook [[DHCP Server ISC, Installing Configuring]]
Zie ook [[DHCP Server ISC, Reserve IP Address]]
Zie ook [[DHCP Server ISC, Stop and Start]]
Zie ook [[Windows, DHCP Server Export and Import, PowerShell]]