> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/linux-server-administrator/servers-configurations-debian/dynamic-host-configuration-protocol-dhcp.md).

# Dynamic Host Configuration Protocol (DHCP)

To install the DHCP server on a Linux-based system, use the following command:

```sh
apt install isc-dhcp-server
```

Specify the network interface to be used by the DHCP server:

```sh
vim /etc/default/isc-dhcp-server
```

Enable and start the DHCP server service with the following commands:

```sh
systemctl enable isc-dhcp-server.service
systemctl start isc-dhcp-server.service
```

#### DHCP Configuration

Modify the DHCP configuration file:

```sh
vim /etc/dhcp/dhcp.conf
```

**IP Address Distribution**

Ensure the authoritative mode is enabled by uncommenting the corresponding line:

```sh
# Search for '# authoritative' and uncomment the line
authoritative;
```

Define the subnet and IP address range:

```sh
subnet <Network_IP_Subnet> netmask 255.255.255.0 {
    range <Start_IP> <End_IP>;
    option routers <Gateway_IP>;
}
```

**Exclusion of Specific IP Addresses**

To exclude specific IP addresses from the DHCP pool:

```sh
subnet <Network_IP_Subnet> netmask 255.255.255.0 {
    range <Start_IP> <End_IP>;
    range <Start_IP> <End_IP>;
    option routers <Gateway_IP>;
}
```

**Reserving an IP Address**

To assign a fixed IP address to a specific device based on its MAC address:

```sh
subnet <Network_IP_Subnet> netmask 255.255.255.0 {
    range <Start_IP> <End_IP>;
    option routers <Gateway_IP>;
}

host <Device_Name> {
    hardware ethernet <MAC_Address>;
    fixed-address <Fixed_IP>;
}
```
