This script is designed to run on a MikroTik RouterOS device and automatically add DNS entries for all active DHCP leases.
-
The script first gets the top-level domain name from the DHCP server's network settings.
-
It then sets a time-to-live (TTL) value for the DNS records to distinguish them from other static DNS entries.
-
Any existing dynamic DNS entries with the same TTL value are removed.
-
The script loops through all active DHCP leases and gets the hostname and IP address for each.
-
If a hostname exists for the lease, it is concatenated with the top-level domain name obtained earlier.
-
The script checks if the DNS entry already exists and, if not, adds the new DNS entry with the hostname and IP address.
-
If the hostname is empty for a lease, a message is displayed indicating that the hostname is empty.
-
Add the script to your scripts in System -> Scripts
-
/system scheduler add interval=30m name=HostToDNS on-event="/system script run htd"
The script will automatically add DNS entries for all active DHCP leases on the network.