Skip to content

How to Use iptables Time Module

DodaTech Updated 2026-06-24 2 min read

The time module allows firewall rules to change based on time of day. This is useful for restricting access during off-hours. This guide walks through the specific troubleshooting steps to diagnose and resolve time-based rule issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

iptables -A INPUT -p tcp --dport 80 -j ACCEPT (always open)

Wrong: Service always accessible

iptables -A INPUT -p tcp --dport 80 -m time --timestart 09:00 --timestop 17:00 --weekdays Mon,Tue,Wed,Thu,Fri -j ACCEPT

Right: Service only accessible during business hours on weekdays

Output

Time-based rule added:\n  Port 80 allowed: Mon-Fri 09:00-17:00\n  All other times: blocked by default policy

Prevention

To avoid future issues, follow these best practices:

  • Use --timestart and --timestop for time range in 24h format
  • Use --weekdays to specify which days the rule applies
  • Use --datestart and --datestop for date range rules
  • Time rules use the server local timezone
  • Combine with LOG rules to track off-hours access attempts

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with time

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world IPTABLES code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What time format does the iptables time module use?|||HH:MM format in 24-hour notation. Example: --timestart 09:00 --timestop 17:00.
Can I use the time module with utc? Yes. Use --utc to treat times as UTC instead of local timezone.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro