Skip to content

wikidotexe/Script-Bandwith-DHCP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Bandwidth Auto-Configuration Using DHCP Client Scripts

This repository provides a straightforward method to automatically configure bandwidth allocation for DHCP clients based on their MAC addresses using MikroTik scripts. This setup ensures efficient bandwidth management for your network.


Features

  • Dynamic Bandwidth Allocation: Automatically assigns bandwidth limits based on the MAC address of DHCP clients.
  • Queue Management: Utilizes PCQ (Per Connection Queue) types for optimized upload and download rates.
  • Scalable Solution: Configures queues dynamically, ensuring seamless management for growing networks.

Prerequisites

  1. MikroTik RouterOS with DHCP Server enabled.
  2. Winbox (or terminal access to the router).
  3. Basic familiarity with MikroTik scripting and queue management.

Step-by-Step Setup

1. Create PCQ Queues

First, configure PCQ (Per Connection Queue) types for both upload and download rates. These queues ensure that bandwidth is allocated proportionally among clients. Follow these steps:

  1. Open the MikroTik terminal in Winbox.
  2. Run the following commands to create PCQ queues:
/queue type add kind=pcq name=pcq_download pcq-rate=500M pcq-classifier=dst-address  
/queue type add kind=pcq name=pcq_upload pcq-rate=500M pcq-classifier=src-address  

These queues specify the bandwidth limits (500 Mbps in this case) for download and upload. You can adjust the pcq-rate value as per your network requirements.


2. Configure the DHCP Lease Script

Use the following script to dynamically create or remove queues based on the DHCP lease status of a client.

:local queueName "Client- $leaseActMAC";  
:if ($leaseBound = "1") do={  
    /queue simple add name=$queueName target=($leaseActIP . "/32") queue=pcq_upload/pcq_download comment=[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name];  
} else={  
    /queue simple remove $queueName  
}

How It Works:

  • Lease Bound (Connected): When a DHCP lease is bound to a client, the script dynamically adds a simple queue using the client’s MAC and IP address.
  • Lease Unbound (Disconnected): If a client disconnects, the corresponding queue is removed automatically.

Adding the Script to Your DHCP Server

  1. Go to IP > DHCP Server > Leases in Winbox.
  2. Open the Script tab.
  3. Paste the script provided above.
  4. Save the changes.

Example Use Case

For a client with:

  • MAC Address: 00:1A:2B:3C:4D:5E
  • IP Address: 192.168.1.10

The script dynamically creates a queue named Client-00:1A:2B:3C:4D:5E and assigns the specified PCQ limits for uploads and downloads.


Benefits

  • Automated Management: Eliminates the need for manual queue creation.
  • Efficiency: Dynamically removes queues for inactive clients, reducing unnecessary load.
  • Scalability: Supports networks of any size with minimal configuration adjustments.

Customization

  • Queue Names: Modify the queueName variable format as needed.
  • Bandwidth Limits: Adjust pcq-rate values in the PCQ setup commands for custom limits.
  • Script Enhancements: Add logging or notification features for better monitoring.

Troubleshooting

  • Queues Not Created: Ensure that the DHCP lease script is enabled and correctly configured.
  • Incorrect Bandwidth Allocation: Verify PCQ classifier settings and rates.
  • Script Errors: Test the script in the MikroTik terminal to debug issues.

Contributing

Contributions are welcome! If you have suggestions for improvements or additional features, feel free to submit a pull request.


License

This project is licensed under the MIT License. See the LICENSE file for more details.


Enjoy automated bandwidth management with MikroTik!

About

Automatic set bandwith with MAC Address

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published