Community discussions

User avatar
Forum Guru
Forum Guru
Topic Author
Posts: 1290
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at

DHCP automatic dynamic to static

Wed Apr 03, 2019 3:41 pm

DHCP dynamic to static lease

I did search for a script that did convert dynamic lease to static lease, but did not find any good solution.
So I made a new script that is placed in the DHCP server settings and convert the dynamic IP to static IP.

Cut and past to:
IP->DHCP-Server->Select your dhcp server->Lease Script

PS this makes all IP static, no expedition.
# Created Jotne 2019 v1.2
# This scripts stats all DHCP release to static automaticalle
# It should run on all routerOS version

# Test if this is a Bound session and the lease is a dynamic one. Do not change older reservation
:if (($leaseBound=1) && ([/ip dhcp-server lease find where dynamic mac-address=$leaseActMAC]!="")) do {

# Get the lease number
	:local Lease [/ip dhcp-server lease find mac-address=$leaseActMAC]
# Get date and time
	:local date [/system clock get date]
	:local time [/system clock get time]
# Make the lease static	
	/ip dhcp-server lease make-static $Lease
# Add date and time as a comment to show when it was seen first time	
	/ip dhcp-server lease comment comment="$date $time" $Lease
# Send a message to the log	
	:log info message="script=dhcp_static server=$leaseServerName IP=$leaseActIP MAC=$leaseActMAC"

If you like to start with converting all current dynamic IP to static in one go, run this from command line.
:local date [/system clock get date]
:local time [/system clock get time]
:foreach lease in=[/ip dhcp-server lease find dynamic] do={
	/ip dhcp-server lease make-static $lease
	/ip dhcp-server lease comment comment="$date $time" $lease
How to use Splunk to monitor your MikroTik Router


Who is online

Users browsing this forum: No registered users and 5 guests