Mikrotik dns static ttl

Introduction

Domain Name System (DNS) usually refers to the Phonebook of the Internet. In other words, DNS is a database that links strings (known as hostnames), such as www.mikrotik.com to a specific IP address, such as 159.148.147.196.

A MikroTik router with DNS feature enabled can be set as a DNS server for any DNS-compliant client. Moreover, the MikroTik router can be specified as a primary DNS server under its DHCP server settings. When the remote requests are enabled, the MikroTik router responds to TCP and UDP DNS requests on port 53.

When both static and dynamic servers are set, static server entries are more preferred, however, it does not indicate that static server will always be used (for example, previously query was received from a dynamic server, but static was added later, then a dynamic entry will be preferred).

When DNS server allow-remote-requests are used make sure that you limit access to your server over TCP and UDP protocol port 53.

Let`s take as an example the following setup: Internet service provider ( ISP) → Gateway (GW) → Local area network ( LAN). The GW is RouterOS based device with the default configuration:

  • You do not configure any DNS servers on the «GW» DHCP server network configuration- the device will forward DNS server received from `ISP` to `LAN` devices;
  • You configure DNS servers on the «GW» DHCP server network configuration- the device will give configured DNS servers to `LAN` devices ( also /ip dns set allow-remote-requests=yes should be enabled);
  • «dns-none» configured under DNS servers on «GW» DHCP server network configuration — the device will not forward any of the dynamic DNS servers to `LAN` devices;

DNS Cache

This menu provides two lists with DNS records stored on the server:

  • /ip dns cache print: this menu provides a list with all address (DNS type «A») records stored on the server ;
  • /ip dns cache all print: This menu provides a complete list with all DNS records stored on the server;

Empty a DNS cache you can with the command: /ip dns cache flush

DNS Static

The MikroTik RouterOS has an embedded DNS server feature in the DNS cache. It allows you to link the particular domain names with the respective IP addresses and advertize these links to the DNS clients using the router as their DNS server. This feature can also be used to provide fake DNS information to your network clients. For example, resolving any DNS request for a certain set of domains (or for the whole Internet) to your own page.

The server is capable of resolving DNS requests based on POSIX basic regular expressions so that multiple requests can be matched with the same entry. In case an entry does not conform with DNS naming standards, it is considered a regular expression and marked with an ‘R’ flag. The list is ordered and is checked from top to bottom. Regular expressions are checked first, then the plain records.

Читайте также:  Установка mikrotik rb951g 2hnd

Use regex to match DNS requests:

Regexp is case sensitive, but DNS requests are not case sensitive, RouterOS converts DNS names to lowercase, you should write regex only with lowercase letters. Regular expression matching is significantly slower than the plain entries, so it is advised to minimize the number of regular expression rules and optimize the expressions themselves.

Quick Example

Dynamic DNS servers are obtained from the DHCP server with the DHCP client configuration. Let`s assume we don’t want to use both dynamic servers, but only one of them:

DNS over HTTPS (DoH)

Starting from RouterOS version v6.47 it is possible to use DNS over HTTPS (DoH). DoH uses HTTPS protocol to send and receive DNS requests for better data integrity. Its main goal is to provide privacy by eliminating the man-in-the-middle attacks (MITM). Currently, DoH is not compatible with FWD-type static entries, in order to utilize FWD entries, DoH must not be configured.

It is advised to import the root CA certificate of the DoH server you have chosen to use for increased security. We strongly suggest not using third-party download links for certificate fetching. Use the Certificate Authority’s own website.

There are various ways to find out what root CA certificate is necessary. The easiest way is by using your WEB browser, navigating to the DoH site, and checking the security of the website. Using Firefox we can see that DigiCert Global Root CA is used by the Cloudflare DoH server. You can download the certificate straight from the browser or navigate to the DigiCert website and fetch the certificate from a trusted source.

DNS > Rootca.PNG» data-location=»RouterOS > DNS > Rootca.PNG» data-image-height=»281″ data-image-width=»1045″>

Download the certificate and import it:

Configure the DoH server:

Note that you need at least one regular DNS server configured for the router to resolve the DoH hostname itself. If you do not have any dynamical or static DNS server configured, configure it like this:

RouterOS prioritize DoH over DNS server if both are configured on the device.

Источник

Manual:IP/DNS

Applies to RouterOS: v4.6

DNS cache is used to minimize DNS requests to an external DNS server as well as to minimize DNS resolution time. This is a simple DNS cache with local items.

Contents

Specifications

  • Packages required: system
  • License required: Level1
  • Submenu level: /ip dns
  • Standards and Technologies: DNS
  • Hardware usage: Not significant

Description

A MikroTik router with DNS feature enabled can be set as a DNS server for any DNS-compliant client. Moreover, MikroTik router can be specified as a primary DNS server under its dhcp-server settings. When the remote requests are enabled, the MikroTik router responds to TCP and UDP DNS requests on port 53.

DNS Cache Setup

DNS facility is used to provide domain name resolution for router itself as well as for the clients connected to it.

Properties

