This repository contains code to build a DNS server in JavaScript (Node.js), inspired by the tutorial at engineerhead/dns-server and engineerhead.github.io/dns-server. The goal is to create a toy DNS server for educational purposes to deepen understanding of the Domain Name System (DNS).
DNS (Domain Name Service) is like the phone book of the Internet. It translates human-readable domain names (e.g., example.com) into numerical IP addresses (e.g., 93.184.216.34) that web browsers use to connect to servers. Before DNS, a centralized file called HOSTS.TXT maintained hostnames and their corresponding IP addresses, which became impractical as the Internet grew. In 1983, Paul Mockapetris created the Domain Name System, which has evolved into the distributed, hierarchical system used today.
This project implements a basic DNS server to handle simple DNS queries, providing a practical way to learn about DNS protocols and networking.
- JavaScript (Node.js) Implementation: A functional DNS server that handles basic DNS queries.
- Simple and lightweight for learning purposes.
To run the Node.js DNS server, ensure you have the following installed:
- Node.js (v14 or higher recommended)
- npm (comes with Node.js)
- Basic understanding of DNS and networking concepts
-
Clone the Repository
git clone https://github.com/amantyagi22/dns-server.git cd dns-server -
Run the DNS Server
This folder contains the code for implementation of a basic authoritative DNS server in Node.js (JavaScript). To run the DNS server:
node index.js
The server will start listening for DNS queries on the default port (e.g., 53 or a custom port if configured). Ensure you have the necessary permissions to bind to port 53 (may require
sudoon some systems).
-
Configure your system or a DNS client to send queries to the server's IP address and port.
-
Query the server using:
dig example.com @127.0.0.1
The server will respond with the IP address for supported domain names based on its internal mapping or configuration.
dns-server/
├── index.js # Main Node.js DNS server implementation
├── parser.js # Parser.js for master file parsing
├── package.json # Node.js dependencies and scripts
├── README.md # This file
└── zones/ # Contains the master file example
- Add support for recursive DNS resolution.
- Enhance the server with caching and more DNS record types (e.g., MX, CNAME).
- Original Tutorial
- Tutorial Website
- DNS-Packet Library for Node.js
- RFC 1035 - Domain Names - Implementation and Specification
Contributions are welcome! Feel free to submit pull requests or open issues for bugs, features, or improvements. Please follow the coding style and include tests where applicable.
- Inspired by engineerhead/dns-server.
- Thanks to Paul Mockapetris for creating the DNS system.
- Built with the help of the open-source community and Node.js ecosystem.