Blog dhcp-and-dns-configuration-basics
networkDECEMBER 10, 2023

DHCP and DNS Configuration : Basics

kraaakilo's avatar

DHCP and DNS Configuration : Basics

Embark on a journey into the intricate realms of networking as we delve into the art of configuring DHCP and DNS servers. In this guide, we'll navigate through the installation and configuration of isc-dhcp-server for dynamic IP address allocation and bind9 for authoritative DNS resolution on based Debian distros. Buckle up as we unravel the mysteries behind subnetting, IP ranges, and zone files, all while ensuring your network sails smoothly through the vast ocean of data. Let's dive into this world!

✨ DHCP Server Configuration:

Install isc-dhcp-server

At a terminal prompt, enter the following command to install isc-dhcp-server:

apt install isc-dhcp-server

Add configuration to isc-dhcp-server in /etc/dhcp/dhcpd.conf.

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 sets the range of values that will be used by the dhcp server.
}

This configuration defines a subnet for the DHCP server. Here's a detailed explanation:

  • subnet 192.168.1.0 netmask 255.255.255.0: Defines the subnet with a starting IP address of 192.168.1.0 and a subnet mask of 255.255.255.0.
  • range 192.168.1.140 192.168.1.150;: Specifies the range of IP addresses that the DHCP server can assign to clients, from 192.168.1.140 to 192.168.1.150.
  • option routers 192.168.1.254;: Indicates the default gateway that clients should use, in this case, 192.168.1.254.
  • option domain-name-servers 192.168.1.100;: Sets the IP address of the DNS server that clients should use to resolve domain names, in this case, 192.168.1.100.

You also may need to edit /etc/default/isc-dhcp-server to specify the interfaces dhcpd should listen to.

INTERFACESv4="wlan0"

After changing the config files, restart the dhcpd service:

systemctl restart isc-dhcp-server.service

✨ DNS Server Configuration (BIND):

Install bind9 and utilities.

apt install bind9 bind9utils bind9-doc -y

Edit the named.conf.local file to add the configuration for the new zone.

zone "example.com" IN {
    type master;
    file "/etc/bind/example.com";
};

Add the zone definition to the file with nano.

nano /etc/bind/example.com

; BIND data file for example.com
$TTL    604800
@       IN      SOA     example.com. root.example.com. (
                          1         ; Serial
                          604800    ; Refresh
                          86400     ; Retry
                          2419200   ; Expire
                          604800    ; Negative Cache TTL
)

@       IN      NS      ns.example.com.
@       IN      A       192.168.1.100 ; Desired IP
ns      IN      A       192.168.1.100 ; Desired IP

This configuration is intended for the "example.com" zone in the BIND DNS server. Here's a detailed explanation:

  • zone "example.com" IN {...};: Defines a zone with the domain name "example.com" and specifies that it is a master server.
  • The following configuration block specifies details of the data file for the "example.com" zone.
  • $TTL 604800: Sets the default time-to-live (TTL) for records to 604800 seconds (one week).
  • @ IN SOA example.com. root.example.com. (...): Defines the Start of Authority (SOA) for the zone.
  • @ IN NS ns.example.com.: Specifies that the primary DNS server for this zone is "ns.example.com".
  • @ IN A 192.168.1.100: Associates the IP address 192.168.1.100 with the domain "example.com".
  • ns IN A 192.168.1.100: Associates the IP address 192.168.1.100 with the domain name "ns.example.com".

This configuration is designed to allow the DNS server to respond to queries for the "example.com" zone and associates this zone with a specific IP address (192.168.1.100) and a specific DNS server ("ns.example.com").

After changing the config files, restart the bind9 and systemd-resolved service:

systemctl restart bind9
systemctl restart systemd-resolved

Test your domain with:

dig example.com

If any errors occur, recheck all steps, and ensure that all services are running and not blocked by a firewall.

PS: Make your configuration work better by adding the DNS and DHCP server things to your computer or the whole internet box.

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!