⬆ Click the blue text above to follow our public account
Welcome to Qingping’s Literary World
Let’s witness the growth of a one-person enterprise together

Hello everyone, I am Qingping, a middle-aged boy born in the 90s who loves reading and writing, and understands products and technology.
Today I want to share how to build a DNS service at home.
📝 Introduction
Recently, I migrated my development and testing environment to an old laptop at home (3 units), and to facilitate access, I set up a DNS service. This article shares how to build your own DNS.
PS: Do not attempt to set up a DNS service on the public network, as this requires qualifications~
🧭 Background
In daily development or home networks, we often need to achieve the following goals:
- • Custom naming resolution for LAN devices (e.g.,
<span>home.local</span>) - • Speed up the resolution of certain domestic/intranet domain names, reducing reliance on the public network
- • Implement lightweight ad blocking or custom DNS routing
- • Localize DNS queries to improve response efficiency and save public network traffic (through local caching)
- • Avoid DNS pollution from ISPs (e.g., inability to access GitHub normally)
While options like BIND and CoreDNS are available, they are relatively complex to configure and consume more resources.
In contrast, <span>dnsmasq</span> is a lightweight DNS server that is very suitable for quickly deploying small network services.
🔍 Use Cases
- • Devices within the LAN wish to access each other via domain names
- • Resolve certain domain names (e.g., company intranet, development environment) to local IPs
- • Break ISP DNS pollution
📌 Final Goal
Access various services on the intranet via custom domain names without memorizing IPs.
Accelerate performance when accessing the public network and avoid DNS pollution.
📋 Prerequisites
- • A host with Ubuntu system installed (recommended to use LTS version 24.04 or above)
- • Familiarity with basic Linux operations
🚀 Detailed Steps
1️⃣ Disable <span>systemd-resolved</span> Service
Ubuntu has enabled the <span>systemd-resolved</span> service by default since version 18.04, which manages the system’s DNS query resolution and caching.
This service automatically takes over <span>/etc/resolv.conf</span> and listens on <span>127.0.0.53</span> as a local DNS forwarder.
This conflicts with our <span>dnsmasq</span>, which is superior to <span>systemd-resolved</span> in many aspects, such as supporting custom domain resolution, upstream DNS control, DNS caching, etc. Therefore, we need to disable this service before we start.
Open the terminal and execute the following commands as the <span>root</span> user:
systemctl disable systemd-resolved --now
rm /etc/resolv.conf
echo "nameserver 127.0.0.1" | sudo tee /etc/resolv.conf
2️⃣ Install dnsmasq
Open the terminal and execute the following command to install:
apt update
apt install dnsmasq -y
After installation, dnsmasq will automatically run as a service.
3️⃣ Configure dnsmasq
Edit the main configuration file <span>/etc/dnsmasq.conf</span>:
vim /etc/dnsmasq.conf
Add custom rules at the end of the file, for example:
# LAN resolution
address=/git.home.com/192.168.10.1
# Public GitHub resolution (to avoid DNS pollution and not require each device to configure hosts)
address=/github.com/20.205.243.166
# Local DNS cache expiration time (seconds)
cache-size=1000
# Custom upstream DNS (e.g., Ali DNS, Google DNS)
server=223.5.5.5
server=8.8.8.8
# Include configuration files ending with .conf in the local /etc/dnsmasq.d directory
conf-dir=/etc/dnsmasq.d,.conf
PS: If you want to access GitHub normally, many other domain names also need to be configured for resolution, which I will not list here.
4️⃣ Manage Local Domain Configuration Separately (Optional)
If there are many domains to manage separately, you can create a <span>.conf</span> file in the <span>/etc/dnsmasq.d</span> directory and then add resolutions.
For example, <span>/etc/dnsmasq.d/home.conf</span>:
address=/git.home.com/192.168.10.2
address=/harbor.home.com/192.168.10.1
After modifying, you need to restart the dnsmasq service for the changes to take effect.
5️⃣ Restart dnsmasq and Verify the Service
# Restart the service
systemctl restart dnsmasq
Test local domain resolution:
dig @127.0.0.1 git.home.com +short
or
ping git.home.com
If it prints: 192.168.10.2, it means the resolution was successful.
6️⃣ Configure DNS Address on Other Devices
Here we can directly configure the preferred DNS on the home router, or configure it on each computer individually.
After configuration, most devices will query from this DNS service.
PS: Some advanced routers come with DNS services or can be flashed to OpenWrt, providing graphical management, which is more convenient. However, I am using an older TP-Link model that does not support it, and I am too lazy to mess with OpenWrt, so building one myself is more convenient~
✅ Summary
Deploying a local DNS service quickly using dnsmasq on Ubuntu is very simple and reliable.
We can flexibly configure custom domain names, solve DNS pollution, and implement caching strategies, significantly improving the access experience and efficiency of the LAN.
Compared to bulky traditional DNS services, dnsmasq is an ideal choice for lightweight network environments.
Selected previous articles:
Dynamic Creation of XXL-JOB Tasks: The Ultimate Solution for Automated Scheduling
Complete Guide to Deploying XXL-JOB on Alibaba Cloud ACS: From Database Initialization to Public Service Exposure
Website AI Summary Upgrade Record: Customizing Your Own AI
Quick Look! How doocs editor creates a fast image hosting experience for WeChat public accounts?
Must-read for sole proprietors: A complete guide to applying for WeChat Pay to boost your business!
Understand the difference between WeChat public accounts and service accounts in one article
Author: Qingping Narrative
Long-termist
Passionate about reading and writing, a product enthusiast who understands technology🐶
THE END