Skip to content
Β 
Β 

Repository files navigation

IPv6 Auto PTR DNS Server

Python 3.13 License: Apache 2.0 Docker

A modern, lightweight DNS server designed to automatically generate IPv6 PTR (reverse DNS) records on-the-fly. Perfect for ISPs, hosting providers, and network administrators who need dynamic reverse DNS for IPv6 subnets.

πŸš€ Features

  • Automatic PTR Generation: Dynamically creates PTR records for any IPv6 address within configured subnets
  • Custom PTR Records: Support for custom PTR mappings via configuration files
  • Multi-Protocol: Supports both UDP and TCP DNS protocols
  • High Performance: Multi-threaded architecture with configurable worker pools
  • Enterprise Configuration: YAML configuration files with environment variable support
  • Docker Ready: Production-ready containerization with security hardening
  • IPv6 Native: Built specifically for IPv6 with full dual-stack support
  • Zero Downtime Config: Hot-reload configuration without service restart

Note: This DNS server is specialized for IPv6 PTR records only. It cannot handle other DNS record types by design.

πŸ“‹ Requirements

  • Python: 3.13+ (tested and optimized)
  • Dependencies: dnslib, pyyaml (see requirements.txt)
  • Network: IPv6-enabled network interface
  • Permissions: Ability to bind to DNS port (53) or configured port

⚑ Quick Start

Using Python (Development)

# Clone the repository
git clone https://github.com/uppaljs/ipv6autoptr.git
cd ipv6autoptr

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Configure your subnets in config.yaml
# Edit config.yaml to set your IPv6 subnets and domain

# Run the server
python ipv6autoptr.py --udp --port 5353 --verbose

Using Docker (Production)

# Quick start with Docker
docker run -d \
  --name ipv6autoptr \
  -p 53:53/udp \
  -e IPV6AUTOPTR_DOMAIN_SUFFIX="ip6.yourdomain.com." \
  -e IPV6AUTOPTR_SUBNETS="2001:db8:1000::/48,2001:db8:2000::/64" \
  uppal/ipv6autoptr:latest

# Or use docker-compose for full setup
docker-compose up -d

πŸ”§ Configuration

The server supports multiple configuration methods with the following priority order:

  1. Command Line Arguments (highest priority)
  2. Environment Variables (IPV6AUTOPTR_* prefix)
  3. Configuration File (config.yaml)
  4. Built-in Defaults (lowest priority)

Configuration File (config.yaml)

# Server Configuration
server:
  port: 53
  bind_address: "::"
  enable_udp: true
  enable_tcp: false
  verbose: 1

# DNS Configuration
dns:
  ttl: 86400
  domain_suffix: "ip6.yourdomain.com."
  max_workers: 32

# IPv6 Subnets
ipv6:
  subnets:
    - "2001:db8:1000::/48"
    - "2001:db8:2000::/64"

# Custom PTR Records
ptr_records:
  config_file: "ipv6autoptr.conf"
  use_custom: true

# Logging
logging:
  level: "INFO"
  format: "%(asctime)s - %(levelname)s - %(message)s"
  file: null

Environment Variables

Perfect for Docker and Kubernetes deployments:

IPV6AUTOPTR_PORT=53
IPV6AUTOPTR_BIND_ADDRESS="::"
IPV6AUTOPTR_DOMAIN_SUFFIX="ip6.yourdomain.com."
IPV6AUTOPTR_SUBNETS="2001:db8:1000::/48,2001:db8:2000::/64"
IPV6AUTOPTR_TTL=86400
IPV6AUTOPTR_VERBOSE=1
IPV6AUTOPTR_MAX_WORKERS=32

See CONFIGURATION.md for complete configuration reference.

🐳 Docker Deployment

Basic Docker Run

docker run -d \
  --name ipv6autoptr \
  --restart unless-stopped \
  -p 53:53/udp \
  -p 53:53/tcp \
  -e IPV6AUTOPTR_DOMAIN_SUFFIX="ip6.example.com." \
  -e IPV6AUTOPTR_SUBNETS="2001:db8:1000::/48" \
  -e IPV6AUTOPTR_VERBOSE=1 \
  uppal/ipv6autoptr:latest

Production Docker Compose

version: '3.8'
services:
  ipv6autoptr:
    image: ghcr.io/uppaljs/ipv6autoptr:latest
    container_name: ipv6autoptr
    restart: unless-stopped
    ports:
      - "53:53/udp"
      - "53:53/tcp"
    environment:
      - IPV6AUTOPTR_PORT=53
      - IPV6AUTOPTR_DOMAIN_SUFFIX=ip6.yourdomain.com.
      - IPV6AUTOPTR_SUBNETS=2001:db8:1000::/32
      - IPV6AUTOPTR_VERBOSE=1
      - IPV6AUTOPTR_TTL=3600
    volumes:
      - ./custom-ptr-records.conf:/app/ipv6autoptr.conf:ro
    networks:
      - dns_network
    cap_drop:
      - ALL
    cap_add:
      - NET_BIND_SERVICE
    read_only: true
    tmpfs:
      - /tmp

