Write a script for mikrotike router to limite the use of data depend on mac address
- User
Write a script for mikrotike router to limite the use of data depend on mac address
- Assistant
Sure! Here's a script for MikroTik router to limit data usage based on MAC address:
/queue type add name="limited" kind=pcq pcq-classifier=dst-address pcq-dst-address-mask=32
pcq-limit-at=0 pcq-rate=0 pcq-total-limit=2000KiB/ip firewall mangle add action=jump chain=forward comment="Limit Data Usage" jump-target=limit_data
src-mac-address=00:11:22:33:44:55/ip firewall mangle add action=mark-packet chain=limit_data comment="Mark Limited Traffic"
connection-mark="" dst-address-type=!local jump-target="limit_by_mac"
limit=2000KiB log-prefix="" mac-protocol="" passthrough=yes src-address-type=local/ip firewall mangle add action=jump chain=limit_by_mac comment="Apply Limit"
jump-target=limited limit-at=0 src-mac-address=00:11:22:33:44:55/ip firewall mangle add action=return chain=limit_by_mac comment="No Limit"
src-mac-address=!00:11:22:33:44:55/ip firewall mangle add action=mark-connection chain=limited comment="Mark Connections"
connection-mark="" dst-address-type=!local limit=2000KiB
mac-protocol="" new-connection-mark="" passthrough=yes
src-address-type=local/ip firewall filter add action=accept chain=forward comment="Allow Limited Traffic"
connection-mark=limited dst-address-type=!local src-address-type=!local/ip firewall filter add action=drop chain=forward comment="Drop Excess Traffic"
connection-mark="" dst-address-type=!local src-address-type=!localBrief Explanation of the Script:
- Define a new queue type called "limited" with a total limit of 2000KiB using the pcq (Per-Connection Queue) method.
- In the forward chain of the firewall mangle table, specify a jump-target called "limit_data" for packets with the specific source MAC address.
- Mark the packets traversing through "limit_data" chain with the mark-packet action to distinguish them from other traffic.
- In the "limit_data" chain, jump to the "limited" chain for packets originating from the specified MAC address.
- Apply the desired limit (2000KiB) in the "limited" chain based on the MAC address.
- Allow limited traffic with the accept action in the forward chain of the filter table.
- Drop excess traffic with the drop action in the forward chain of the filter table.
Remember to replace "00:11:22:33:44:55" with the desired MAC address you want to limit. Make sure to adjust the data limit and any other parameters as per your requirement.