"It's always the [bleep]ing DNS" is a common complaint when dealing with networks, especially if you're running an internal DNS for your own services and not just doing simple lookups for other internet sites. And of course the GeekLab has a more complex configuration typical of larger organisations with split horizon and multiple internal domains.

Compared to the old Draytek router the Mikrotik service is surprisingly limited by comparison but thankfully I don't (currently ) need to have the advanced features on the router itself and there are workarounds for when I do.

Current State

The GeekLab DNS is more complex than expected in an attempt to simplify operations (which doesn't make sense until it makes sense. Err, yeah)

  1. Most user devices refer to Samba AD internal DNS first
  2. Which then forwards to the internal router which is running DNSmasq so I can do internal overrides on A, CNAME and PTR records if needed
  3. Which then forwards to the Draytek - which has some global internal overrides and forwarders for other internal sub-domains
  4. Which then forwards to public DNS, currently Google since it wasn't playing nicely with the ISPs servers.

The Draytek connection to public DNS is now getting routed via the Mikrotik as standard TCP connections. This can be be a little unstable and can take several seconds for DNS lookups to succeed. With the decrease in traffic thought the Draytek I've noticed it reporting the firewall is blocking connection on a rule that doesn't exist for good measure - that appear to be unrelated to the Mikrotik though.

Desired State

Mikrotik handling DNS at #3 above, so in theory with split horizon support for selected services, same as the Draytek was providing but a without the delays. Not really too fussed if it's using the ISP, Google, Cloudflare or whoever for upstream DNS.

Why So Complex?

Normal DNS is easy. Your device is configured to use a DNS service, typically to your router which then sends all requests to the DNS services offered by your ISP, or directly to the public DNS servers provided by your ISP or offered by Google, Cloudflare and the like (who are not doing this out of the goodness of their hearts - there's value in analysing DNS queries). This is all simple stuff when everything you want to connect to is on the internet.

I run my own services on the GeekLab, which fall into four scenarios as far as DNS is concerned.

  1. Most service are not available to the internet so are not listed in public DNS. I need to run internal DNS servers to support them.
  2. Some internal services also need to be available to my users externally so I need to use the same full name internally and externally, routing external access through firewalls and proxies.
  3. A few services are publicly available, internal users should be able to access directly without proxy restrictions
  4. Guest users should have access to selected internal services, potentially via a proxy for TLS handling since they won't have my internal root certificate installed.

I also have externally hosted services but these don't count as they're accessed using public DNS whether at home or away and by all users.

While I could route all access via the public DNS, this would also mean using the public IP address on my router and having to feed everything through the proxy. This is not a good solution as I block access to certain features of some services at the proxy and for IPv4-based services there's also NAT involved and routing out and back in again causes complications and unnecessary load on the router.

Example of split horizon DNSOne way around this is to use split-horizon DNS. External users will be able to access via the publicly listed hostname to reach my router public IP and NAT will take it from there, connecting to the internal proxy. which will then connect to the host providing the service.

Guests will use the same hostname from a Guest DNS and will be connected to the proxy, with the hostname ideally being a CNAME record for the proxy itself. The proxy has a Lets Encrypt certificate so both guest and internet users can use TLS. The proxy could also be configured to allow guest users, who will be known to me, to have additional access that is denied to internet-based users.

Internal users will still use the same hostname and as they're using the internal DNS this is actually a CNAME alias pointing to the internal host so they will connect to it directly.

In all three scenarios everyone is still getting to the same server, just through different routes depending on their location. If internal users want full access while travelling they'll need to use another access method such as VPN so they appear to be internal.

The second scenario only applies to internal users. I currently have three separate internal domains that provide services, I may add more later or even remove one. While I could manually configure every other domain to correctly resolve all the others this takes a little bit of time and organisation and gives a chance for errors to creep in. What I can do instead is define a forwarder on the Mikrotik so that any requests for an internal domain that reach the Mikrotik router are forwarded to the domain concerned. This is also handled by the Draytek so again it's just a translation exercise.

Mikrotik and internal spit-horizon DNS

The Draytek has a feature on it's DNS implementation called Same Subnet Reply, which is a kind of limited split-horizon DNS within the router itself. You can define multiple IP addresses for a domain name and if a host makes a request for that domain name and one of the addresses is in the same subnet as that host and the same subnet reply flag is set for it, the host will receive that IP address instead. I was using this for hosts in my public subnet requesting access to internal resources to be given the IP for a proxy rather then routing directly.

The Mikrotik does not support this, it has a single address (or list of addresses) for each hostname. If you need to return different results based on where the request is coming from you need to use a different DNS solution.

While I don't currently have any public hosts I would like to route Guests though the proxy while allowing internal users go access internal hosts directly. The simplest solution for me is use the Mikrotik to provvide CNAME aliaes for the internal interface of the proxy and use to use DNSmasq on the internal routers to provide CNAME aliases for internal users. It's a little more effort on my part, but on the other hand if the Mikrotik should go offline for any reason inernal DNS resolution should be unaffected.

I have also seen references to running a BIND or other DNS servers in a container on the Mikrotik, but that's something to look at in future if the need arises.

Enable DNS Services

This should be done already when the default configuration was loaded which is good as this needs to be enabled to allow the Mikrotik to provide DNS services to other hosts. The default firewall rules allows DNS queries from any interface in the LAN interface list so you may need to add an explicit accept rule for other interfaces. Note this also means DNS is not accepted from the internet, which is a good thing.

Go to IP > DNS and make sure Allow Remote Requests is ticked.

Configure Internal DNS entries

I already have hostnames for the public and externally enabled services for the GeekLab defined in the Draytek router (under Applications > LAN DNS / DNS Forwarding) so this should simply be a case of recreating them in the Mikrotik.

Go to IP > DNS > Configuration :  Static and click New for each entry you need.

Add a DNS A record (example)
Parameter Value
Name nextcloud.example.com
Type A
DNS Servers 192.168.241.42

Unlike the Draytek, the Mikrotik support a wider range of DNS record types:

Mikrotik DNS record types
Type Purpose
A IPv4 address for a host
AAAA IPv6 address for a host
CNAME Alias name for a host
MX Mail eXchange sets mail servers for domain
NS Name Server record to provide information about DNS servers for a domain
SRV Specify hostname and port for a given service e.g. SIP, LDAP for applications that can use SRV records
TXT Generic text record, used my many applications

PTR records are also created and managed by the Mikrotik as needed but there is no manual control over this, which is a shame as you can't use it to centrally manage reverse lookups to other internal domains.

Two additional options are supported which are not really DNS record types but are specific to Mikrotik DNS functions:

  • NXDOMAIN : Used to blackhole domains by forcing an non-existent domain error for any queries for it
  • FWD : Use for forwarding, see next section.

I have a list of 7 entries that needed to be moved across and kept in sync with the Draytek while they're both active. This is also a good time for a little housekeeping and dropping entries that are no longer in use. The entires are implemented as A records for actual hotnames with the IP addresses of the hosts concerned and CNAME records pointing the a A records for the proxies that will service guest and other non-internal users.

DNS Forwarding

When the Mikrotik receives a DNS query for one of the internal domains I want it to forward that query to a DNS server specific to that domain. In practice this means forwarding to the appropriate internal router since my internal domains are all self-contained. The internal routers all run DNSmasq so whether it forwards in turn to the the actual DNS server for the domain or handles the query itself doesn't really matter to the Mikrotik.

The first step is to define a forwarder and the DNS Server(s) it should use. Go to IP > DNS > Configuration : Forwarders
Define DNS forwarder

Define DNS forwarder
Parameter Value
Name [Something descriptive e.g. sandpit]
DNS Servers 192.168.nnn.nnn

You can define multiple DNS servers for each forwarder if you have resilience configured. And given the criticality of DNS you should have at least two.

The second step is to define the domain(s) to use the forwarder for. Go to IP > DNS > Config : Static and click New to add an entry.Create a FWD entry for domain forwarding

Add FWD record
Parameter Value
Name [domain to forward for e.g. sandpit.example.com
Type FWD
Match subdomain Tick
Forward To [Forwarder to use e.g. sandpit]

The Forward To parameter is drop-down of all the forwarders you've created in the previous step.

DNSmasq activation on internal routers

The majority of DNS queries are generated by hosts on the internal networks, and nearly all of that unsurprisingly comes from the live network. The modular design of these networks means all DNS requests go through the internal routers so all I need to do is update DNSmasq on those to use the Mikrotik as their first preference.

I already have DNSmasq configured to use /etc/dnsmasq-forwards.conf instead of the hosts own /etc/resolv.conf as the source for where to forward DNS queries it can't resolve to so I just need to add a new nameserver entry for 192.168.11.2 to the top of file

# Copy of resolv.conf for use by dnsmasq
nameserver 192.168.11.2
nameserver 192.168.11.1

I'm leaving the old .1 entry for the Draytek in place for the moment to allow for a quick fallback if something interesting happens.

Draytek changes & observations

Within an hour switching the internal routers to use the Mikrotik for DNS forwarding, the DNS related entries in the NAT connections table (Diagnostics > NAT Sessions Table) had nearly all disappeared and the DNS cache (Diagnostics > DNS Cache Table) was noticeably reduced and a few days later was mostly made up of static entries from the Drayteks LAN DNS feature.

Summary

DNS resolution looks to be running properly. The cache list started filling within seconds of adding the nameserver entry on the House internal router and all the issues I've been seeing with initial browser response for the last several months appear to have gone away too.

Some of the entries may need revision when the Guest VLAN moves across to make sure they're getting redirected to the right place but it's working nicely for internal users which is all that counts right now. Their feedback after prompting was "oh yeah, it's a bit quicker I guess" which is typical really. Very quick to complain when things break, fixes and improvements get ignored

Notes

This was article was written with reference to a Mikrotik RB5009 running RouterOS 7.21.5 using WinBox 4.3 and a Draytek Vigor 2862. I expect this to be broadly similar for equivalent products and later versions but that cannot be guaranteed.