Kubernetes Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ipv6autoptr
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ipv6autoptr
  template:
    metadata:
      labels:
        app: ipv6autoptr
    spec:
      containers:
      - name: ipv6autoptr
        image: ghcr.io/uppaljs/ipv6autoptr:latest
        ports:
        - containerPort: 53
          protocol: UDP
        env:
        - name: IPV6AUTOPTR_DOMAIN_SUFFIX
          value: "ip6.yourdomain.com."
        - name: IPV6AUTOPTR_SUBNETS
          value: "2001:db8:1000::/32"

πŸ“Š How It Works

Automatic PTR Generation

When a PTR query is received for an IPv6 address:

  1. Parse: Extract IPv6 address from ip6.arpa query
  2. Validate: Check if address is within configured subnets
  3. Lookup: Check for custom PTR record in config file
  4. Generate: Create automatic PTR record if no custom mapping exists
  5. Respond: Return PTR response with configured TTL

Example Queries and Responses

# Query for 2001:db8:1000::251
$ dig @your-server -x 2001:db8:1000::251

# Automatic Response:
1.5.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.
β†’ 20010db8100000000000000000000251.ip6.yourdomain.com.

# Query for custom record
$ dig @your-server -x 2001:db8:1000::1

# Custom Response (if configured):
β†’ server.yourdomain.com.

πŸŽ›οΈ Custom PTR Records

Create custom mappings in ipv6autoptr.conf:

# Format: <ipv6-address-in-arpa-format> = <custom-domain-name>

# Custom PTR for 2001:db8:1000::1
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa. = server.yourdomain.com.

# Custom PTR for 2001:db8:1000::5
5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa. = mail.yourdomain.com.

πŸš€ Production Deployment

SystemD Service (Traditional)

# Download and install
wget https://github.com/uppaljs/ipv6autoptr/releases/latest/download/ipv6autoptr.py -O /usr/local/bin/ipv6autoptr.py
chmod 755 /usr/local/bin/ipv6autoptr.py

# Create service file
cat > /etc/systemd/system/ipv6autoptr.service << EOF
[Unit]
Description=IPv6 Auto PTR DNS Server
After=network.target
Wants=network-online.target

[Service]
Type=simple
User=dns
Group=dns
WorkingDirectory=/etc/ipv6autoptr
ExecStart=/usr/bin/python3 /usr/local/bin/ipv6autoptr.py --config /etc/ipv6autoptr/config.yaml
ExecReload=/bin/kill -s HUP \$MAINPID
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal

# Security settings
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/etc/ipv6autoptr

[Install]
WantedBy=multi-user.target
EOF

# Enable and start
systemctl daemon-reload
systemctl enable ipv6autoptr.service
systemctl start ipv6autoptr.service

Performance Tuning

For high-traffic environments:

dns:
  max_workers: 64        # Increase worker threads
  ttl: 3600             # Lower TTL for faster updates

server:
  enable_tcp: true      # Enable TCP for large responses
  enable_udp: true      # Keep UDP for standard queries

logging:
  level: "WARNING"      # Reduce log verbosity

πŸ§ͺ Testing and Validation

Basic Functionality Test

# Test automatic PTR generation
dig @localhost -p 5353 -x 2001:db8:1000::10

# Test custom PTR record
dig @localhost -p 5353 -x 2001:db8:1000::1

# Test NXDOMAIN response (out of subnet)
dig @localhost -p 5353 -x 2001:db8:9000::1

# Performance test
dig @localhost -p 5353 -x 2001:db8:1000::$(shuf -i 1-1000 -n 1)

Load Testing

# Install dnsperf for load testing
sudo apt-get install dnsperf

# Create test file
echo "2001:db8:1000::10 PTR" > test-queries.txt

# Run performance test
dnsperf -s localhost -p 5353 -d test-queries.txt -c 10 -T 10

πŸ“ˆ Monitoring and Observability

Health Checks

# Docker health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD dig @localhost -p $IPV6AUTOPTR_PORT -x 2001:db8:1::1 || exit 1

# Kubernetes readiness probe
readinessProbe:
  exec:
    command:
    - dig
    - "@localhost"
    - "-x"
    - "2001:db8:1::1"
  initialDelaySeconds: 5
  periodSeconds: 10

Prometheus Metrics (Future Enhancement)

