DNS Client and Cache · Topic 2 of 2
Static DNS Entries
Learn how to add static DNS entries in RouterOS, match many names with a regular expression, and how static records beat the cache and upstream servers.
- 4 min
- Static entries are in
/ip dns static. - The router answers static entries before the cache and before upstream servers.
- A static entry has either a
nameor aregexp, not both.
What it is
A static DNS entry is a name to address record that you define on the router.
The router answers it directly, without asking an upstream server. This is useful for local servers, for names that exist only inside your network, and for steering a name to a different address.
Static entries live in /ip dns static. They only help clients that use the router as their DNS server, so remote requests must be allowed for the LAN to use them.
How it works
The router checks static entries first, then the cache, then the upstream servers.
Adding an entry
An entry has a name and an address. A TTL can be given too.
/ip dns static add name=nas.lan address=192.168.88.20 ttl=1d
/ip dns static add name=web.example.com address=192.168.88.50
/ip dns static print
A client that asks for nas.lan now receives 192.168.88.20. The entry works even when there is no internet link, because the router does not need an upstream server for it.
Order of answers
For every query the router follows the same order.
| Step | Source | Result |
|---|---|---|
| 1 | Static entries | Answer returned at once if the name matches |
| 2 | Cache | Answer returned from memory if the TTL has not expired |
| 3 | Upstream servers | The router asks, then stores the answer in the cache |
Because static entries come first, a static record overrides the real address of a public name. You can use this to redirect a name inside your network.
Several records for one name
You can add more than one entry with the same name. The router then returns all of them. Clients typically try the addresses in turn, which gives a simple form of load sharing.
/ip dns static add name=app.lan address=192.168.88.31
/ip dns static add name=app.lan address=192.168.88.32
Matching with a regular expression
Instead of name, a static entry can use regexp. It matches every query whose name fits the expression, and returns the address you set.
/ip dns static add regexp=".*\\.ads\\.example" address=127.0.0.1
A single such rule covers all names that end in the pattern. This is how you block a group of names, or point a whole domain at one server. An entry uses either name or regexp, not both.
Keep expressions narrow, because a wide pattern can capture names you did not intend.
Record types
In version 7 a static entry has a record type, and older releases may offer fewer types. The usual type is an address record, an A record.
Other types exist, such as AAAA for IPv6 addresses, CNAME for an alias, MX for mail and TXT for text.
A forwarder type can send a name to a chosen DNS server. Check your version before relying on a type.
/ip dns static add name=files.lan type=CNAME cname=nas.lan
Checking
Look at the table and test from the client.
/ip dns static print
Static entries themselves are not cached, so a change takes effect at once, but a client may keep its own copy for a while.
Combine a static entry with a DHCP server that gives the router address as DNS, and local names will resolve for every client that joins the network.
What to remember for the exam
Seven facts cover most questions on this topic.
- Static entries are in
/ip dns static. - The router answers static entries before the cache and before upstream servers.
- A static entry has either a
nameor aregexp, not both. - Several entries with the same name return several addresses.
- A regular expression can match a whole group of names.
- Clients must use the router as their DNS server for static entries to work.
- Static answers do not need an internet link.
A static entry overrides the real address of a public name. Check your entries when a site opens the wrong server.
Common mistakes
These four mistakes appear often.
Forgetting remote requests. Clients cannot reach the router DNS service, so static entries never answer.
Using a very wide regular expression. It matches names you did not mean to change.
Flushing the cache to fix a static entry. Static entries are answered before the cache, so the cache plays no part.
Mixing name and regexp. An entry uses one or the other.
Check yourself
Work through these three questions.
In which order does the router answer a DNS query?
First static entries, then the cache, and then the upstream servers.
How can one entry cover many names?
Use
regexpinstead ofname, so every matching name receives the answer.Why must
allow-remote-requestsbe enabled for static entries to help LAN clients?Clients ask the router DNS service, and it only answers LAN queries when remote requests are allowed.
Topic 2 of 2 in DNS Client and Cache
Test yourself on DNS Client and Cache
The full MikroTik MTCTCE question bank has 479 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by MikroTik. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.