DNS Client and Cache

Document revision 1.4 (21-Jul-2003)
This document applies to the MikroTik RouterOS V2.7

Table Of Contents

Summary

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 recursive DNS server with local items.

Specifications

Packages required : dns-cache
License required : Any
Home menu level : /ip
Standards and Technologies : DNS (RFC1035)
Hardware usage : not significant

Related Documents

Software Package Installation and Upgrading
AAA (Authentication, Authorization and Accounting)
HotSpot Gateway

Description

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

DNS Client Configuration

Submenu level : /ip dns

Description

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

Property Description

resolve-mode (read-only: remote-dns | local-dns-cache) - the type of domain name resolution
  • remote-dns - names will be resolved by asking remote DNS servers
  • local-dns-cache - names will be resolved using local DNS cache
    primary-dns (IP address; default: 0.0.0.0) - primary DNS server
    secondary-dns (IP address; default: 0.0.0.0) - secondary DNS server

    Notes

    resolve-mode automatically changes to local-dns-cache when dns-cache is enabled.

    When using DHCP Server and Client if the parameter use-peer-dns under ip dhcp-client is set to yes then primary-dns under /ip dns will change to DNS address given by DHCP Server.

    If resolve-mode is remote-dns then DHCP, PPP, PPTP, L2TP, ISDN and PPPoE servers as DNS server address will specify the values listed under /ip dns, otherwise - server's own address.

    Example

    We will set the primary DNS server to 159.148.60.2:
    [admin@MikroTik] ip dns> set primary-dns=159.148.60.2
    [admin@MikroTik] ip dns> print
         resolve-mode: remote-dns
          primary-dns: 159.148.60.2
        secondary-dns: 0.0.0.0
    [admin@MikroTik] ip dns> .. dns-cache set enabled=yes
    [admin@MikroTik] ip dns> print
         resolve-mode: local-dns-cache
          primary-dns: 159.148.60.2
        secondary-dns: 0.0.0.0
    [admin@MikroTik] ip dns>
    
    You can see that resolve-mode has changed its value to local-dns-cache. It means that from this moment domain names will be resolved using local DNS cache.

    DNS Cache Setup

    Submenu level : /ip dns-cache
    [admin@MikroTik] ip dns-cache> print
                 enabled: no
                    size: 256
          primary-server: 0.0.0.0
        secondary-server: 0.0.0.0
                 running: no
    [admin@MikroTik] ip dns-cache>
    

    Property Description

    enabled (yes | no; default: no) - defines whether DNS cache (TCP and UDP port 53) is enabled
    size (integer; default: 256) - size of cache in kilobytes
    primary-server (IP address; default: 0.0.0.0) - primary DNS server
    secondary-server (IP address; default: 0.0.0.0) - secondary DNS server
    running (read only: yes | no) - whether the DNS cache is currently running
    usage (read only: percentage) - percent of cache used
    entries (read only: integer) - number of entries in cache

    Notes

    usage and entries are showed only when the DNS cache is running.

    DNS servers are queried by DNS cache in the following order (the ones which are 0.0.0.0 are skipped):

    1. ip dns-cache primary-server
    2. ip dns-cache secondary-server
    3. ip dns primary-server
    4. ip dns secondary-server

    Example

    To enable DNS cache using 159.148.60.2 as the router's primary DNS server:
    [admin@MikroTik] ip dns-cache> set enabled=yes primary-server=159.148.60.2
    [admin@MikroTik] ip dns-cache> print
                 enabled: yes
                    size: 256
          primary-server: 159.148.60.2
        secondary-server: 0.0.0.0
                 running: yes
                   usage: 0 %
                 entries: 0
    [admin@MikroTik] ip dns-cache>
    

    Adding Static DNS Entries

    Submenu level : /ip dns-cache hosts

    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 this link to the DNS clients using the router as their DNS server.

    Property Description

    address (IP address) - IP address to link the domain name with
    name (text) - the name to be resolved to the given IP address

    Example

    To add a static DNS entry for admin.home.pc domain name to be resolved to 10.0.0.10 IP address:
    [admin@MikroTik] ip dns-cache hosts> add name=admin.home.pc address=10.0.0.10
    [admin@MikroTik] ip dns-cache hosts> print
      # ADDRESS         NAME
      0 10.0.0.10       admin.home.pc
    
    [admin@MikroTik] ip dns-cache hosts>
    

    Flushing DNS cache

    Command name : /ip dns-cache flush

    Description

    DNS cache can be flushed using this command when it is disabled and not running.

    Example

    To flush DNS cache:
    [admin@MikroTik] ip dns-cache> print
                 enabled: yes
                    size: 256
          primary-server: 159.148.60.2
        secondary-server: 0.0.0.0
                 running: yes
                   usage: 32 %
                 entries: 358
    [admin@MikroTik] ip dns-cache> set enabled=no
    [admin@MikroTik] ip dns-cache> print
                 enabled: no
                    size: 256
          primary-server: 159.148.60.2
        secondary-server: 0.0.0.0
                 running: no
    [admin@MikroTik] ip dns-cache> flush
    [admin@MikroTik] ip dns-cache> set enabled=yes
    [admin@MikroTik] ip dns-cache> print
                 enabled: yes
                    size: 256
          primary-server: 159.148.60.2
        secondary-server: 0.0.0.0
                 running: yes
                   usage: 0 %
                 entries: 0
    [admin@MikroTik] ip dns-cache>
    

    Additional Resources

    Below are the links to DNS documentation:

    http://www.freesoft.org/CIE/Course/Section2/3.htm
    http://www.networksorcery.com/enp/protocol/dns.htm
    http://www.ietf.org/rfc/rfc1035.txt?number=1035


    © Copyright 1999-2003, MikroTik