Mikrotik – How To Speed Limit With DHCP?
In this article, Mikrotik
devices and DHCP Server
is the desire to make an IP based speed limit. We will now see how to do this together. For example, when the user requests an IP, the DHCP Server
adds a rule about speed while giving IP. When DHCP lease time expires or is deleted from the lease list, our rule with speed limitation will also be disabled.
Of course, we need to pay attention to a subject here. If the user has given a manual IP address, that user is not subject to the speed limit. To avoid such a situation, you should write a rule that will affect your entire network.
If everyone gets IP from DHCP and manual IP address can be prevented, user-based speed stabilization can be done and we have the opportunity to monitor their speed from the.
We will need to use a script to do this. We will use the following script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # -------------------------------------------------------------------- # When IP is received from the DHCP server, it implements bandwidth. # # https://techsoftcenter.com/ # -------------------------------------------------------------------- :local IP $leaseActIP; Queues Lis # If he is a newcomer. :if ($leaseBound = "1") do={ :local MAC [/ip dhcp-server lease get [find active-address=$IP] mac-address]; # Puts Bandwidth restriction. /queue simple add name=$IP target=$IP parent=none packet-marks="" priority=1/1 queue=default-small/default-small limit-at=512k/4M max-limit=512k/4M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s bucket-size=0.1/0.1 comment=[/ip dhcp-server lease get [find where active-mac-address=$MAC && active-address=$IP] host-name]; # If the system has expired, it deletes the restriction. } else={ # Deletes the restriction. /queue simple remove $IP } |
In the example we will do, we have given the Download value 4M, the upload value 512kbit. (limit-at = 512k / 4M max-limit = 512k / 4M
)
If you want to change it, you can change the values in “limit-at = 512k / 4M max-limit = 512k / 4M
”. Change both values. “Limit-at = Upload / Download max-limit = Upload / Download“. k = Kilobit, M = Megabit
.
When connected with Winbox, go to System> Script menu. Add a new rule with “+” and paste the code. Give it a name you want. (No gap)

Now go to IP> DHCP Server menu. Click on the DHCP Server segment here. In the window that opens, we press the + button in DHCP and we come to the Script segment in the window that opens. Here we give the name we gave to the Script List section and click OK.

A new rule will now be added to the Queues List
for clients receiving IP. Also, we want to check. It takes and writes the “Hostname” part of the client as a “Comment“.

We now know how to do speed stabilization in DHCP
based IP
distribution.
I hope it was a useful article.