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.

DHCP server on MikroTik

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.

Usually bridge, the LAN bridge. For a separate network, its VLAN interface.
Becomes the gateway for devices. If the interface has no such address, the script adds it.
A range with a hyphen, short form allowed: .100-.254. Keep fixed addresses outside the pool.
Optional. With the domain lan, devices are reachable as printer.lan.
1d, 8h, 30m. An hour or two for guests, a day or more for an office.
Optional. The server SIP phones download their settings from.

Fixed addresses

The device always gets the same address. The script removes old leases of these MACs and addresses. Any MAC format works.

Script

   
Check

   
Undo

   

The script is built in your browser; addresses and MACs are not sent anywhere.

How to set up DHCP on MikroTik

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.

How to use it

  1. Enter the interface (usually bridge), the router address with prefix and the range to hand out.
  2. Choose DNS, domain and lease time.
  3. Add devices that need a fixed address: name, MAC and an IP outside the pool.
  4. Paste the script into the WinBox terminal, or upload the .rsc file and run /import, then reconnect the devices.

Known devices only

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.

Frequently asked questions

Why take fixed addresses from outside the pool?

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.

Will the script break the default configuration?

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.

How do I make an address a device already got permanent?

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.

Why does printer.lan not work?

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 .

More tools

MikroTik

MikroTik guest Wi-Fi
Isolation, speed limits, QR code
CAPsMAN on MikroTik
One Wi-Fi on all APs, guests in a VLAN
MikroTik speed limits
Simple queues, PCQ, limits by address
MikroTik dual WAN
Backup link and load sharing with a link check
MikroTik configuration diff
What changed between two /export outputs
MikroTik backups
Backup and /export on a schedule to e-mail or SFTP
MikroTik configuration audit
Find holes in /export and get fix commands
MikroTik basic protection
Firewall, services and management access in one script