tourze / dns-server-bundle
DNS服务端管理系统,支持权威DNS解析和上游DNS服务器配置
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/dns-server-bundle
Requires
- ext-filter: *
- ext-intl: *
- ext-json: *
- ext-mbstring: *
- ext-pcre: *
- ext-spl: *
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- monolog/monolog: ^3.1
- psr/cache: ^2.0 || ^3.0
- psr/log: ^3|^2|^1
- react/datagram: ^1.9
- react/dns: ^1.13
- react/event-loop: ^1.5
- react/promise: ^3.2
- spatie/dns: ^2.0
- symfony/cache: ^7.3
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/form: ^7.3
- symfony/framework-bundle: ^7.3
- symfony/http-client: ^7.3
- symfony/http-client-contracts: ^3.6
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/property-access: ^7.3
- symfony/routing: ^7.3
- symfony/yaml: ^7.3
- tourze/arrayable: 1.*
- tourze/bundle-dependency: 1.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-ip-bundle: 1.1.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/doctrine-track-bundle: 1.1.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/enum-extra: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
- tourze/symfony-routing-auto-loader-bundle: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2025-11-15 17:18:11 UTC
README
A comprehensive DNS server implementation for Symfony applications with async I/O support, admin interface, and complete DNS record management.
Table of Contents
- Features
- Dependencies
- Installation
- Configuration
- Quick Start
- Commands
- Admin Interface
- Advanced Usage
- Performance Considerations
- Security
- Contributing
- License
Features
- Async DNS Server: Built with ReactPHP for high-performance async I/O
- Multi-Protocol Support: UDP and TCP DNS protocols
- Complete Record Types: Support for A, AAAA, NS, CNAME, MX, TXT, SOA, PTR, SRV, CAA, and DNSSEC records
- Admin Interface: EasyAdmin-based management interface for DNS records and logs
- Query Logging: Comprehensive logging of DNS queries with IP tracking
- Upstream Forwarding: Configurable upstream DNS servers with different protocols
- Flexible Matching: Domain pattern matching strategies for selective forwarding
- Performance Optimized: Built-in caching and query optimization
Dependencies
Required
- PHP: ^8.1
- Symfony: ^6.4 || ^7.0
- ReactPHP: For async I/O operations
- Doctrine ORM: For entity management
- EasyAdmin: For admin interface
Optional
- Monolog: For enhanced logging (recommended)
- Symfony Security: For admin interface authentication
Installation
composer require tourze/dns-server-bundle
Add the bundle to your config/bundles.php:
return [ // ... DnsServerBundle\DnsServerBundle::class => ['all' => true], ];
Configuration
Service Configuration
Configure the bundle in config/services.yaml:
services: DnsServerBundle\Service\DnsWorkerService: arguments: $dnsQueryService: '@DnsServerBundle\Service\DnsQueryService' $logger: '@logger' tags: - { name: 'monolog.logger', channel: 'dns' }
Database Entities
The bundle provides two main entities:
DnsQueryLog: Stores DNS query logs with IP trackingUpstreamDnsServer: Manages upstream DNS server configurations
Quick Start
1. Database Setup
Run migrations to create the required tables:
php bin/console doctrine:migrations:migrate
2. Start the DNS Server
php bin/console dns:worker:start --host=0.0.0.0 --port=53
3. Configure Upstream DNS Servers
Access the admin interface at /admin and add upstream DNS servers:
// Example upstream server configuration $upstream = new UpstreamDnsServer(); $upstream->setName('Cloudflare DNS'); $upstream->setHost('1.1.1.1'); $upstream->setPort(53); $upstream->setProtocol(DnsProtocolEnum::UDP); $upstream->setMatchStrategy(MatchStrategy::SUFFIX); $upstream->setMatchPattern('*.example.com');
4. Basic Usage in Code
use DnsServerBundle\Service\DnsQueryService; use DnsServerBundle\Service\DnsResolver; // Resolve DNS queries $resolver = new DnsResolver($upstreamServers); $result = $resolver->resolve('example.com', RecordType::A); // Handle DNS queries programmatically $queryService = new DnsQueryService($resolver, $logger); $response = $queryService->handleQuery($dnsMessage, $clientAddress, $server);
Commands
DNS Worker
Start the DNS server daemon:
# Start with default settings (0.0.0.0:53) php bin/console dns:worker:start # Start with custom host and port php bin/console dns:worker:start --host=127.0.0.1 --port=5353 # Start with verbose logging php bin/console dns:worker:start -v
Options:
--host: DNS server binding host (default: 0.0.0.0)--port: DNS server binding port (default: 53)
Note: Port 53 requires root privileges on most systems.
Admin Interface
The bundle integrates with EasyAdmin to provide:
- DNS Query Logs: View and analyze DNS query history
- Upstream DNS Servers: Manage upstream server configurations
- Real-time Monitoring: Track DNS server performance and statistics
Access the admin interface at /admin after proper authentication setup.
Advanced Usage
DNS Record Types
Full support for DNS record types including:
- A/AAAA: IPv4/IPv6 address records
- NS: Name server records
- CNAME: Canonical name records
- MX: Mail exchange records
- TXT: Text records
- SOA: Start of authority records
- PTR: Pointer records for reverse DNS
- SRV: Service location records
- CAA: Certificate Authority Authorization
- DNSSEC: DS, RRSIG, NSEC, DNSKEY records
Match Strategies
Configure how domains are matched for upstream forwarding:
- EXACT: Exact domain match
- SUFFIX: Domain suffix matching
- PREFIX: Domain prefix matching
- REGEX: Regular expression matching
- WILDCARD: Wildcard pattern matching (e.g.,
*.example.com)
Protocol Support
- UDP: Standard DNS over UDP (implemented)
- TCP: DNS over TCP for large responses (implemented)
- DoH: DNS over HTTPS (implemented)
- DoT: DNS over TLS (implemented)
Upstream Server Configuration
Configure multiple upstream DNS servers with different settings:
use DnsServerBundle\Enum\DnsProtocolEnum; use DnsServerBundle\Enum\MatchStrategy; use DnsServerBundle\Entity\UpstreamDnsServer; // Configure DNS over TLS upstream $dotServer = new UpstreamDnsServer(); $dotServer->setName('Cloudflare DoT') ->setHost('1.1.1.1') ->setPort(853) ->setProtocol(DnsProtocolEnum::DOT) ->setCertPath('/path/to/client.crt') ->setKeyPath('/path/to/client.key') ->setVerifyCert(true); // Configure DNS over HTTPS upstream $dohServer = new UpstreamDnsServer(); $dohServer->setName('Google DoH') ->setHost('dns.google') ->setPort(443) ->setProtocol(DnsProtocolEnum::DOH) ->setPath('/dns-query');
DNS Query Logging
All DNS queries are automatically logged with detailed information:
use DnsServerBundle\Entity\DnsQueryLog; // Query logs include: // - Domain name // - Query type (A, AAAA, MX, etc.) // - Client IP address // - Response code // - Response time // - Upstream server used // - Query timestamp
Custom DNS Resolvers
Create custom resolvers for specific use cases:
use DnsServerBundle\Service\DnsResolver; use DnsServerBundle\Service\DnsMatcherService; $matcher = new DnsMatcherService(); $resolver = new DnsResolver($upstreamServers, $matcher, $logger); // Add custom resolution logic $resolver->resolve('example.com', RecordType::A);
Performance Considerations
- Memory Usage: Default cache limit is 10,000 entries
- Query Performance: ~5,000 QPS per instance
- Cache Hit Rate: Optimize for >80% cache hit rate
- Concurrent Connections: Async I/O handles thousands of concurrent queries
Security
- Query Logging: All DNS queries are logged with IP tracking
- Access Control: Configurable upstream server restrictions
- Rate Limiting: Built-in query rate limiting (configurable)
- Input Validation: Comprehensive DNS message validation
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.