DHCP

Dynamic Host Configuration Protocol (DHCP) is a network protocol used to automatically assign IP addresses and other network configuration settings, such as subnet mask and default gateway, to devices on a network. DHCP enables network administrators to manage and automate the process of IP address assignment, making it more efficient and less error-prone. It allows devices to connect to a network without requiring manual configuration of network settings, simplifying network setup and maintenance. DHCP is widely used in local area networks (LANs) and is a key component of many enterprise networks.

DHCP Client

A DHCP client is a device that requests and obtains an IP address, subnet mask, default gateway, and other network configuration information from a DHCP server. When a DHCP client is connected to a network, it sends a broadcast request message (DHCPDISCOVER) requesting IP configuration information. The DHCP server responds with an offer (DHCPOFFER) containing the requested information. The client then sends a request (DHCPREQUEST) to the server indicating its acceptance of the offered IP configuration. Finally, the server acknowledges (DHCPACK) the request, and the client can begin to use the assigned IP address and network configuration information to communicate on the network.

SoodarOS uses DHCPCD as its DHCP client program to automatically get IP address for interfaces.

DHCP Client Configuration

To configure a DHCP client, you need to enable DHCP on the interface that will receive an IP address from the DHCP server.

ip dhcp client hostname HOSTNAME

The command is used to configure a hostname for a DHCP client. When the router or switch sends a DHCP request, it includes the configured hostname in the request packet. This can be useful for identifying the device on the DHCP server, particularly in large networks with many DHCP clients.

  • HOSTNAME: Specifies the name to be used as the DHCP client hostname.

Note

The default value is the router’s hostname.

ip dhcp client request router

The command is used to configure the device running as a DHCP client to request the IP address of the default gateway (router) from the DHCP server.

By default, the DHCP client requests the IP address of the default gateway from the DHCP server, so the no ip dhcp client request router command can be used to disable this behavior.

Note

When the no form of the command is used, it will deny the provided gateway address.

ip dhcp client request dns-nameserver

Request( deny in case of negating) DNS option from server.

DHCP Server

A DHCP server is a network server that automatically assigns IP addresses and other network configuration parameters to devices on a network, such as subnet mask, default gateway, and DNS servers. It helps simplify network administration by providing a centralized way to manage IP addresses and reduce the likelihood of address conflicts. The DHCP server listens for DHCP requests from clients and responds with the necessary configuration information to enable the client to communicate on the network. DHCP servers are commonly used in home and business networks.

SoodarOS uses Kea DHCP as a backend to provide DHCP server functionalities. These functionalities include:

  • Add IP pools and define subnet and IP ranges to allocate to hosts

  • Provide clients DNS server addresses

  • Provide clients gateway address

  • Provide clients NTP server addresses

  • Set leasing time for each pool

  • Show/Clear bindings

Configuring Pool

ip dhcp pool DHCP4POOL

The command is used to configure a DHCP (Dynamic Host Configuration Protocol) server pool for IPv4 addresses. When configuring a DHCP pool, the network administrator defines a pool of IP addresses that can be assigned dynamically to clients requesting an IP address from the DHCP server. This command is used to create the pool and configure various parameters for the pool such as subnet mask, default gateway, DNS server, lease duration, and more.

  • DHCP4POOL: Specifies the pool name.

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)#
network A.B.C.D/M

In DHCP pool configuration, the network command is used to specify the network address and the prefix length of the IP address pool to be assigned to DHCP clients. The syntax of this command is as follows:

  • A.B.C.D/M: Specifies the pool prefix address.

For example, to configure a DHCP pool with the network address of 192.168.1.0/24, the command would be:

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# network 192.168.1.0/24

This command tells the DHCP server that it should assign IP addresses within the 192.168.1.0/24 network to DHCP clients.

included-address A.B.C.D A.B.C.D

The command is used to specify a range of addresses that could be used for allocating to clients from the subnet. By default, every IP in the pool subnet is available to offer by DHCP Server and, to change this behavior one should set the included address ranges.

Each pool can have multiple included-address commands.

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# network 192.168.1.0/24
soodar(dhcp-config)# included-address 192.168.1.100 192.168.1.120
soodar(dhcp-config)# included-address 192.168.1.140 192.168.1.165
dns-server A.B.C.D ...

The dns-server command is used to specify the IP address of a Domain Name System (DNS) server for a DHCP pool. When a DHCP client receives an IP address from the pool, the DNS server information is also provided so that the client can perform name resolution using DNS.

  • A.B.C.D ...: represents the IP address of a DNS server. Multiple IP addresses can be specified in a single command or by adding additional dns-server commands.

Note

