Kellis
February 9, 2025, 8:33am
1
Hey there.
I’m trying to assign an IP pool based on the connection interface (just to keep Wi-Fi and ethernet clients grouped together).
My two IP pools are on the same subnet.
/ip pool
add comment=ethernet name=ethernet ranges=192.168.88.10-192.168.88.99
add comment=wifi name=wifi ranges=192.168.88.100-192.168.88.254
When it comes to the lease script, there are some issues I cannot fix
So my lease script is
:local clientMAC $leaseActMAC
#:log info $clientMAC
:local clientInterface [/interface bridge host get [find mac-address=$clientMAC] interface]
#:log info $clientInterface
:local wifiInterfaces {"2GHz-MikroTik-1";"5GHz-MikroTik-1"}
#:log info $wifiInterfaces
#:foreach int in $wifiInterfaces do={:log info $int}
:if ($clientInterface="2GHz-MikroTik-1") do={
:log info ("Wi-Fi client " . $clientMAC . " detected on " . $clientInterface . ". Assigning from Wi-Fi pool.")
/ip dhcp-server lease set [find mac-address=$clientMAC] address=wifi
} else={
:if ($clientInterface="5GHz-MikroTik-1") do={
:log info ("Wi-Fi client " . $clientMAC . " detected on " . $clientInterface . ". Assigning from Wi-Fi pool.")
/ip dhcp-server lease set [find mac-address=$clientMAC] address=wifi
} else={
:if ($clientInterface="ether2") do={
:log info "Ethernet client $clientMAC detected on $clientInterface. Assigning from Ethernet pool."
/ip dhcp-server lease set [find mac-address=$clientMAC] address=ethernet
}
}
}
ISSUE #1
if ($clientInterface in $wifiInterfaces)
does not work at all, so I have to use nested IFs.
ISSUE #2 Im just stupid, fixed
Even with nested IFs, only the 1st interface is logged - so it looks like the logic doesn’t even go into the 2nd IF
info: Wi-Fi client XXXXX detected on 2GHz-MikroTik-1. Assigning from Wi-Fi pool.
ISSUE #3 Last but not least
/ip dhcp-server lease set [find mac-address=$clientMAC] address=wifi
Just throws a script error in the logs, but when I try it manually with a real MAC in the terminal it looks fine.
If it is important:
I have CAPsMan for WiFi interfaces
I have a bridge with Ethernet and WiFi interfaces
You try to set something on a dynamic lease?
Kellis
February 10, 2025, 2:58pm
3
I would say I want to override IP pool from config using lease script.
I don't want to create 2nd bridge and use 2nd DHCP server so my thought was it was possible through script.
In what you wrote I didn’t read the answer.
It is implicit that it cannot be done in dynamic leases, but only in static ones.
It is difficult for a smartphone to connect via ethernet,
it is likely that a laptop can connect (but with two different MACs) to both (and even simultaneously)
Kellis
February 10, 2025, 4:24pm
5
I am not sure about the right terminology, but we can call it Dynamic Lease.
It is implicit that it cannot be done in dynamic leases, but only in static ones.
It is difficult for a smartphone to connect via ethernet,
it is likely that a laptop can connect (but with two different MACs) to both (and even simultaneously)
That is why Im checking for the client's interface and its work, but part with assign does not work.
Are you trying to set (modify / change) something in a dynamic lease?
I don't think more or less correct English can make much difference in this question.
You haven't answered the question yet.
The answer can be yes or no, not a comment.
And I already wrote that dynamic leases cannot be changed.
Kellis
February 10, 2025, 5:24pm
7
Are you trying to set (modify / change) something in a dynamic lease?
I don't think more or less correct English can make much difference in this question.
You haven't answered the question yet.
The answer can be yes or no, not a comment.
And I already wrote that dynamic leases cannot be changed.
I probably misunderstood it.
Is "dynamic leases" one that DHCP servers serve?
If so, then I try to do it.
Then come next question if there way to achive my goal?
Question already closed.
There are plenty of ways to do this, but if you don’t know a fixed lease from a dynamic one,
I think it’s extremely difficult to do this by reading here and there on the forum,
unless someone sits down, analyzes the entire configuration of each machine and does it for you.
You must consider hiring a consultant.
Kellis
February 10, 2025, 5:34pm
9
I just want to keep my configuration as simple as possible.
So if there is no way to do script-based leasing then I will go with standard way with second bridge and dhpc server.