Skip to content

How to Use iptables String Module

DodaTech Updated 2026-06-24 2 min read

The string module inspects packet payloads for pattern matching. It enables content-based filtering at the firewall level. This guide walks through the specific troubleshooting steps to diagnose and resolve string matching 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

No content-based filtering in firewall

Wrong: No content inspection

iptables -A FORWARD -p tcp --dport 80 -m string --algo bm --string "malicious" -j DROP

Right: Dropping packets containing the string malicious

Output

String match configured:\n  Algorithm: Boyer-Moore\n  Pattern: malicious\n  Port: 80 (HTTP)

Prevention

To avoid future issues, follow these best practices:

  • Use --algo bm (Boyer-Moore) for most patterns, kmp (Knuth-Morris-Pratt) for patterns with repeated substrings
  • String matching inspects packet payload on all TCP connections
  • String match is CPU-intensive -- use with rate limiting
  • Test patterns with known traffic to verify matches
  • Use LOG rule before DROP to see what is being blocked

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 string

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

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 algorithms are available for string matching?|||bm (Boyer-Moore) is faster for most patterns. kmp (Knuth-Morris-Pratt) is better for patterns with repeated characters.
Does string matching work on encrypted traffic? No. String matching inspects plaintext payloads. It works on HTTP (port 80) but not HTTPS (port 443).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro