I’ve developed a Command Line Interface (CLI) tool in Go that serves as an Iterative DNS Resolver, allowing users to override default DNS responses using PostgreSQL. This project utilizes the Cobra library to provide various commands for managing custom DNS records and running the DNS server.
I built this CLI to have a personal solution for overriding DNS when needed. One of the aspects I’m most proud of is the custom DNS packet handling over UDP, implemented without relying on pre-built libraries. Implementing iterative lookups was an insightful experience, deepening my appreciation for the intricate process of Name Address Translation.
The tool supports all Resource Record types and Classes but does not implement TTL, as it's unnecessary for our custom DNS database in PostgreSQL.
- Custom DNS Parsing: It does not uses any dns packages available in go and uses the basic net/http package to create UDP DNS Response and read from an UDP connection.
 - Iterative DNS Lookup: Automatically performs iterative DNS resolution by querying root servers, TLD servers, and authoritative servers recursively. Also Caches the Itterative Resolution Rsponse.
 - Custom DNS Records: Override DNS answers with custom entries stored in a PostgreSQL database.
 - Record Management: Add, list, and remove DNS records from the database via CLI commands.
 - Modular Architecture: Separation of concerns with distinct modules for CLI, database interactions, and resolver logic.
 
To utilize the custom DNS records feature, ensure you have a running PostgreSQL instance. You can set this up using Docker:
docker run --name my-postgres-container   -e POSTGRES_USER=postgres   -e POSTGRES_PASSWORD=mypassword   -e POSTGRES_DB=postgres   -p 5432:5432   -d postgres:latestThis command pulls the latest PostgreSQL image from Docker Hub and runs it in a container with the specified environment variables. Learn more about using PostgreSQL with Docker.
./dns-server add --domain example.com --answer 1.2.3.4 --type A./dns-server list./dns-server remove 1./dns-server startBy default, the server listens on 127.0.0.1:53.
You can see my server looksup the AAAA record from internet but because A and TXT record was preset in Database, it fetched from there
The project follows a modular architecture:
dns-server/
├── cmd/
│   ├── add.go
│   ├── delete.go
│   ├── dns.go
│   ├── list.go
│   └── root.go
├── internal/
│   ├── dnsdb/
│   │   └── db.go
│   ├── dnslookup/
│   │   ├── constants.go
│   │   ├── lookup.go
│   │   └── types.go
│   └── dnsproxy/
│       └── dnsproxy.go
├── docs/
│   └── images/
│       ├── db.png
│       ├── image.png
│       └── lookup.png
├── .gitignore
├── dns-server.exe
├── go.mod
├── go.sum
├── main.go
├── Readme.md
└── Tood.md
cmd/: Contains CLI command implementations using Cobra.internal/:dnsdb/: Handles database interactions.dnslookup/: Manages DNS resolution logic.dnsproxy/: Implements DNS proxy functionalities.
docs/: Documentation and related images.main.go: The entry point of the application.
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.