DNS Server Configuration
DNS Server Configuration
Section titled âDNS Server ConfigurationâTL;DR (Quick Start)
Section titled âTL;DR (Quick Start)âEnable DNS server for LAN clients:
/ip dns set servers=8.8.8.8,1.1.1.1 allow-remote-requests=yesAdd a static DNS entry:
/ip dns static add name=server.local address=192.168.88.100Verify configuration:
/ip dns print/ping server.localOverview
Section titled âOverviewâWhat this covers: Configuring your MikroTik router as a DNS server for your local network, including caching and static entries.
When to use this:
- You want LAN devices to use the router for DNS resolution
- You need local hostname mappings (e.g.,
printer.local,nas.local) - You want to reduce external DNS queries through caching
- You want faster DNS resolution for frequently accessed domains
How it works:
- Router receives DNS queries from LAN clients
- Checks local static entries first
- Checks cache for previously resolved queries
- Forwards unknown queries to upstream DNS servers
- Caches responses for future queries
Prerequisites:
- A MikroTik router running RouterOS 6.x or later
- Working internet connection with upstream DNS access
- Basic understanding of IP addressing
Configuration
Section titled âConfigurationâStep 1: Configure Upstream DNS Servers
Section titled âStep 1: Configure Upstream DNS ServersâSet the DNS servers your router will use for resolution:
/ip dns set servers=8.8.8.8,1.1.1.1This configures Google DNS (8.8.8.8) as primary and Cloudflare DNS (1.1.1.1) as secondary.
Step 2: Enable DNS for LAN Clients
Section titled âStep 2: Enable DNS for LAN ClientsâAllow devices on your network to use the router as their DNS server:
/ip dns set allow-remote-requests=yesSecurity
Enabling allow-remote-requests opens UDP/TCP port 53 on ALL interfaces. You MUST add firewall rules to block external DNS access, or your router becomes an open DNS resolver that attackers can abuse.
Step 3: Add Firewall Protection
Section titled âStep 3: Add Firewall ProtectionâBlock DNS queries from the WAN interface:
/ip firewall filter add chain=input protocol=udp dst-port=53 \ in-interface-list=WAN action=drop comment="Block external DNS"/ip firewall filter add chain=input protocol=tcp dst-port=53 \ in-interface-list=WAN action=drop comment="Block external DNS TCP"If you donât use interface lists, specify your WAN interface directly:
/ip firewall filter add chain=input protocol=udp dst-port=53 \ in-interface=ether1 action=drop comment="Block external DNS"Step 4: Configure DHCP to Distribute DNS
Section titled âStep 4: Configure DHCP to Distribute DNSâEnsure DHCP clients receive the router as their DNS server:
/ip dhcp-server network set [find] dns-server=192.168.88.1Replace 192.168.88.1 with your routerâs LAN IP address.
Step 5: Verify Configuration
Section titled âStep 5: Verify ConfigurationâCheck DNS settings:
/ip dns printExpected output:
servers: 8.8.8.8,1.1.1.1 dynamic-servers: use-doh-server: verify-doh-cert: no allow-remote-requests: yes max-udp-packet-size: 4096 query-server-timeout: 2s query-total-timeout: 10s max-concurrent-queries: 100 max-concurrent-tcp-sessions: 20 cache-size: 2048KiB cache-max-ttl: 1w cache-used: 42KiBTest DNS resolution:
/ping google.com count=1Static DNS Entries
Section titled âStatic DNS EntriesâStatic DNS entries let you create local hostnames that resolve to specific IP addresses.
Adding Static Entries
Section titled âAdding Static EntriesâCreate entries for local resources:
/ip dns static add name=nas.local address=192.168.88.50 comment="Network storage"/ip dns static add name=printer.local address=192.168.88.51 comment="Office printer"/ip dns static add name=server.local address=192.168.88.100 comment="Local server"Wildcard Entries
Section titled âWildcard EntriesâUse regex for wildcard matching:
/ip dns static add name=".*\\.local\$" type=FWD forward-to=192.168.88.100 \ regexp=yes comment="Forward all .local to server"View Static Entries
Section titled âView Static Entriesâ/ip dns static printExpected output:
Flags: D - DYNAMIC; X - DISABLED, I - INVALID; M - MATCH-SUBDOMAINSColumns: NAME, ADDRESS, TTL# NAME ADDRESS TTL0 nas.local 192.168.88.50 1d1 printer.local 192.168.88.51 1d2 server.local 192.168.88.100 1dTest Static Entry
Section titled âTest Static Entryâ/ping nas.local count=1Cache Management
Section titled âCache ManagementâView Cache Statistics
Section titled âView Cache Statisticsâ/ip dns printCheck cache-used to see current cache utilization.
View Cached Entries
Section titled âView Cached Entriesâ/ip dns cache printFlush DNS Cache
Section titled âFlush DNS CacheâClear all cached entries:
/ip dns cache flushAdjust Cache Size
Section titled âAdjust Cache SizeâFor networks with many clients or heavy DNS usage:
/ip dns set cache-size=8192KiBAdvanced Configuration
Section titled âAdvanced ConfigurationâDNS over HTTPS (DoH)
Section titled âDNS over HTTPS (DoH)âRouterOS 7.x supports DNS over HTTPS for encrypted DNS queries:
/ip dns set use-doh-server=https://cloudflare-dns.com/dns-query verify-doh-cert=yesIncrease Cache TTL
Section titled âIncrease Cache TTLâKeep entries cached longer (reduces external queries but may serve stale data):
/ip dns set cache-max-ttl=2wQuery Timeouts
Section titled âQuery TimeoutsâAdjust timeouts for slow upstream servers:
/ip dns set query-server-timeout=5s query-total-timeout=15sTroubleshooting
Section titled âTroubleshootingâProblem 1: LAN Clients Cannot Resolve DNS
Section titled âProblem 1: LAN Clients Cannot Resolve DNSâSymptoms: Clients get âDNS server not respondingâ errors.
Checks:
/ip dns print# Verify allow-remote-requests=yesSolutions:
- Enable remote requests:
/ip dns set allow-remote-requests=yes
- Verify DHCP is distributing the router as DNS:
/ip dhcp-server network print
- Check firewall isnât blocking internal DNS:
/ip firewall filter print where dst-port=53
Problem 2: Router Cannot Resolve External Domains
Section titled âProblem 2: Router Cannot Resolve External DomainsâSymptoms: /ping google.com fails with âcould not resolveâ.
Checks:
/ip dns print# Check servers field has valid DNS IPs
/ping 8.8.8.8 count=1# Verify upstream connectivitySolutions:
- Set upstream DNS servers:
/ip dns set servers=8.8.8.8,1.1.1.1
- Check internet connectivity and routing
- If using DoH, verify certificate settings:
/ip dns set verify-doh-cert=no
Problem 3: Static Entry Not Working
Section titled âProblem 3: Static Entry Not WorkingâSymptoms: Local hostname doesnât resolve despite static entry.
Checks:
/ip dns static print# Verify entry exists with correct name/addressSolutions:
- Verify exact name match (check for typos)
- Flush cache and retry:
/ip dns cache flush
- Ensure client is using router as DNS server
- Check for conflicting entries:
/ip dns static print where name~"hostname"
Problem 4: DNS Amplification Attack
Section titled âProblem 4: DNS Amplification AttackâSymptoms: High CPU, bandwidth usage; router responding to external DNS queries.
Security Issue
If your router is answering DNS queries from the internet, itâs being used in DNS amplification attacks. This is a serious security issue.
Solution: Add firewall rules immediately:
/ip firewall filter add chain=input protocol=udp dst-port=53 \ in-interface-list=WAN action=drop place-before=0/ip firewall filter add chain=input protocol=tcp dst-port=53 \ in-interface-list=WAN action=drop place-before=1Problem 5: Slow DNS Resolution
Section titled âProblem 5: Slow DNS ResolutionâSymptoms: Websites take a long time to load initially.
Checks:
/ip dns print# Check cache-used vs cache-sizeSolutions:
- Increase cache size:
/ip dns set cache-size=8192KiB
- Use faster upstream DNS (try Cloudflare 1.1.1.1)
- Check upstream server response time:
/tool traceroute 8.8.8.8
Verification Commands
Section titled âVerification Commandsâ# Show DNS configuration/ip dns print
# List static entries/ip dns static print
# Show cached entries/ip dns cache print
# Test resolution from router/ping hostname.example.com count=1
# Check cache usage/ip dns print where cache-usedRelated Topics
Section titled âRelated TopicsâPrerequisites
Section titled âPrerequisitesâ- IP Address Configuration - router LAN IP for DNS server
DNS Distribution
Section titled âDNS Distributionâ- DHCP Server - distribute DNS settings to clients automatically
- DHCP Relay - DNS option passed through relay
Security
Section titled âSecurityâ- Firewall Basics - protect DNS service from external access
- Firewall Mangle - redirect DNS queries
Related Services
Section titled âRelated Servicesâ- NTP Client - time synchronization (DNS depends on correct time for DoH)
- Certificates - required for DNS over HTTPS
Reference
Section titled âReferenceâOfficial Documentation
Section titled âOfficial Documentationâ- MikroTik DNS Documentation - Complete DNS reference
- MikroTik DoH Guide - DNS over HTTPS configuration
Quick Reference Commands
Section titled âQuick Reference Commandsâ# Configure DNS/ip dns set servers=8.8.8.8,1.1.1.1 allow-remote-requests=yes
# Static entries/ip dns static add name=X address=Y/ip dns static remove [find name=X]/ip dns static print
# Cache management/ip dns cache print/ip dns cache flush
# Diagnostics/ip dns print/ping hostnameSummary
Section titled âSummaryâDNS server configuration involves:
- Set upstream servers - Configure which DNS servers handle external queries
- Enable for LAN - Set
allow-remote-requests=yes - Secure the service - Block external access with firewall rules
- Configure DHCP - Distribute router as DNS to clients
- Add static entries - Create local hostname mappings as needed
Key points:
- Always add firewall rules when enabling
allow-remote-requests - Static entries take precedence over cached/upstream results
- Flush cache after making changes or when troubleshooting
- Consider DoH for encrypted DNS queries (RouterOS 7.x)