A DNS over TLS (DoT) server implementation using Python and dnspython with CLI support via Python Fire.
- DNS over TLS (RFC 7858) support on port 853
- Forwards queries to upstream DNS server (default: 8.8.8.8)
- Multi-threaded client handling
- SSL/TLS encryption
- Command-line interface with configurable parameters
- Structured logging with multiple levels
git clone [email protected]:nsiregar/tldns.git
cd tldns
uv pip install -e .pip install tldns- Generate SSL certificate (for testing):
./scripts/generate_cert.sh- Run the server:
tldns start# Start with default settings (port 853, upstream 8.8.8.8)
tldns start
# Show help
tldns --help# Custom port and upstream DNS
tldns --port 8853 --upstream_dns 1.1.1.1 start
# Custom host binding
tldns --host 127.0.0.1 --port 8853 start
# Custom SSL certificates
tldns --cert_file custom.crt --key_file custom.key start
# Enable debug logging
tldns --log_level DEBUG start
# Quiet mode (errors only)
tldns --log_level ERROR start--host: Bind address (default: '0.0.0.0')--port: Port number (default: 853)--cert_file: SSL certificate file (default: 'server.crt')--key_file: SSL private key file (default: 'server.key')--upstream_dns: Upstream DNS server (default: '8.8.8.8')--log_level: Logging level - DEBUG, INFO, WARNING, ERROR (default: 'INFO')
Test with dig:
dig @127.0.0.1 -p 853 +tls example.comOr with kdig:
kdig @127.0.0.1 -p 853 +tls example.com# Install in development mode
uv pip install -e .
# Run directly from source
python -m tldns.server start# Install test dependencies
uv pip install -e ".[test]"
# Run all tests
python -m pytest
# Run tests with coverage
python -m pytest --cov=tldns
# Run specific test categories
python -m pytest -m unit
python -m pytest -m integration
python -m pytest -m "not slow"tests/test_server.py- Unit tests for server functionalitytests/test_protocol.py- DNS and TLS protocol teststests/test_performance.py- Performance and load teststests/conftest.py- Test fixtures and configuration
- dnspython: DNS library for Python
- fire: Command-line interface generation