# Setting up a DHCP Server on a Cisco Router

### <mark style="color:blue;">**Scenario:**</mark>&#x20;

You are configuring a <mark style="color:red;">**Cisco router as a DHCP server**</mark> to dynamically assign IP addresses to client devices on a local network.

### <mark style="color:blue;">**1. Understanding DHCP**</mark>

DHCP (Dynamic Host Configuration Protocol) automatically assigns <mark style="color:red;">**IP addresses**</mark>, <mark style="color:red;">**subnet masks**</mark>, <mark style="color:red;">**default gateways**</mark>, and other parameters to network devices. A Cisco router can function as a DHCP server, providing these settings to clients.

### <mark style="color:blue;">**2. Practical Scenario**</mark>

* You are setting up a small office network.
* The router will act as a DHCP server.
* The local network uses the **192.168.1.0/24** subnet.
* The router's interface (**FastEthernet0/0**) will be the gateway **192.168.1.1**.
* The DHCP server should assign addresses from **192.168.1.100 to 192.168.1.200**.
* Some devices (like a printer) will need **static IP reservations**.

### <mark style="color:blue;">3. Network Topology</mark>

<figure><img src="/files/2oR3M4hR8ouR7HGq86Um" alt=""><figcaption><p>Topology</p></figcaption></figure>

### <mark style="color:blue;">**4. Configuration Steps**</mark>

#### **Step 1: Enter Global Configuration Mode**

Connect to the router via <mark style="color:red;">**CLI**</mark> (Console, SSH, or Telnet), then enter global configuration mode:

```
R1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#
```

#### **Step 2: Exclude Reserved IP Addresses**

Reserve specific IP addresses that <mark style="color:red;">**should not be assigned**</mark> by DHCP (e.g., for the router, printers, and servers):

```
R1(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.10
```

* **192.168.1.1** is the router’s IP.
* **192.168.1.2 – 192.168.1.10** are reserved for static devices.

#### **Step 3: Create a DHCP Pool**

Define a DHCP pool named <mark style="color:red;">**OFFICE\_NETWORK**</mark>:

```
R1(config)#ip dhcp pool OFFICE_NETWORK
R1(dhcp-config)#
```

#### **Step 4: Define the Network and Subnet Mask**

Specify the subnet for DHCP clients:

```
R1(dhcp-config)#network 192.168.1.0 255.255.255.0
```

#### **Step 5: Set Default Gateway**

Assign the router’s IP as the default gateway:

```
R1(dhcp-config)#default-router 192.168.1.1
```

#### **Step 6: Define the DNS Server**

Specify a DNS server (e.g., Google’s **8.8.8.8**):

```
R1(dhcp-config)#dns-server 8.8.8.8
```

#### **Step 7: Configure the Lease Time**

Set a lease duration (e.g., **24 hours**):

```
R1(dhcp-config)#lease 1 0 0
```

`1 0 0` means **1 day, 0 hours, 0 minutes**.

#### Step 8: Exit the DHCP Configuration

```
R1(dhcp-config)#exit
R1(config)#
```

#### Step9: Assign IP address to **fastEthernet 0/0** (Connected to PC1)

```
R1(config)#interface fastEthernet 0/0
R1(config-if)#ip address 192.168.1.1 255.255.255.0
R1(config-if)#no shutdown
```

#### Step 9: PC1 Configuration

```
PC1> ip dhcp
DORA IP 192.168.1.11/24 GW 192.168.1.1

PC1> show ip

NAME        : PC1[1]
IP/MASK     : 192.168.1.11/24
GATEWAY     : 192.168.1.1
DNS         : 8.8.8.8
DHCP SERVER : 192.168.1.1
DHCP LEASE  : 86395, 86400/43200/75600
MAC         : 00:50:79:66:68:00
LPORT       : 20008
RHOST:PORT  : 127.0.0.1:20009
MTU         : 1500

PC1>
```

#### Step 10: Printer (Static IP)

* Manually set **IP: 192.168.1.2**, **Gateway: 192.168.1.1**.
* Ensure it doesn’t request DHCP.

```
PC2> ip 192.168.1.2/24 192.168.1.1
Checking for duplicate address...
PC2 : 192.168.1.2 255.255.255.0 gateway 192.168.1.1

PC2> show ip

NAME        : PC2[1]
IP/MASK     : 192.168.1.2/24
GATEWAY     : 192.168.1.1
DNS         :
MAC         : 00:50:79:66:68:01
LPORT       : 20010
RHOST:PORT  : 127.0.0.1:20011
MTU         : 1500

PC2>
```

### <mark style="color:blue;">**5. Verifying DHCP Configuration**</mark>

#### **1. Check the DHCP Configuration**

```
R1#show ip dhcp pool

Pool OFFICE_NETWORK :
 Utilization mark (high/low)    : 100 / 0
 Subnet size (first/next)       : 0 / 0
 Total addresses                : 254
 Leased addresses               : 0
 Pending event                  : none
 1 subnet is currently in the pool :
 Current index        IP address range                    Leased addresses
 192.168.1.1          192.168.1.1      - 192.168.1.254     0
R1#
```

This shows the active DHCP pool and available IP addresses.

#### 2. View DHCP Bindings (Leased IPs)

```
R1#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address          Client-ID/              Lease expiration        Type
                    Hardware address/
                    User name
192.168.1.11        0100.5079.6668.00       Mar 23 2025 05:54 AM    Automatic
R1#
```

This displays assigned IP addresses and MAC addresses.

### <mark style="color:blue;">**7. Troubleshooting Commands**</mark>

* Check if the DHCP service is running:

```
R1#show running-config | inclu
R1#show running-config | include dhcp
ip dhcp excluded-address 192.168.1.1 192.168.1.10
ip dhcp pool OFFICE_NETWORK
R1#
```

* Debug DHCP process:

```
R1#debug ip dhcp server events
DHCP server event debugging is on
```

### <mark style="color:blue;">Keywords</mark>

`DHCP`, `Cisco Router`, `IP Address`, `Subnet Mask`, `Default Gateway`, `DNS Server`, `Lease Time`, `Excluded Address`, `DHCP Pool`, `Network Configuration`, `IP Binding`, `DHCP Reservation`, `Dynamic IP`, `Static IP`, `Show Commands`, `Debugging`, `Packet Tracer`, `Network Automation`, `Router Configuration`, `CCNA`, `سیسکو`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://netsec.nerd-cafe.ir/network-engineering/ccna/setting-up-a-dhcp-server-on-a-cisco-router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
