Community discussions

MikroTik App
 
JNK
just joined
Topic Author
Posts: 8
Joined: Tue Feb 10, 2015 5:00 pm

Feature Request: Add non-static DHCP clients to address-list

Sat Mar 14, 2015 10:17 am

Static Leases can be added dynamically to address-lists in the lease-definition. That is a great feature, as this address-list can be used in firewall-rules to block traffic from unassigned IP-addresses.

Dynamic-Leases from the pool cannot be added, it would be nice to have that feature too. Maybe it can be done with the lease-script, but it would be easier if the DHCP server could do this directly.

Best Regards,

Jan
 
santa
newbie
Posts: 43
Joined: Sun Jul 06, 2014 10:53 pm
Location: POLAND, Gdansk

Re: Feature Request: Add non-static DHCP clients to address-list

Mon Mar 16, 2015 4:14 pm

+1 :)

Very good idea, it would be useful.
 
User avatar
cbrown
Trainer
Trainer
Posts: 1839
Joined: Thu Oct 14, 2010 8:57 pm
Contact:

Re: Feature Request: Add non-static DHCP clients to address-list

Mon Mar 30, 2015 10:01 pm

Agreed it would be nice but here is how I do it in lease-script.
:if ($leaseBound = "1" ) do={
/ip firewall address-list add address=$leaseActIP list=DHCP
:log info "Lease $leaseActIP added to AList"

} else={
/ip firewall address-list remove numbers=[find where address=$leaseActIP]
:log info "Removing Lease $leaseActIP from AList"
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12657
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Feature Request: Add non-static DHCP clients to address-list

Tue Mar 31, 2015 1:01 am

Already exist lease time script on dhcp-server options (ROS 6.27).
IS possible to add the ip to one address-list for the same time of the lease.
 
User avatar
Nexon
newbie
Posts: 27
Joined: Tue Jan 31, 2006 9:38 am
Location: Serbia
Contact:

Re: Feature Request: Add non-static DHCP clients to address-list

Sat Aug 08, 2020 4:16 am

The above script does not work for me.
Is there a way to add dynamic dhcp leases to the ip firewall address list?
 
User avatar
sindy
Forum Guru
Forum Guru
Posts: 11317
Joined: Mon Dec 04, 2017 9:19 pm

Re: Feature Request: Add non-static DHCP clients to address-list

Sat Aug 08, 2020 3:47 pm

The above script does not work for me.
Where have you placed the above script? Into the lease-script item of an /ip dhcp-server row or to /system script? The first variant is correct. Also, the lease has to change state if I remember correctly, so a mere lease renewal after adding the script will not trigger it - you have to disconnect the device, let the lease expire, and let the device request a lease again.
 
User avatar
Nexon
newbie
Posts: 27
Joined: Tue Jan 31, 2006 9:38 am
Location: Serbia
Contact:

Re: Feature Request: Add non-static DHCP clients to address-list

Sat Aug 08, 2020 4:10 pm

Yes, I put the script into the /ip dhcp-server inside the lease-script.

I need to control WiFi connected clients, to have internet connection for an hour, and after that time to not to have internet connection for an hour.
My idea is is to control that by /ip firewall address-list with timeout option and /ip firewall filter.

Is there a lease-script that can add any new dhcp dynamic entry to address-list?
 
User avatar
sindy
Forum Guru
Forum Guru
Posts: 11317
Joined: Mon Dec 04, 2017 9:19 pm

Re: Feature Request: Add non-static DHCP clients to address-list

Sat Aug 08, 2020 6:01 pm

I need to control WiFi connected clients, to have internet connection for an hour, and after that time to not to have internet connection for an hour.
For that, a lease script is not sufficient. No problem to add timeout=1h to the /ip firewall address-list add ... in the lease script, but doing so would just limit access for the first hour after getting the address; once that hour expires, the lease script will not re-add the address to the list until the dhcp lease expires and gets assigned (not renewed) again. So you need three lists:
  • one to store the addresses currently leased
  • a "permit" one where the users which enjoy their active hour are placed
  • a "deny" one where the users which suffer their gap hour are placed
So the lease script will add the address to the first two lists if it doesn't find it at the first one, to the first one for a week and to the second one for an hour. A scheduled script running every minute will move the addresses between the permit and deny lists each time the timeout of a given address on its current list is below 2 minutes.

The lease duration needs to be at least two hours - if another device would get the same IP which is still on the first list, it might fall into the deny period; if you cleared the first list at lease expiration, it would be enough to switch the WiFi client off for the lease time, so after its expiration, the whole cycle would start from scratch (the permit hour).

But people are creative, so be prepared that they will use a second mobile to stay online all the time :)