Up to 8 DNS servers can be set. It is not allowed to set up more than 8 servers.

Example:

Following lines set 1.1.1.1, 4.2.2.4 and 8.8.8.8 as DNS servers:

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# dns-server 4.2.2.4 1.1.1.1
soodar(dhcp-config)# dns-server 8.8.8.8
default-router A.B.C.D ...

The command is used in DHCP pool configuration mode to specify the default gateway IP address to be assigned to DHCP clients.

  • A.B.C.D ...: Specifies the IP address of the default gateway to be used by DHCP clients. Multiple default-router commands can be used in the same DHCP pool configuration to specify multiple default gateway IP addresses.

Note

Up to 8 gateway can be set. It is not allowed to set more than 8 addresses.

For example, to configure a DHCP pool with a default gateway of 192.168.1.1, the following command would be used:

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# default-router 192.168.1.1
ntp-server NTP ...

The ntp-server command is used to specify the IP address of the Network Time Protocol (NTP) server in a DHCP pool configuration. The NTP server provides accurate time information to clients on the network.

  • NTP: Specifies the IP address or name of the NTP server.

Note

Up to 8 NTP servers can be set. It is not allowed to set more than 8 servers.

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# ntp-server ir.pool.ntp.org
domain-name NAME

Specifies the domain name for clients

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# domain-name example.org
lease <(0-365)$days (0-23)$hours (0-59)$minutes|infinite>

The lease command is used in a DHCP pool configuration to specify the lease duration for DHCP clients. The lease duration specifies the amount of time that a client can use an assigned IP address before the lease expires and the client must request a new IP address assignment.

  • days: Specifies the number of days in the lease duration (0-365).

  • hours: Specifies the number of hours in the lease duration (0-23).

  • minutes: Specifies the number of minutes in the lease duration (0-59).

  • infinite: Specifies an infinite lease duration, which means that the IP address assignment will never expire unless manually revoked.

For example, to configure a lease duration of 7 days and 12 hours, you would use the following command:

soodar(config)# ip dhcp pool p1
soodar(dhcp-config)# lease 7 12 0

Note

Default lease time is 1 day.

Configure interfaces

ip dhcp server

The ip dhcp server command is used to enable the device to act as a DHCP server.

When this command is executed, the device starts to listen on the interface for incoming DHCP requests from clients. If a client request is received, the DHCP server will assign an IP address, subnet mask, default gateway, and other options (such as DNS servers and NTP servers) to the requesting client.

It should be noted that additional configuration is required to configure the DHCP server, such as defining DHCP pools, specifying options to be assigned to clients, and configuring DNS and NTP servers.

soodar(config-if)# ip dhcp server
ip address dhcp

The ip address dhcp command is used to obtain an IP address dynamically through DHCP (Dynamic Host Configuration Protocol) from a DHCP server.

When this command is used on an interface, the router will act as a DHCP client and request an IP address from a DHCP server. The DHCP server will assign an IP address along with other network settings, such as subnet mask, default gateway, and DNS server address, to the device.

Pool status and management

show ip dhcp pool

Show general information about a pool(s)

soodar# show ip dhcp pool p1

Pool p1 :
 Total addresses: 47
 Leased addresses:        1
 Declined addresses:      0
 2 ranges are currently in the pool :
 Range's low       Range's high
 192.168.1.100     192.168.1.120
 192.168.1.140     192.168.1.165
show ip dhcp binding [<DHCP4POOL|A.B.C.D>]

The show command is used to display information about DHCP bindings on the device. It can be used with or without a specific pool name or client IP address.

  • DHCP4POOL: (Optional) Specifies the DHCP pool name for which to display the bindings.

  • A.B.C.D: (Optional) Specifies the IP address of the DHCP client for which to display the binding.

If a pool name or client IP address is specified, the command displays information about the bindings for that specific entity. If no parameters are given, the command displays information about all DHCP bindings on the device.

soodar# show ip dhcp binding
  IP Address   Client hostname   Client HW address   Lease expiration           Pool   Type        State
  1.1.1.100    n4                00:00:00:aa:00:01   Wed Nov  3 11:20:06 2021   p2     Automatic   Leased

In the above example, the command output displays the IP address, client ID or hardware address, lease expiration time, and the type of the DHCP binding.

clear ip dhcp binding <*|A.B.C.D>

The command is used to remove a DHCP address binding from the DHCP server database.

  • *: Specifies to clear all DHCP address bindings

  • A.B.C.D: Specifies the IP address of the client whose DHCP address binding is to be cleared

Note that clearing a DHCP address binding will release the IP address back to the address pool, allowing it to be assigned to another client.

soodar# clear ip dhcp binding *