Property Description
allow-remote-requests (yes | no; Default: no) Specifies whether to allow network requests
cache-max-ttl (time; Default: 1w) Maximum time-to-live for cache records. In other words, cache records will expire unconditionally after cache-max-ttl time. Shorter TTL received from DNS servers are respected.
cache-size (integer[64..4294967295]; Default: 2048) Specifies the size of DNS cache in KiB
max-concurrent-queries (integer; Default: 100) Specifies how much concurrent queries are allowed
max-concurrent-tcp-sessions (integer; Default: 20) Specifies how much concurrent TCP sessions are allowed
max-udp-packet-size (integer [50..65507]; Default: 4096) Maximum size of allowed UDP packet.
query-server-timeout (time; Default: 2s) Specifies how long to wait for query response from one server
query-total-timeout (time; Default: 10s) Specifies how long to wait for query response in total. Note that this setting must be configured taking into account query-server-timeout and number of used DNS server.
servers (list of IPv4/IPv6 addresses; Default: ) List of DNS server IPv4/IPv6 addresses
Читайте также:  Asus скинуть настройки роутера до заводских
Property Description
cache-used (integer) Shows the currently used cache size in KiB
dynamic-server (IPv4/IPv6 list) List of dynamically added DNS server from different services, for example, DHCP.

When both static and dynamic servers are set, static server entries are more preferred, however it does not indicate that static server will always be used (for example, previously query was received from dynamic server, but static was added later, then dynamic entry will be preferred).

Note: If allow-remote-requests is used make sure that you limit access to your server over TCP and UDP protocol.

Example

To set 159.148.60.2 as the primary DNS server and allow the router to be used as a DNS server, do the following:

Cache Monitoring

Description

This menu provides a list with all address (DNS type «A») records stored on the server

Property Description

Property Desciption
address (read-only: IP address) IP address of the host
name (read-only: name) DNS name of the host
ttl (read-only: time) remaining time-to-live for the record

All DNS Entries

  • Submenu level: /ip dns cache all

Description

This menu provides a complete list with all DNS records stored on the server

Property Description

Property Desciption
data (read-only: text) DNS data field. IP address for type «A» records. Other record types may have different contents of the data field (like hostname or arbitrary text)
name (read-only: name) DNS name of the host
ttl (read-only: time) remaining time-to-live for the record
type (read-only: text) DNS record type

Static DNS Entries

Description

The MikroTik RouterOS has an embedded DNS server feature in DNS cache. It allows you to link the particular domain names with the respective IP addresses and advertize these links to the DNS clients using the router as their DNS server. This feature can also be used to provide fake DNS information to your network clients. For example, resolving any DNS request for a certain set of domains (or for the whole Internet) to your own page.

The server is capable of resolving DNS requests based on POSIX basic regular expressions, so that multiple requets can be matched with the same entry. In case an entry does not conform with DNS naming standards, it is considered a regular expression and marked with ‘R’ flag. The list is ordered and is checked from top to bottom. Regular expressions are checked first, then the plain records.

Читайте также:  Keenetic air ac1200 характеристики

Property Description

Property Desciption
address (IP address) IP address to resolve domain name with
name (text) DNS name to be resolved to a given IP address.
regex (text) DNS regex
ttl (time) time-to-live of the DNS record
type (text) type of the DNS record. Available values are: A, AAAA, CNAME, FWD, MX, NS, NXDOMAIN, SRV, TXT

Notes

Reverse DNS lookup (Address to Name) of the regular expression entries is not possible. You can, however, add an additional plain record with the same IP address and specify some name for it.

Remember that the meaning of a dot (.) in regular expressions is any character, so the expression should be escaped properly. For example, if you need to match anything within example.com domain but not all the domains that just end with example.com, like www.another-example.com, use regexp=».*\\.example\\.com\$»

Regular expression matching is significantly slower than of the plain entries, so it is advised to minimize the number of regular expression rules and optimize the expressions themselves. Example

To add a static DNS entry for www.example.com to be resolved to 10.0.0.1 IP address:

It is also possible to forward specific DNS requests to a different server using FWD type. This will fordward all subdomains of «example.com» to server 10.0.0.1:

Note: regexp entries are case sensitive, but since DNS requests are not case sensitive, RouterOS converts DNS names to lowercase, you should write regex only with lowercase letters.

Flushing DNS cache

  • Command name: /ip dns cache flush

Command Description

Command Desciption
flush clears internal DNS cache

Example

DNS over HTTPS

Starting from RouterOS version v6.47 it is possible to use DNS over HTTPS (DoH). DoH uses HTTPS protocol to send and receive DNS requests for better data integrity. Its main goal is to provide privacy by eliminating the man in the middle attacks (MITM). Currently DoH is not compatible with FWD type static entries, in order to utilize FWD entries, DoH must not be configured.

Example

It is advised to import the root CA certificate of the DoH server you have chosen to use for increased security.

Warning: We strongly suggest not use third-party download links for certificate fetching. Use the Certificate Authority’s own website.

There are various ways to find out what root CA certificate is necessary. The easiest way is by using your WEB browser, navigating to the DoH site and checking the websites security. Using Firefox we can see that DigiCert Global Root CA is used by CloudFlare DoH server. You can download the certificate straight from the browser or navigate to DigiCert website and fetch the certificate from a trusted source.

Download the certificate and import it:

Configure the DoH server:

Note that you need at least one regular DNS server configured for the router to resolve the DoH hostname itself. If you do not have any dynamical or static DNS server configured, you can configure a static DNS entry like this:

Note: RouterOS prioritize DoH over DNS server if both are configured on the device.

Источник