How to limit bandwidth using mikrotik with script


 

To limit bandwidth using MikroTik, you can create simple queue rules with scripting or directly from the MikroTik RouterOS interface. Here, I'll provide a guide on how to limit bandwidth using both methods.

Method 1: Using the MikroTik RouterOS Interface

  1. Log into your MikroTik Router: Access the MikroTik RouterOS through Winbox, the web interface, or SSH.
  2. Create a Queue Type:
    • Go to "Queues" in the MikroTik interface.
    • Click on the "Queue Types" tab.
    • Click the "+" icon to create a new queue type.
    • Set the name, rate, and max-limit for the queue type. For example:
      • Name: "1Mbps-limit"
      • Rate: 1M
      • Max Limit: 2M (this is the maximum burst speed)
    • Click "OK" to create the queue type.
  3. Create a Simple Queue:
    • Go to "Queues" in the MikroTik interface.
    • Click on the "Simple Queues" tab.
    • Click the "+" icon to create a new simple queue.
    • Set the target address (the IP address or IP range you want to limit), the queue type (the one you created in step 2), and other parameters.
    • For example, if you want to limit a specific IP address to 1Mbps down and 256Kbps up, set the parameters accordingly.
    • Click "OK" to create the simple queue.
  4. Verify the Bandwidth Limit:
    • Test the bandwidth limit by generating traffic from the specified IP address and monitoring the bandwidth usage in the MikroTik interface.

Method 2: Using Script to Create Queue Rules

Here's how you can create queue rules to limit bandwidth using a script. You can execute this script via the terminal in the MikroTik RouterOS:

 

bash

# Define variables

:local limit 1M      # Set your desired limit (e.g., 1Mbps)

:local targetIP "192.168.1.2"  # Set the IP address to limit

 

# Create a queue type

/ip queue type add name=1Mbps-limit kind=pcq pcq-classifier=dst-address pcq-rate=$limit pcq-limit=50 pcq-total-limit=2000

 

# Create a simple queue with the specified target IP

/queue simple add target=$targetIP dst=$targetIP/32 name=1Mbps-limit parent=global-out packet-marks="" priority=8/8 queue=1Mbps-limit limit-at=0/0 max-limit=$limit burst-limit=0/0 burst-threshold=0/0 burst-time=0s

 

 

In this script, you can modify the limit and targetIP variables to set your desired bandwidth limit and target IP address. After configuring the variables, execute the script in the MikroTik terminal.

Both of these methods will allow you to limit the bandwidth for specific IP addresses or IP ranges on your network. The first method is more user-friendly, while the second method using a script provides more control and automation.

 

Viewers
Read Also

No comments:

Post a Comment

SEARCH