Sunday, December 22, 2019

Creating Automatically Simple Queue using DHCP Server Lease Script

Let's get started and login to your winbox :
1. First, create DHCP server using DHCP Setup in IP - DHCP Server, set all setting according to your needs.

2. Create a Simple Queue and give it name Wifi, set Max-limit and other setting according to your needs. This queue will be parent queue for dhcp client queue.

2. Then click on DHCP server you just created and copy paste the script below to Lease Script box :

:local queueName "HOTSPOT- $leaseActMAC";
:if ($leaseBound = "1") do={
/queue simple add name=$queueName target=($leaseActIP . "/32") max-limit=2M/10M limit-at=126k/1M priority=7/7 parent=Wifi;
} else={
/queue simple remove $queueName
}


4. Check the result after you connected a devices to mikrotik  through DHCP Server interface in Simple Queue. A new queue called HOTSPOT-4C:49:XX:XX will show up under Wifi queue as child queue.



















5. The Following script is the complete version of the script. With this script it will check if a parent queue with name Wifi exists or not . If it doesn't exist, the script will create a new parent queue called Wifi. 192.168.1.0/24 is your network address. Set it and all other settings according to your needs.

:local parent [/queue simple find name=Wifi]
:local network "192.168.1.0/24"
:local queueName "HOTSPOT- $leaseActMAC";
:if ([:len $parent] = 0) do={/queue simple add name=Wifi max-limit=10M/50M target="$network" queue=default/default}
:if ($leaseBound = "1" && $leaseServerName != "all") do={
/queue simple add name=$queueName target=($leaseActIP . "/32") max-limit=1M/10M limit-at=126k/1M priority=7/7 parent=Wifi queue=default/default;
} else={
/queue simple remove $queueName
}

Note :

&& $leaseServerName != "all" : With this, we can set different limit for a client in simple queue. Change dhcp server for the client to all. Don't forget to make the client lease static.

Reconnect the client to the network, then go to simple queue and change the bandwidth limit. Don't change the name, instead write description in "comment" button. 

To make sure all client get limited in bandwitdh, we can set only client who gets ip from dhcp server ( not static ) can connect to internet. Here's how it's done :
- Go to Ip - Dhcp Server, then click on dhcp1 or dhcp server you just created. Check Add Arp For Leases :


- Then change ARP parameter on Dhcp Interface to reply-only. If you don't bridge interfaces, just set ARP parameter on interface that dhcp server uses. If you bridge interfaces, set ARP parameter on bridge interface and slave interfaces of the bridge ( interfaces that used for bridge)

 -  If you still want the client who has set static ip on their device can connect to internet, you must make the mac address and ip for the client static in Ip - ARP List


  Source : https://labkom.co.id/mikrotik/membuat-simple-queue-otomatis-dari-dhcp-server-leases

No comments:

Post a Comment