kraaakilo

Command Palette

Search for a command to run...

Blog dhcp-dns-setup-basics
networkDECEMBER 10, 2023

DHCP and DNS Configuration: Basics

network

DHCP and DNS Configuration: Basics

This guide explains how to set up DHCP and DNS servers on a Debian-based system. We'll use isc-dhcp-server for dynamic IP address assignment and bind9 for DNS resolution.


1. Setting Up the DHCP Server

1.1 Install the DHCP server

bash

sudo apt update
sudo apt install isc-dhcp-server

1.2 Configure the DHCP Server

Edit the main configuration file:

bash

sudo nano /etc/dhcp/dhcpd.conf

Add the following configuration:

bash

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.140 192.168.1.150;
    option routers 192.168.1.254;
    option domain-name-servers 192.168.1.100;
}
  • range: the IP addresses the server can assign.
  • routers: the default gateway.
  • domain-name-servers: DNS server to use.

1.3 Set the Listening Interface

Edit:

bash

sudo nano /etc/default/isc-dhcp-server

Set the network interface (e.g., eth0, wlan0):

bash

INTERFACESv4="wlan0"

1.4 Restart the DHCP Service

bash

sudo systemctl restart isc-dhcp-server

2. Setting Up the DNS Server (BIND9)

2.1 Install BIND9

bash

sudo apt install bind9 bind9utils bind9-doc -y

2.2 Define a DNS Zone

Edit:

bash

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

Add:

bash

zone "0x3adomain.com" IN {
    type master;
    file "/etc/bind/db.0x3adomain.com";
};

2.3 Create the Zone File

Create the file:

bash

sudo nano /etc/bind/db.0x3adomain.com

Example content:

bash

$TTL    604800
@       IN      SOA     0x3adomain.com. root.0x3adomain.com. (
                          1         ; Serial
                          604800    ; Refresh
                          86400     ; Retry
                          2419200   ; Expire
                          604800    ; Negative Cache TTL
)

@       IN      NS      ns.0x3adomain.com.
@       IN      A       192.168.1.100
ns      IN      A       192.168.1.100

2.4 Restart DNS Services

bash

sudo systemctl restart bind9
sudo systemctl restart systemd-resolved

2.5 Test DNS Resolution

Use dig to test:

bash

dig 0x3adomain.com

If there are errors, review the zone file and check the status of bind9.


Conclusion

You’ve now configured a basic DHCP server for IP assignment and a DNS server for name resolution on Debian. This setup provides a solid base for managing a local network. You can explore advanced options like static leases, reverse zones, or DNSSEC as next steps.

Let's connect

Stay in the loop with my latest projects and insights! Follow me on Twitter to catch all the updates as they happen. Don't miss out on the journey – let's connect and explore the world of tech together. Click to follow now!