# Example metrics endpoint (planned feature)
curl http://localhost:9090/metrics

# Sample metrics:
# ipv6autoptr_queries_total{type="automatic"} 1234
# ipv6autoptr_queries_total{type="custom"} 567
# ipv6autoptr_query_duration_seconds{quantile="0.95"} 0.001

πŸ”§ Development

Local Development Setup

# Clone and setup
git clone https://github.com/uppaljs/ipv6autoptr.git
cd ipv6autoptr

# Setup development environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# Run with development config
cp config.yaml config-dev.yaml
# Edit config-dev.yaml with development settings

python ipv6autoptr.py --config config-dev.yaml --port 5353 --verbose

Building Docker Image

# Build image
docker build -t ipv6autoptr:dev .

# Test image
docker run --rm -p 5353:53/udp ipv6autoptr:dev

Running Tests

# Install test dependencies
pip install pytest pytest-cov

# Run tests
pytest tests/ -v --cov=ipv6autoptr

# Test specific functionality
python -m pytest tests/test_config.py -v

πŸ†š Migration from Original Version

If you're upgrading from the original hardcoded version:

  1. Create Configuration File: Use your existing hardcoded values
  2. Update Systemd Service: Use new configuration-based startup
  3. Test Configuration: Verify all settings work correctly
  4. Deploy Gradually: Test in development first

Migration Helper

# Extract current configuration
python3 -c "
from ipv6autoptr import Config
config = Config('config.yaml')
print('Current configuration loaded successfully')
print(f'Subnets: {config.subnets}')
print(f'Domain: {config.domain_suffix}')
"

🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass (pytest)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

πŸ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

πŸ‘₯ Authors and Acknowledgments

Original Author

Current Maintainer

Key Enhancements in This Fork

  • βœ… Python 3.13 Support - Latest Python compatibility
  • βœ… YAML Configuration - Professional configuration management
  • βœ… Environment Variables - Docker and Kubernetes ready
  • βœ… Docker Support - Production-ready containerization
  • βœ… Security Hardening - Non-root user, minimal privileges
  • βœ… Comprehensive Documentation - Usage guides and examples
  • βœ… Performance Improvements - Configurable threading and optimization
  • βœ… Modern Development - Virtual environments, pinned dependencies
  • βœ… Production Ready - Health checks, monitoring, logging
  • βœ… CI/CD Pipeline - Automated testing, building, and releases

πŸš€ Automated Releases & CI/CD

This project features a complete automated CI/CD pipeline with GitHub Actions:

πŸ”„ Continuous Integration

  • βœ… Multi-Python Testing - Tests across Python 3.11, 3.12, and 3.13
  • βœ… Code Quality Checks - Automated linting, formatting, and security scans
  • βœ… Docker Build Validation - Ensures containers build correctly
  • βœ… Configuration Validation - YAML syntax and configuration testing

πŸ“¦ Automated Releases

  • 🏷️ Semantic Versioning - Create releases with git tag v1.0.0
  • 🐳 Multi-Platform Docker Images - Automatic builds for AMD64 and ARM64
  • πŸ“‹ Generated Changelogs - Automatic release notes from commit history
  • πŸ”’ Security Scanning - Container vulnerability analysis with Trivy

🐳 Docker Hub Integration

Official Images: uppal/ipv6autoptr

# Latest stable release
docker pull uppal/ipv6autoptr:latest

# Specific version
docker pull uppal/ipv6autoptr:v1.0.0

# Development builds
docker pull uppal/ipv6autoptr:main

Supported Platforms:

  • linux/amd64 (Intel/AMD 64-bit)
  • linux/arm64 (ARM64/Apple Silicon)

πŸ“– For Contributors

See .github/ACTIONS.md for detailed CI/CD documentation, including:

  • Setting up Docker Hub credentials
  • Creating releases
  • Workflow customization
  • Troubleshooting guide

πŸ†˜ Support and Issues

πŸ—ΊοΈ Roadmap

  • Prometheus Metrics - Built-in monitoring support
  • DNS-over-HTTPS - Modern DNS protocol support
  • Rate Limiting - Built-in DDoS protection
  • Geographic PTR - Location-based PTR generation
  • API Interface - REST API for management
  • High Availability - Clustering and failover support

⚑ Performance Benchmarks

Tested on modern hardware with Python 3.13:

Metric Value
Queries/second 10,000+ (single instance)
Memory usage < 50MB (base)
CPU usage < 5% (normal load)
Response time < 1ms (average)
Concurrent connections 1000+

Made with ❀️ for the IPv6 community

About

This is a simple DNS server in Python designed for dynamic, on-the-fly generation of PTR records for IPv6.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages