Firewall

Time-Based Internet Rules on MikroTik (Office Hours and Night Block)

Allow or block internet, or specific sites, by time of day and weekday on a MikroTik router with the firewall time matcher, including midnight rules and the Bangladesh work week.

Commands in this article follow RouterOS v7 documentation but have not yet been marked as lab-tested on this site. Always test changes in a lab or maintenance window and keep a backup.

Problem

You want internet rules that depend on the time: for example no social media during office hours, or no internet for students' devices after 11 PM.

Symptoms

  • A time rule works at the wrong hours.
  • A night block that should run from 11 PM to 6 AM never works.

Likely causes

The firewall time matcher uses the router's clock, so a wrong time zone shifts every rule. A time range cannot cross midnight in one rule.

Prerequisites

  • Correct time on the router (RouterOS v7 shown; on v6 the NTP client uses primary-ntp= instead of servers=):
RouterOS CLI
/system clock set time-zone-name=Asia/Dhaka
/system ntp client set enabled=yes servers=time.google.com
/system clock print
  • An address list with the affected users, for example students.

Solution (WinBox / CLI)

Night block from 11 PM to 6 AM needs two rules, one before and one after midnight:

RouterOS CLI
/ip firewall filter
add chain=forward src-address-list=students out-interface-list=WAN time=23:00:00-23:59:59,sun,mon,tue,wed,thu,fri,sat action=drop comment="Night block" place-before=0
add chain=forward src-address-list=students out-interface-list=WAN time=00:00:00-06:00:00,sun,mon,tue,wed,thu,fri,sat action=drop comment="Night block" place-before=0

Office hours (Bangladesh work week, Sunday to Thursday): add the time condition to any rule, for example the YouTube rule from How to block Facebook and YouTube:

RouterOS CLI
/ip firewall filter add chain=forward src-address-list=staff protocol=tcp dst-port=443 tls-host=*.youtube.com time=09:00:00-17:00:00,sun,mon,tue,wed,thu action=reject reject-with=tcp-reset comment="Office hours YouTube" place-before=0

Note: Place time rules at the top of the forward chain. Below the "accept established" rule they only affect new connections, so a video that started before 9 AM keeps playing.

Verification

  • /system clock print shows the correct local time.
  • /ip firewall filter print stats where comment~"Night block" counters rise during the blocked hours.

Common errors

  • Time zone not set: rules run 6 hours off (UTC instead of Dhaka time).
  • One rule from 23:00 to 06:00: it never matches. Split it at midnight.
  • FastTrack: fasttracked connections skip the time rule. Exclude the affected users from FastTrack.

Rollback

RouterOS CLI
/ip firewall filter disable [find comment="Night block"]
Go deeper in class

This topic is covered hands-on in MTCTCE — MikroTik Certified Traffic Control Engineer.

View MTCTCE
WhatsApp