Can DHCP Stop Leasing Ip On Provided Date?
For Example : User Cannot Get Ip After 30 Days (Like 30 Of Every Month at 12:00 am)
No, you cannot.
I’m guessing at your use case since you don’t give many details, but you’re selling service and want to block users at the end of the month unless they’ve paid for the next month. One feasible workaround would be to enter static leases for the customers in “/ip dhcp-server lease”. Mark them with comments. Then schedule a script at the end of the month that finds all those leases with those comments and sets “block-access” to “yes”:
[admin@MikroTik] > /ip dhcp-server lease print detail where comment="test"
Flags: X - disabled, R - radius, D - dynamic, B - blocked
2 ;;; test
mac-address=AA:BB:CC:DD:EE:FF
[admin@MikroTik] > :foreach LEASE in=[/ip dhcp-server lease find comment="test"] do={ /ip dhcp-server lease set $LEASE block-access=yes }
[admin@MikroTik] > /ip dhcp-server lease print detail where comment="test"
Flags: X - disabled, R - radius, D - dynamic, B - blocked
2 B ;;; test
mac-address=AA:BB:CC:DD:EE:FF block-access=yes
Thanks alot Fewi.
can u guide me in winbox interface?
it take ur couple of mins but this will make us able to configure this rule perfectly.
Thanks Again.
I don’t have access to winbox on this machine.
can u do that later ? or please ask someone else to provide this rule in winbox.
Thanks Alot.
Which part don’t you understand? Blindly running configuration you don’t understand is generally a bad idea.
i read this method in pervious threads and tried my self but unable to get what i need.
thats y write this request. that rule require to be made in the end of the month.
but i need the automatically script by which users cannot get ip automatically on its last date.
i do that manually every month in the end of month by disabling their Ip but it take much time to disable Ips 1 by 1.
any option to make it automatic.?
Right. So I gave you a script:
:foreach LEASE in=[/ip dhcp-server lease find comment="test"] do={ /ip dhcp-server lease set $LEASE block-access=yes }
Which finds all static DHCP leases that have a comment of “test” and blocks access for those clients. You then create a scheduled job (System/Scheduler) and set it to run at midnight on the last of the month, and use that script as the code to run on the event. Just make sure to swap out the “test” comment for something sensible and edit the one line script to reflect that, set static DHCP leases for all clients and make sure to apply that comment to those that need to be disabled by the script.