Skip to content

A robust, high-performance DNS proxy server written in Go, featuring Redis-based caching, multi-upstream support (IPv4/IPv6), and hot-reloading for development.

License

Notifications You must be signed in to change notification settings

Iktahana/dns-proxy

Repository files navigation

High-Performance DNS Proxy with Redis Caching

Docker Publish Go Version License: MIT Docker Image

A robust, high-performance DNS proxy server written in Go, featuring Redis-based caching, multi-upstream support (IPv4/IPv6), and hot-reloading for development.

Project Structure

.
├── main.go                # Main entry point
├── internal/
│   ├── cache/              # Redis caching logic
│   ├── config/             # Configuration handling
│   └── proxy/              # DNS proxy core logic
├── Dockerfile              # Production Dockerfile
├── Dockerfile.dev          # Development Dockerfile
└── docker-compose.yml      # Orchestration

Features

  • Redis Caching: Automatically caches DNS responses based on the upstream TTL to reduce latency and load.
  • High Performance: Optimized Redis connection pooling and server configuration for extreme throughput.
  • Multi-Upstream Support: Dynamically load up to 10 upstream DNS servers via environment variables. Supports both IPv4 and IPv6.
  • Fault Tolerance: Automatically retries across all configured upstream servers if one fails.
  • Hot Reloading: Developer-friendly setup using air for instant feedback upon code changes.
  • Dockerized: Ready for production and development environments using Docker and Docker Compose.
  • Request Monitoring: Real-time logging of client requests and cache hits.

Prerequisites

  • Docker and Docker Compose
  • Go 1.25+ (if running locally)

Configuration

The application is configured primarily through environment variables or a .env file.

Environment Variables

Variable Description Default
REDIS_ADDR Address of the Redis server localhost:6379
DNS_SERVER_0 ... DNS_SERVER_9 Upstream DNS servers (e.g., 8.8.8.8, 1.1.1.1) -

Note: If no upstream servers are configured, the proxy falls back to Cloudflare DNS (1.1.1.1 and 2606:4700:4700::1111).

Getting Started

Development Mode (with Hot Reload)

This mode mounts your local directory into the container and uses air to recompile the app whenever you save a file.

docker-compose -f docker-compose.dev.yml up --build

Production Mode

Optimized for stability and performance.

docker-compose up -d --build

The DNS proxy will listen on port 53/udp.

Docker Image Release

This project uses GitHub Actions to automatically build and push Docker images to GitHub Packages (GHCR) when a new release is published.

How it works

  1. When you create and publish a new Release on GitHub, the Docker Publish workflow is triggered.
  2. It builds the Docker image and tags it with the release version (e.g., v1.2.3), major/minor versions (1.2), and the commit SHA.
  3. The image is pushed to ghcr.io/${{ github.repository }}.

Usage

To pull the image:

docker pull ghcr.io/<your-username>/dns-proxy:latest

Performance Optimizations

Redis Connection Pool

The Go client is configured with:

  • PoolSize: 100: High concurrency support.
  • MinIdleConns: 10: Keeps persistent connections alive.
  • PoolTimeout: 30s: Prevents blocking under heavy load.

Redis Server

The Redis instance is tuned for caching:

  • Disabled RDB/AOF persistence to maximize I/O throughput.
  • Optimized TCP keepalive for long-lived connections.

License

MIT License

About

A robust, high-performance DNS proxy server written in Go, featuring Redis-based caching, multi-upstream support (IPv4/IPv6), and hot-reloading for development.

Topics

Resources

License

Stars

Watchers

Forks

Packages