Skip to main content

MikroTik RouterOS Integration

DNS-MNS now includes comprehensive integration with MikroTik RouterOS, allowing you to configure and manage DNS settings directly on your MikroTik router from the command line.

Overview

MikroTik routers are popular in Iran for their flexibility and powerful networking features. This integration enables you to:
  • Configure DNS servers on your MikroTik router with the best performing servers
  • Enable DoH/DoT (DNS over HTTPS/TLS) on RouterOS 7+ for encrypted DNS
  • Manage static DNS entries for local network resolution
  • Backup and restore DNS configurations
  • Test connectivity to DNS servers from the router’s perspective

Prerequisites

Router Requirements

  • MikroTik router running RouterOS 6.x or 7.x
  • API service enabled on the router
  • Network connectivity between your computer and the router

Enable API on Your Router

Connect to your router via Winbox or SSH and run:

Firewall Configuration

If you have a firewall on your router, allow access to the API ports:

Quick Start

1. Detect Your Router

Find MikroTik routers on your network:

2. Check Router Status

View detailed information about your router:

3. Configure DNS

Set the best DNS servers on your router:

CLI Commands

mikrotik detect

Detects MikroTik routers on the local network.

mikrotik status

Shows detailed router and DNS status.

mikrotik configure

Configures DNS settings on the router.

mikrotik test

Tests connectivity to DNS servers from the router.

mikrotik flush

Flushes the DNS cache on the router.

mikrotik backup

Creates a backup of the current DNS configuration.

mikrotik restore

Restores DNS configuration from a backup file.

mikrotik static

Manages static DNS entries.

Interactive Menu

You can also access MikroTik integration through the interactive menu:
Then select option 12) MikroTik Integration.

RouterOS Version Support

RouterOS 6.x (Legacy)

  • Basic DNS server configuration
  • Static DNS entries
  • DNS cache management
  • No DoH/DoT support

RouterOS 7.x (Modern)

  • All RouterOS 6.x features
  • DNS over HTTPS (DoH)
  • DNS over TLS (DoT)
  • Certificate validation for DoH

Security Considerations

Password Security

  • Never commit passwords to version control
  • Use environment variables for passwords in scripts
  • Consider using API-SSL (--tls flag) for encrypted connections

Example with Environment Variable

API Access Control

Limit API access to specific IP addresses:

Troubleshooting

Connection Refused

Problem: failed to connect to 192.168.88.1: connection refused Solution:
  1. Verify the router is reachable: ping 192.168.88.1
  2. Enable API service: /ip service enable api
  3. Check firewall rules

Authentication Failed

Problem: login failed: invalid user name or password Solution:
  1. Verify username and password
  2. Check if the user has API access permissions
  3. Try logging in via Winbox to confirm credentials

DoH/DoT Not Working

Problem: DoH requires RouterOS 7.x or later Solution:
  1. Check RouterOS version: /system resource print
  2. Upgrade to RouterOS 7.x if needed
  3. Verify certificate configuration for DoH

Certificate Issues with DoH

Problem: DoH fails with certificate validation errors Solution:

Best Practices

1. Always Backup First

Before making changes, create a backup:

2. Test DNS Servers

Test servers from the router’s perspective:

3. Use Secure Connections

Whenever possible, use API-SSL:

4. Flush Cache After Changes

After changing DNS settings, flush the cache:

Common Use Cases

Use Case 1: Gaming Optimization

Configure the fastest DNS servers for gaming:

Use Case 2: Bypass Censorship with DoH

Use DoH to bypass DNS-based censorship:

Use Case 3: Local Network with Static Entries

Set up local domain resolution:

API Reference

Connection Options

When using --tls, the API client’s InsecureSkipVerify setting controls certificate validation. By default, certificate verification is enabled for security. Only disable verification if you’re using self-signed certificates and understand the security implications.

Global Flags

Further Reading

Getting Help

If you encounter issues with the MikroTik integration:
  1. Run with diagnostics: dns-mns diagnose
  2. Check router logs: /log print
  3. Verify API service: /ip service print
  4. Open an issue with the output of dns-mns mikrotik status --json