DNS/accessing local machines by host name

Hi all,

I’ve been setting up a Mikrotik router for my (very) small office, and it’s gone well so far, even though I’m an absolute noob when it comes to networking. But I can’t seem to figure out how to get the router to act as a DNS server to resolve local host names. I have a few different servers that should be accessible by host name (for instance truenas.local), but I can only reach them by IP. I’ve ticked the “Allow Remote Requests” box and made sure that my clients use the router’s IP for DNS, but no luck so far. What am I missing?

I’ve tried to search around for answers, but haven’t found anything. I have however found that apparently using .local domains is discouraged and it’s better to use a subdomain like .internal.company.com. How do I go about setting that up? I suppose I need to change my DNS records (Which one? CNAME? To where?) but what do I do on the Mikrotik side?

As a bonus I’d also like this to work for L2TP IPsec road warriors and across site to site OVPN tunnels, but let’s do the basics first …

There are a few components to this. Firstly to enable the Mikrotik router to act as a DNS server you need to enable remote requests, and specify forwarders that it will use for addresses that are not resolved locally. I use Open DNS servers.

/ip dns
set allow-remote-requests=yes servers=208.67.222.222,208.67.220.220

To deal with resolving local machines, first decide on your chosen domain for internal addresses, for example “home.lan”. Now you can add static DNS host entries for devices with fixed IP addresses for example ..

/ip dns static
add address=172.17.18.1 name=rb4011.home.lan
add address=172.17.18.100 name=win1064.home.lan
add address=172.17.18.210 name=gigaset.home.lan
add address=172.17.18.201 name=humax.home.lan

Update your DHCP to use your router as DNS server, and include the domain so that clients use this as their default ..

/ip dhcp-server network
add address=172.17.18.0/24 comment=defconf dns-server=172.17.18.1 domain=home.lan gateway=172.17.18.1

Finally if you want to be smart you can add a script to the DHCP server so that it creates DNS entries for any addresses it issues. I cribbed one from somewhere, I haven’t taken the trouble to run though it and understand it but I know it works.

It’s half-true. The .local TLD is used by mDNS, and if all devices support it, it’s good idea to use it, because then the router as DNS server doesn’t need to be involved at all. But as manually configured it’s not good, because it conflicts with mDNS. Problem is that as the name suggests, it’s local, in fact very local. And to overcome that, router would have to be involved, but RouterOS currently doesn’t help with that. Related topic: mDNS repeater feature

Cheers! It works now using static DNS entries, so that’s something. It also works on L2TP road warrior clients, but I haven’t tested on site-to-site VPNs yet. But why do I need to add a static entry for the TrueNAS server even though TrueNAS’ UI allows for entering its hostname/domain there?

And in the list of DHCP leases, there are quite a few clients listed with host names – but I can’t access them by those host names – unless I add a static entry obviously.

This isn’t really important, I can assign static IPs to everything that I want to access by host name anyway, I just didn’t realise it was necessary to do it this way (but I don’t mind!)

What you enter on NAS is only for NAS itself, so that it knows its identity. Same for clients, they do have hostnames and they send them to DHCP server, but there’s no standard saying that DHCP server should add them to DNS (you can do it with DHCP lease script, look around the forum for some). Some clients can do DNS updates themselves, but you need DNS server that supports it. The one in RouterOS doesn’t.

:bulb: Got it! Makes sense.

I’d like to do just that. Can you post that script?

Set “zone” to same value as in the “domain” section of dhcp networks settings for this server.

:local zone "myzone.local"
:local dnsrecord [/ip dns static find where address=$leaseActIP]
:if ( $leaseBound = 0 ) do={
   :if ( [ :len $dnsrecord ] > 0 ) do={
     :log info "DNS removed record for $[/ip dns static get $dnsrecord name] ( $leaseActIP )"
    /ip dns static remove $dnsrecord
  }
} else={
  :local hostname [/ip dhcp-server lease get [/ip dhcp-server lease find where address=$leaseActIP server="$leaseServerName" ] host-name]
  :local fqdn
  :local dhcplease
  :foreach dhcplease in=[/ip dhcp-server lease find where ( server="$leaseServerName" && address=$leaseActIP ) ] do={
    :set hostname [/ip dhcp-server lease get $dhcplease host-name ]
    :set fqdn "$hostname.$zone"
    :local ttl [/ip dhcp-server lease get $dhcplease expires-after ]
    :if ( [ :len $dnsrecord ] > 0 ) do={
      /ip dns static remove $dnsrecord
    }
    :log info "DNS renewed record for $fqdn ( $leaseActIP, $ttl )"
    /ip dns static add name=$fqdn address=$leaseActIP ttl=$ttl comment=$leaseActMAC
  }
}