DHCP server on MikroTik
Fixed addresses for devices, DNS names and addresses only for your own devices.
A RouterOS 7 script — with check and undo.
Fixed addresses for devices, DNS names and addresses only for your own devices.
A RouterOS 7 script — with check and undo.
A script for RouterOS 7 (also fine for 6.4x): the router address in the network, an address pool, gateway, DNS, domain, lease time, fixed addresses for devices with DNS names like printer.lan, and option 66 for IP phones. If the interface already has a DHCP server, for example from the default configuration, the script reconfigures it instead of adding a second one.
The device always gets the same address. The script removes old leases of these MACs and addresses. Any MAC format works.
The script is built in your browser; addresses and MACs are not sent anywhere.
In its default configuration a MikroTik already hands out addresses in the local network. This page helps to tidy that up: give the printer, NAS and cameras fixed addresses, reach them by names like nas.lan, tell IP phones where their settings server is and, if you like, let only known devices into the network.
In this mode the server has no free pool (address-pool=static-only): only listed devices get an address. The server adds them to the ARP table itself (add-arp), and the interface gets arp=reply-only, so the router answers only those addresses. A device with a hand-typed address does not reach the internet. This protects against casual connections, not a targeted attack: a MAC can be faked. Keep guests apart with the MikroTik guest Wi-Fi, and split networks with MikroTik VLANs.
RouterOS does not exclude static lease addresses from the pool. While a device with a fixed address is off, the router may give that address to someone else, and later there is a conflict. So, for example, the pool is .100-.254 and fixed addresses are .2-.99.
No: if the interface already has a DHCP server, the script switches it to the new pool and lease time and leaves the rest alone. Still, save a copy first: /export file=before-dhcp.
In WinBox: IP → DHCP Server → Leases, select the lease and click Make Static. The generator is handier with many devices or when you need DNS names: it removes old leases of these MACs itself.
The names from this page are answered by the router's own DNS. Choose “The router itself” in the DNS field, or set the router's address as DNS on the device by hand. Check on a computer: nslookup printer.lan