RouterOS configuration

Use MikroTik as a DNS Server: Cache, Static Entries and DNS over HTTPS

Run your LAN's DNS on the MikroTik router: upstream servers and cache, local names with static entries, forcing clients to use it, encrypted DNS over HTTPS, and keeping it closed to the internet.

Commands in this article follow RouterOS v7 documentation but have not yet been marked as lab-tested on this site. Always test changes in a lab or maintenance window and keep a backup.

Problem

You want faster name resolution, local names such as nvr.office for internal devices, and control over which DNS servers your LAN uses.

Symptoms

  • Slow page loading on first visit.
  • Users remember IP addresses instead of names for the printer or NVR.
  • Some devices ignore your DNS and use their own.

Likely causes

Without a local DNS, every client asks the ISP's DNS directly, there are no local names, and devices with hard-coded DNS bypass your settings.

Prerequisites

  • The router's LAN address handed out as DNS by the DHCP server (dns-server=192.168.88.1).

Solution (WinBox / CLI)

1. Upstream servers and cache:

RouterOS CLI
/ip dns set servers=1.1.1.1,8.8.8.8 allow-remote-requests=yes cache-size=4096

Warning: With allow-remote-requests=yes, the input firewall must drop DNS from the WAN, or your router becomes an open DNS server used in attacks.

2. Local names:

RouterOS CLI
/ip dns static add name=nvr.office address=192.168.88.20
/ip dns static add name=printer.office address=192.168.88.30

3. Force LAN devices to use the router's DNS:

RouterOS CLI
/ip firewall nat add chain=dstnat in-interface-list=LAN protocol=udp dst-port=53 action=redirect to-ports=53 comment="Force DNS"
/ip firewall nat add chain=dstnat in-interface-list=LAN protocol=tcp dst-port=53 action=redirect to-ports=53 comment="Force DNS"

4. Optional: encrypted DNS over HTTPS (DoH) to the upstream server. The router needs trusted root certificates first:

RouterOS CLI
/tool fetch url=https://curl.se/ca/cacert.pem
/certificate import file-name=cacert.pem passphrase=""
/ip dns set use-doh-server=https://cloudflare-dns.com/dns-query verify-doh-cert=yes

Verification

RouterOS CLI
/ip dns cache print
:put [:resolve nvr.office]

From a LAN PC, nslookup nvr.office returns 192.168.88.20.

Common errors

  • Clients still get the ISP's DNS from DHCP: set dns-server in IP > DHCP Server > Networks.
  • DoH enabled without certificates and with verify-doh-cert=yes: all DNS fails. Import the certificates first.
  • Old cached answers after a change: /ip dns cache flush.

Rollback

RouterOS CLI
/ip firewall nat disable [find comment="Force DNS"]
/ip dns set use-doh-server=""
Go deeper in class

This topic is covered hands-on in MTCNA — MikroTik Certified Network Associate.

View MTCNA
WhatsApp