DNS Name Server (Go)
Simple UDP DNS responder written in Go. It listens on port 53 and answers A (IPv4) queries for a few hard-coded names (for now).
Requirements
- Go 1.25+
Build
make build
# outputs ./nsRun Port 53 is privileged; run with sudo or grant the binary the capability:
# Option 1: run as root
sudo ./ns
# Option 2: allow binding to low ports, then run normally
sudo setcap 'cap_net_bind_service=+ep' ./ns
./nsWhat it does
- Listens on UDP :53
- Supports only IN A questions
- Answers using an in-memory map:
- example.com. -> 1.2.3.4
- localhost. -> 5.6.7.8
- test.local. -> 8.9.1.2
- Returns NXDOMAIN for other names/types
Quick test In another shell after starting the server:
dig @127.0.0.1 example.com A +short
dig @127.0.0.1 localhost A +short
dig @127.0.0.1 test.local A +shortProject layout
- cmd/main.go: starts the UDP server on :53
- internal/dns/handler.go: decodes queries and builds responses
- pkg/utils/utils.go: DNS message pack/unpack helpers