Skip to content

How to Use iptables iprange Module

DodaTech Updated 2026-06-24 1 min read

The iprange module allows efficient matching of IP address ranges without converting to CIDR notation or creating many individual rules. This guide walks through the specific troubleshooting steps to diagnose and resolve iprange 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 -s 10.0.0.1 -j DROP (single IP per rule)

Wrong: Individual rules for each IP

iptables -A INPUT -m iprange --src-range 10.0.0.1-10.0.0.50 -j DROP

Right: IP range match with iprange module

Output

IP range rule added: 10.0.0.1-10.0.0.50 blocked\nSingle rule replaces 50 individual rules\nPerformance: hash-based matching

Prevention

To avoid future issues, follow these best practices:

  • Use iprange for contiguous IP ranges instead of CIDR
  • The --src-range and --dst-range accept dash-separated start-end
  • Combine with other matches for granular rules
  • iprange is more readable than many CIDR rules
  • Test with iptables -L -v -n to verify match counts

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 iprange

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

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 is the difference between iprange and CIDR notation?|||CIDR matches subnets (10.0.0.0/24). iprange matches arbitrary ranges (10.0.0.1-10.0.0.50). iprange is useful when the range does not align to CIDR boundaries.
Can I specify both source and destination ranges? Yes. Use both --src-range and --dst-range in a single rule.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro