Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Limit Data Usage Per User in MikroTik

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Limiting data usage per user in MikroTik routers helps control bandwidth consumption, prevent network abuse, and ensure fair resource allocation—especially in shared environments like offices, cafes, or apartment complexes. This guide walks you through setting up data quotas using MikroTik’s built-in tools: queues, address lists, and scripts. You’ll need basic familiarity with the MikroTik RouterOS interface (WinBox or WebFig) and administrative access to your router.

What You'll Need

  • A MikroTik router running RouterOS v6 or later
  • Administrative access via WinBox, WebFig, or terminal
  • Known IP addresses or DHCP client names for target users
  • Basic understanding of MikroTik’s firewall and queue systems

Step-by-Step

  1. Identify User Devices
    Determine the IP addresses or MAC addresses of the devices you want to limit. You can find these under IP > DHCP Server > Leases if using DHCP, or assign static leases for consistency.
  2. Create Address Lists
    Go to IP > Firewall > Address Lists. Click + to add a new list. Name it (e.g., user1) and enter the user’s IP address in the Address field. Repeat for each user. This allows you to group and track traffic per user.
  3. Set Up Traffic Monitoring with Mangle
    Navigate to IP > Firewall > Mangle. Click + to add a new rule:
    - Set Chain to forward
    - Under Src. Address, select the address list for the user (e.g., user1)
    - Go to the Actions tab, set Action to mark-connection
    - Enter a mark name like user1-conn
    - Click OK.
    Repeat this for each user, using unique connection marks.
  4. Mark Packets for Tracking
    Add another mangle rule:
    - Chain: forward
    - Connection Mark: select the mark you just created (e.g., user1-conn)
    - Action: mark-packet
    - Set New Packet Mark to user1-packet
    This enables packet tracking for queue usage.
  5. Create Simple Queues for Data Limits
    Go to Queues > Simple Queues. Click +:
    - Set Name to user1-limit
    - Under Target, enter the user’s IP address
    - Set Packet Marks to user1-packet (from step 4)
    - Under Limit At, set maximum download/upload speeds (e.g., 1M/512k)
    - Set Max Limit slightly higher (e.g., 2M/1M)
    - Enable Time if you want time-based restrictions (optional)
    This enforces bandwidth caps.
  6. Monitor Data Usage via Scripts
    Since MikroTik doesn’t natively support data quotas, use a script to track and disable access when limits are exceeded.
    Go to System > Scripts. Click + and name it check-user1-data. Paste this script:
    :local maxBytes 1073741824  # 1GB in bytes
    :local currentBytes [/interface monitor-traffic ether2 once as-value]->"rx-byte"
    :if ($currentBytes >= $maxBytes) do={
      /ip firewall filter add chain=forward src-address=192.168.88.10 action=drop comment="user1-quota-exceeded"
    }
    
    Replace ether2 with the user’s interface and 192.168.88.10 with their IP.
  7. Schedule the Script
    Go to System > Scheduler. Click +:
    - Name: run-user1-check
    - On Event: check-user1-data
    - Interval: 00:05:00 (run every 5 minutes)
    This ensures regular quota checks.
  8. Repeat for Other Users
    Duplicate steps 2–7 for each user, using unique names, marks, IPs, and scripts. Avoid reusing packet/connection marks to prevent conflicts.
  9. Test and Verify
    Have the user download a large file and monitor usage under Tools > Torch or Interfaces tab. Confirm the script triggers when expected and traffic is blocked after the limit.

Common Mistakes

  • Using wrong interface in script: Ensure monitor-traffic references the correct physical or bridge interface handling user traffic.
  • Overlapping firewall rules: A global allow rule above the drop rule may override it. Place quota-based drop rules above general allow rules in Firewall Filter.
  • Incorrect packet marking: If queues don’t activate, verify mangle rules are in forward chain and marks match exactly.
  • Not using address lists: Hardcoding IPs in multiple places makes updates error-prone. Use address lists for easier management.
  • Ignoring reset on reboot: Data counters reset after router restart. For persistent quotas, log usage externally or use User Manager (paid).

Tips

  • Use MikroTik’s User Manager (if available): It supports built-in data quotas and time limits, simplifying management for large networks.
  • Log quota events: Add /log info "User1 quota exceeded" in the script to track violations.
  • Set soft warnings: Modify the script to send an email or alert before blocking (requires SMTP setup).
  • Group users by tier: Use similar scripts for users with the same limit to reduce duplication.
  • Monitor overall usage: Use Tools > Graphing to visualize traffic trends and adjust limits accordingly.

Troubleshooting

If data limits aren’t enforced:

  • Check script execution: In System > Scripts, run the script manually. If it fails, verify syntax and interface/IP names.
  • Verify firewall rule order: Go to IP > Firewall > Filter. Ensure the drop rule for quota is above any accept rules for the same traffic.
  • Test packet marks: Use Torch on the user’s interface and filter by packet mark. If no traffic appears, mangle rules may be misconfigured.
  • Check scheduler status: In Scheduler, confirm the script runs at intervals. A disabled or errored script won’t enforce limits.
  • Confirm traffic direction: If users are behind NAT, ensure mangle rules are in forward chain, not output.

Frequently Asked Questions

  • Can MikroTik enforce monthly data caps?
    Not natively. Use scripts with external logging or User Manager for rolling monthly quotas.
  • Do I need User Manager for data limits?
    No. Scripts and queues can enforce limits, but User Manager offers easier control for many users.
  • Why isn’t my script blocking traffic?
    Check firewall rule order, script syntax, and ensure the drop rule targets the correct IP and chain.
  • Can I limit Wi-Fi users individually?
    Yes. Assign static IPs or DHCP leases and apply the same method per device.
  • Is bandwidth shaping the same as data usage limits?
    No. Shaping controls speed; data limits cap total volume. Use both for full control.
  • Will rebooting reset data usage?
    Yes. Built-in counters reset on reboot. For persistent tracking, use external monitoring.