This is a minimal authoritative DNS server implementation in Go. It parses DNS master zone files into ResourceRecord structs, then decodes DNS messages and replies with the correct records.
-
Go 1.21+
-
A zone file (e.g., ./zones/example.com.zone)
-
dig (from bind9-dnsutils/bind-utils) and CLI tool for testing
# 1) Clone & prepare
git clone https://github.com/c0d_0x/mimidns
cd mimidns
# 2) run
go run ./cmd/mimidns
# 3) Build
make
# 4) Run the server
./mimidns -h # or
#OUTPUT:
# Usage of ./mimidns:
# -p string
# specify the port to run the server (default "3000")
# -zones string
# <path> specify zones' directory (default "zones")Parse zone/master files into Go structs.
Handle DNS Header, Query, Answer sections.
Reply to client requests with matching records.
Lightweight, hackable, and easy to extend.
Zone files (master files) are converted into this internal structure:
type ResourceRecord struct {
Name string
TTL int
Class string
Type string
RData []string
}Incoming messages are decoded into headers, questions, and answers.
//Header
type Header struct {
ID uint16
FLAG [2]byte
QDCOUNT uint16
ANCOUNT uint16
NSCOUNT uint16
ARCOUNT uint16
}
//Question
type Query struct {
NAME string
TYPE MessageType
CLASS MessageClass
}
// Answer
type Answer struct {
NAME string
TYPE MessageType
CLASS MessageClass
TTL uint32
RDLENGTH uint16
RDATA []string
}
// Full Message
type Message struct {
MHeader Header
Question []Query
Answer []Answer
Authority []Answer
Additional []Answer
} $ORIGIN example.com.
$TTL 3600
@ IN A 192.0.2.1
@ IN NS ns1.example.com.Load the zone file, listen for queries, and serve responses.
dig @127.0.0.1 -p 5353 example.com A
#Response should return:
example.com. 3600 IN A 192.0.2.1
This project is built as a learning tool first. Feel free to fork, experiment, and open issues or PRs!