Community discussions

MikroTik App
 
Jonas25
just joined
Topic Author
Posts: 1
Joined: Sun Feb 18, 2018 2:20 am

Automatic static ip after successful dhcp lease

Sun Feb 18, 2018 2:29 am

I serve internet access for my clients, they get an IP address through a dhcp server. Now I want that when a user with a device gets an IP address from the dhcp server that he always get the same IP address, based on his MAC address, when he connects on the network, it’s not possible to make them manually static because every day there are new devices. Is there a way to do this automatically?

Thanks
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Automatic static ip after successful dhcp lease

Mon Mar 25, 2019 9:34 pm

Here is a simple solution.

Save this as a script:
: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
	}
Make a scheduler and run it once an hour.

It will then take all active DHCP leases that are not static and set it static with the current date as a comment.

Who is online

Users browsing this forum: elvo3d, voytecky and 95 guests