The RouterOS DHCP Server (MRDS) from MikroTik doesn’t natively support registering hostnames from DHCP leases to its DNS server. Instead, it supports executing a “DHCP lease script” when new leases are issued, released, or expires. You can use a lease script to manage DNS entries for DHCP leases. However, this isn’t the best solution for managing static DNS registrations for your network hosts.
DHCP lease scripts may sound like the ideal solution, but MikroTik’s implementation in MRDS has some severe limitations. The lease script is only executed when a new DHCP lease is issued, released, or expires. In a perfect world, this should suffice.
Unfortunately, networking is messy and DHCP clients can behave unpredictably. Your phone or laptop may renew an expired DHCP lease when it wakes up from hibernation instead of requesting a new lease. The same can happen after a device change its Wi-Fi MAC address (as some do periodically as a privacy precaution). As the lease script isn’t executed for renewals, you won’t have a DNS entry for the host if the lease already has expired. The result is an unreliable DNS service.
dnsmasq server has a similar DHCP lease script feature. It has an additional
--script-on-renewal flag that enables it to better handle these situations. MikroTik hasn’t added a similar option in MRDS. You can’t rely on a DHCP lease script to provide reliable DHCP to DNS mappings in RouterOS.
Instead of a DHCP lease script, you’ll need to use a system script executed on a schedule. Hosts won’t immediately become available over DNS, but at least the service will be reliable. If you run the script once a minute, the average delay won’t be more than 30 seconds.
The scheduled system script should iterate through all your DHCP leases, assign or update existing DNS entries, and delete any unused DNS entries. You can use my DHCP to DNS script as an example. Install it in System: Scripts, and execute it on a repeating schedule through System: Scheduler. The script shouldn’t interfere with any other static DNS entries you might have set up.
To keep the memory consumption low, you may want to run the script in batches by subnets when dealing with many DHCP leases. My script doesn’t deal with internationalized domain names (IDN) or other hostname normalization. You must not deploy any scripts that don’t normalize hostnames in an environment where a device might try to register a pile-of-poo emoji as its hostname, hostnames could conflict, or the clients could be trying something more malicious.