A custom, lightweight authoritative DNS server built with Node.js and TypeScript.
It operates at the Authoritative DNS Server level in the DNS hierarchy, meaning it directly responds to queries for the domains defined in its local zone configuration (zones.json). This project is a fantastic educational tool for understanding how the backbone of the internet works, or for setting up your own local "homelab" environment!
Root DNS Servers
│
▼
TLD Servers
(.com, .org, .net, etc.)
│
▼
Authoritative DNS Server
(This Project)
│
▼
DNS Records
(A, AAAA, CNAME, NS, SOA)
│
▼
Client
(Browser / Device)
- Lightweight & Fast: Built from scratch using
dns-packet. - Supported Records: A, AAAA, NS, SOA, and CNAME records.
- Easy Configuration: Define your domains and records in a simple JSON file (
zones/zones.json). - Homelab Ready: Can be used to hijack local domains for your own internal network.
-
Clone the repository:
git clone https://github.com/01iamysf/DNS-Server.git cd DNS-Server -
Install dependencies:
npm install
-
Build the project (Compile TypeScript to JavaScript):
npm run build
By default, the server runs on Port 5300 so that it doesn't require administrator/root privileges, making it safe and easy to test.
-
Start the server:
npm start
(You can also run
npm run devto hot-reload TypeScript files directly). -
Test it using
dig: Open a new terminal and ask your local server to resolve a domain:dig @127.0.0.1 -p 5300 mysite.dev +short dig @127.0.0.1 -p 5300 ysf.host +short
If you want to use this DNS server exactly like a production server (so your web browser actually uses it to load websites), it must run on Port 53.
Because Port 53 is a protected system port, you must run it with sudo, and you must ensure your operating system isn't already hogging the port (like systemd-resolved on Linux).
-
Start the server on Port 53:
sudo DNS_HOST=127.0.0.1 DNS_PORT=53 $(which node) dist/server.js -
Tell your Operating System to use your server:
- Go to your computer's Wi-Fi / Network Settings.
- Go to the IPv4 settings.
- Turn off "Automatic DNS" and manually enter
127.0.0.1. - Reconnect to your Wi-Fi to apply the change.
-
Browser Troubleshooting:
- DNS over HTTPS (DoH): Modern browsers (like Firefox) encrypt DNS and send it to Cloudflare, ignoring your local server. You must go into Firefox Settings -> DNS -> and turn "Enable DNS over HTTPS" to Off.
- The
.localTrap: Operating systems use mDNS for.localdomains, which bypasses custom DNS servers. If you are testing locally, use the.testTLD in yourzones.json(e.g.,mysite.test) because it is officially reserved for local testing!
To add new domains, simply edit zones/zones.json.
Example of adding a domain that points to your local machine:
{
"name": "mysite.test",
"soa": { ... },
"ns": [ ... ],
"records": {
"@": [
{ "type": "A", "ttl": 300, "address": "127.0.0.1" }
],
"www": [
{ "type": "A", "ttl": 300, "address": "127.0.0.1" }
]
}
}(Remember to restart the DNS server after editing the JSON file!)
Md Yusuf