Hi all!
Are there a form to force all clients of my DHCP server to get a new IP address without reboot the client device?
Thank in advance!
Fabrício
/ip pool
add name=LAN-pool1 next-pool=LAN-pool2 ranges=192.168.1.100-192.168.101.110
add name=LAN-pool2 next-pool=LAN-pool3 ranges=192.168.1.111-192.168.101.120
add name=LAN-pool3 next-pool=LAN-pool4 ranges=192.168.1.121-192.168.101.130
add name=LAN-pool4 next-pool=LAN-pool5 ranges=192.168.1.131-192.168.101.140
add name=LAN-pool5 next-pool=LAN-pool1 ranges=192.168.1.141-192.168.101.150
The next-pool is necessary so a client receives an IP, even if a current pool is full.
# poolserver = lease active-server
# poolprefix = prefix for pools (ex. <poolprefix>1, <poolprefix>2, etc...)
:local poolserver "lan_dhcp"
:local poolprefix "LAN-pool"
# Internal processing here.....
# ----------------------------------
:local pools ""
# Get /ip pool list with prefix of $poolprefix
/ip pool {
:local poolname
:foreach p in=[find] do={
:set poolname [:tostr [get $p name]]
:if ([:pick $poolname 0 [:len $poolprefix]] = $poolprefix) do={
:if ([:len $pools] > 0) do={
:set pools ([:tostr $pools] . "," . $poolname) } else={
:set pools ($poolname) } }
}
# /ip pool
}
/ip dhcp-server lease {
:local activemac
:local activeaddress
:local poolused
:local newpool
# Convert dynamic leases to static and set it's address to lease pool
:foreach l in=[find] do={
:if ([get $l dynamic] = true && \
[get $l disabled] = false && \
[get $l active-server] = [:tostr $poolserver]) do={
:set activeaddress [get $l active-address]
:set activemac [get $l active-mac-address]
# Get lease's current pool
:set poolused ""
/ip pool used {
:foreach p in=[find] do={
:if ([get $p address] = [:toip $activeaddress] && [get $p info] = [:tostr $activemac]) do={
:set poolused [get $p pool] } }
}
:if ([:len $poolused] > 0) do={
:put ($activemac . " (" . $activeaddress . ") converting to static lease...")
make-static $l
:put ([:terminal cuu] . [:terminal el] . $activemac . " (" . $activeaddress . ") converting to static lease...[done]")
# Set new static lease's address to $poolused
:put ($activemac . " (" . $activeaddress . ") setting address to pool: " . $poolused . "...")
set $l address=[:tostr $poolused]
:put ([:terminal cuu] . [:terminal el] . $activemac . " (" . $activeaddress . ") setting address to pool: " . $poolused . "...[done]")
}
}
}
# Search /ip dhcp-server lease for bound static leases with address in pool from $pools list
:foreach l in=[find] do={
:set activemac [get $l active-mac-address]
:set activeaddress [:toip [get $l active-address]]
# If lease is static, bound, and has active-address and active-mac-address...
:if ([get $l dynamic] = false && [get $l status] = "bound" && \
[get $l active-server] = [:tostr $poolserver] && [get $l disabled] = false && \
[:len $activemac] > 0 && [:len $activeaddress] > 0) do={
# Get lease's current pool
:set poolused ""
/ip pool used {
:foreach p in=[find] do={
:if ([get $p address] = [:toip $activeaddress] && [get $p info] = [:tostr $activemac]) do={
:set poolused [get $p pool] } }
}
# If we found a matching pool...
:if ([:len $poolused] > 0) do={
# If lease's address is set to $poolused, increment to newpool
:if ([:tostr [get $l address]] = [:tostr $poolused]) do={
:set newpool [:find [:toarray $pools] [:tostr $poolused]]
:if ([:len $newpool] > 0) do={
:if ([:tonum $newpool] = ([:len [:toarray $pools]] - 1)) do={
:set newpool [:pick [:toarray $pools] 0] } else={
:set newpool [:pick [:toarray $pools] ([:tonum $newpool] + 1)] }
:put ($activemac . " - obtained lease from current pool: " . $poolused)
:put ($activemac . " - pool change: " . $poolused . " -> " . $newpool)
set $l address=[:tostr $newpool]
}
}
# end if [:len $poolused] > 0
}
# end if static, bound, and active lease addresses
}
# foreach l
}
# /ip dhcp-server lease
}