A lightweight DNS server implementation written in Go.
This DNS server provides basic DNS functionality, including:
- UDP-based DNS message handling
- Support for standard DNS queries
- Lightweight and containerized deployment
├── Dockerfile # Docker configuration for containerization
├── go.mod # Go module dependencies
├── Makefile # Build automation
├── cmd/ # Command-line entrypoints
│ └── dns/ # Main DNS server binary
│ └── main.go # Entry point for the DNS server
└── pkg/ # Core DNS implementation
├── answer.go # DNS answer section handling
├── dns.go # Core DNS functionality
├── flags.go # DNS flag handling
├── header.go # DNS header implementation
├── question.go # DNS question section handling
└── server.go # Server implementation
- Go 1.18+ (or Docker for containerized use)
- Make (optional, for using the provided Makefile)
Clone the repository and build the server:
# Build the binary
make build
# Run tests
make test
# Format the codebase
make fmt# Using make
make run
# Or run the binary directly
./dist/dnsThe server will start listening for DNS queries on localhost (127.0.0.1) port 2053 by default.
make docker-build
# or
docker build -t dns .make docker-run
# or
docker run -p 2053:2053/udp dnsYou can test your DNS server using tools like dig:
dig @127.0.0.1 -p 2053 example.com- Modify the code in the
pkg/directory for DNS functionality - Use
make testto verify your changes work as expected - Use
make fmtto format the code according to Go standards
MIT License - Feel free to use and modify this code for your own projects.
This project is created as a learning exercise to understand DNS protocols and Go network programming.