Kiến Thức Linux Tutorial

🛠️ How to Set Up a Local DNS Server with Dnsmasq on Debian 12

Dnsmasq

Dnsmasq is a lightweight and versatile tool that provides DNS forwarding, caching, and DHCP services, making it ideal for small networks. This guide will walk you through the process of installing and configuring Dnsmasq on a Debian 12 system to serve as a local DNS server.


📋 Prerequisites

Before you begin, ensure you have:

  • A Debian 12 system with root or sudo privileges.
  • A static IP address assigned to your server.
  • Basic understanding of Linux command-line operations.

🔄 Step 1: Update System Packages

Start by updating your system’s package index:

sudo apt update -y
sudo apt upgrade -y

Reboot the system if necessary:

sudo reboot

☕ Step 2: Install Dnsmasq

Install Dnsmasq using the following command:

sudo apt install dnsmasq -y

After installation, verify that the Dnsmasq service is running:

sudo systemctl status dnsmasq

🛠️ Step 3: Configure Dnsmasq

Backup the original configuration file:

sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup

Edit the Dnsmasq configuration file:

sudo nano /etc/dnsmasq.conf

Add or modify the following lines to set up Dnsmasq as a local DNS server:

# Listen on the local network interface
interface=eth0
listen-address=127.0.0.1,192.168.1.1

# Enable DNS caching
cache-size=1000

# Don't read /etc/resolv.conf
no-resolv

# Specify upstream DNS servers
server=1.1.1.1
server=8.8.8.8

# Expand hostnames
expand-hosts

# Set the domain for the local network
domain=local.lan

Replace eth0 and 192.168.1.1 with your network interface and server’s IP address, respectively.

Save and close the file.


🔁 Step 4: Configure Local Hostnames

Edit the /etc/hosts file to define local hostnames:

sudo nano /etc/hosts

Add entries like:

192.168.1.10   server1.local.lan server1
192.168.1.11   server2.local.lan server2

Save and close the file.


🔄 Step 5: Restart Dnsmasq

Apply the changes by restarting the Dnsmasq service:

sudo systemctl restart dnsmasq

Enable Dnsmasq to start on boot:

sudo systemctl enable dnsmasq

🔒 Step 6: Configure Firewall

If you have UFW (Uncomplicated Firewall) enabled, allow DNS traffic:

sudo ufw allow 53

Reload UFW to apply the changes:

sudo ufw reload

🧪 Step 7: Test the DNS Server

On a client machine, configure the DNS settings to use the Dnsmasq server’s IP address (e.g., 192.168.1.1).

Test DNS resolution using the dig command:

dig server1.local.lan

You should receive a response with the correct IP address.


✅ Conclusion

You’ve successfully set up a local DNS server using Dnsmasq on Debian 12. This configuration allows for efficient hostname resolution within your local network and can be extended to include DHCP services if needed.


Meta Description: Learn how to install and configure Dnsmasq on Debian 12 to set up a local DNS server. Step-by-step guide with preserved commands for efficient network management.

SEO Keywords: Dnsmasq Debian 12, local DNS server setup, install Dnsmasq Debian, configure Dnsmasq, Debian 12 DNS server

Hướng dẫn cài đặt Cluster Kafka trên Ubuntu

https://forum.congdonglinux.com


Add Comment

Click here to post a comment