In network management, DHCP (Dynamic Host Configuration Protocol) and DNS (Domain Name System) play a crucial role in ensuring that devices on the network function properly. DHCP simplifies network management by dynamically assigning IP addresses to devices, while DNS translates domain names into IP addresses, making it easier for users to access network resources.

This document explains how to set up and configure DHCP and DNS servers on a Linux system. Both servers help network administrators manage network configurations more efficiently.

Setting Up a DHCP Server

1. Installing the DHCP Server Software

On Linux, the ISC DHCP Server is commonly used for DHCP services. Below are the steps to install it on Debian/Ubuntu and CentOS/RHEL-based systems.

Debian/Ubuntu:

sudo apt update
sudo apt install isc-dhcp-server

CentOS/RHEL:

sudo yum install dhcp

Once the installation is complete, the DHCP service can be started.

2. Configuring the DHCP Server

The isc-dhcp-server configuration file is located in /etc/dhcp/dhcpd.conf. This file controls how the DHCP server behaves.

To edit the configuration file, use the following command:

sudo nano /etc/dhcp/dhcpd.conf

Here is a simple example of a DHCP configuration:

# DHCP Configuration File
# Define the IP range for the subnet
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.100 192.168.1.200;  # IP address range
  option routers 192.168.1.1;         # Gateway IP address
  option domain-name-servers 8.8.8.8, 8.8.4.4;  # DNS servers
  default-lease-time 600;             # Default lease time
  max-lease-time 7200;                # Maximum lease time
}

This configuration assigns IP addresses between 192.168.1.100 and 192.168.1.200 within the 192.168.1.0/24 network and sets 192.168.1.1 as the gateway with Google's DNS servers.

3. Starting the DHCP Server

After configuring the server, you can restart the DHCP service using the following commands:

sudo systemctl restart isc-dhcp-server
sudo systemctl enable isc-dhcp-server

To check the status of the service:

sudo systemctl status isc-dhcp-server

4. Testing the DHCP Server

To verify that the DHCP server is working, check if a client on your network receives an IP address. You can do this by restarting the network interface or using the dhclient command:

sudo dhclient

This command allows the client to request a new IP address from the DHCP server.

Setting Up a DNS Server

DNS is responsible for resolving domain name queries into IP addresses for networked devices. BIND (Berkeley Internet Name Domain) is the most commonly used DNS server software on Linux systems. BIND can be used to handle both local DNS queries and external DNS resolution.

1. Installing the BIND DNS Server

Debian/Ubuntu:

sudo apt update
sudo apt install bind9 bind9utils bind9-doc

CentOS/RHEL:

sudo yum install bind bind-utils

Once the installation is complete, the BIND service can be started.

2. Configuring BIND

The main configuration file for BIND is /etc/bind/named.conf or /etc/named.conf. This file is where you define which networks the DNS server will serve.

To edit the configuration file, use:

sudo nano /etc/bind/named.conf.local

Here is an example of a basic DNS configuration:

# Local network DNS configuration

zone "mydomain.local" {
    type master;
    file "/etc/bind/db.mydomain.local";
};
zone "1.168.192.in-addr.arpa" {
    type master;
    file "/etc/bind/db.192.168.1";
};

This example sets up a zone for mydomain.local and a reverse zone for reverse DNS (PTR) queries.

3. Creating Zone Files

You also need to create zone files for domain name resolution and reverse DNS lookups. For example, create a zone file for mydomain.local:

sudo nano /etc/bind/db.mydomain.local

The contents of the file might look like this:

$TTL 86400
@   IN  SOA  ns1.mydomain.local. root.mydomain.local. (
            20220101    ; Serial
            3600        ; Refresh
            1800        ; Retry
            1209600     ; Expire
            86400 )     ; Minimum TTL

    IN  NS  ns1.mydomain.local.
ns1 IN  A   192.168.1.1
www IN  A   192.168.1.2

This file defines an NS record for the nameserver and an A record for the www subdomain.

To add reverse DNS records, create a file for the reverse zone:

sudo nano /etc/bind/db.192.168.1

The file might look like this:

$TTL 86400
@   IN  SOA  ns1.mydomain.local. root.mydomain.local. (
            20220101    ; Serial
            3600        ; Refresh
            1800        ; Retry
            1209600     ; Expire
            86400 )     ; Minimum TTL
    IN  NS  ns1.mydomain.local.
1   IN  PTR ns1.mydomain.local.
2   IN  PTR www.mydomain.local.

4. Starting the BIND Server

After completing the configuration, you can restart the BIND service with the following commands:

sudo systemctl restart bind9
sudo systemctl enable bind9

To check the status of the service:

sudo systemctl status bind9

5. Testing the DNS Server

To test if your DNS server is functioning correctly, use the dig or nslookup commands.

For example, to query the mydomain.local domain using dig:

dig @192.168.1.1 mydomain.local

This command queries the DNS server at 192.168.1.1 for the mydomain.local domain.