Suricata and Snort Rules Explained: Anatomy, Common Errors and Linting
Learn how Suricata and Snort IDS rules are built, which mistakes stop rules from loading or matching, and how to lint and maintain a local rules file.

Suricata and Snort Rules Explained: Anatomy, Common Errors and Linting
Network intrusion detection systems such as Suricata and Snort inspect traffic against rules, also called signatures. Most teams run large published rule sets and add a local.rules file with their own detections: a domain from a recent incident, an internal policy, a check for a vulnerability they have not patched yet. Local rules are where errors creep in, because they are written by hand under time pressure. This guide explains the rule format and the checks worth running before you reload the engine.
Anatomy of a rule
A rule has a header and options.
The header has seven parts: action, protocol, source address, source port, direction, destination address and destination port. For example, alert http $EXTERNAL_NET any -> $HOME_NET any. Actions include alert, drop, reject and pass. Protocols are tcp, udp, icmp and ip, plus application-layer protocols such as http, tls and dns in Suricata and Snort 3. Addresses and ports can be any, variables like $HOME_NET, lists in brackets, ranges and negations.
Options sit inside parentheses, separated by semicolons. They include msg, the text of the alert; sid, a unique number; rev, the revision; classtype; references; and the detection logic: content matches, modifiers, pcre, flow and many protocol-specific keywords.
How content matching works
content looks for bytes in a buffer. Printable text goes in quotes; other bytes go in pipes as hex, such as |3a|. Modifiers that follow a content change how it matches: nocase ignores case, depth and offset limit where to look from the start, distance and within place a content relative to the previous match, and fast_pattern picks which content the engine uses as its quick pre-filter. Suricata also has sticky buffers such as http.uri or tls.sni, placed before the content, that switch inspection to a parsed field.
Errors that stop rules from loading
- A missing semicolon after the last option, or an unescaped quote or semicolon inside content.
- An odd number of pipes or non-hex characters in a hex block.
- A content modifier with no content before it.
- Duplicate sids within the loaded rule set.
- Undefined variables, such as a $SQL_SERVERS that your configuration never sets.
- Keywords from another engine, such as Suricata sticky buffers in Snort 2.
Errors that load but never match
These are worse, because the engine is happy and you are not protected.
- A depth shorter than the content it limits, so the match can never fit.
- flow:to_server,to_client, which is a contradiction.
- distance or within on the first content, with nothing to be relative to.
- The wrong buffer: matching a URI string in the raw payload of a TLS session, for instance.
Performance hints
Rules without content are inspected against every packet in scope. pcre without a content pre-filter is expensive. TCP rules without a flow keyword inspect both directions, including unestablished packets. On a busy sensor, a few careless local rules can cause packet drops that hurt every other rule.
Linting a rules file
The Suricata and Snort Rule Validator checks all of the above in the browser. Choose Suricata, Snort 3 or Snort 2.9, paste or open a rules file, and it validates every header and option, reports duplicate sids, impossible content constraints, flow contradictions and performance concerns, and lists the variables the file depends on. Each rule can be explained in plain English, which helps reviewers who do not read signatures every day. Bulk actions add rev:1 where missing, renumber sids from a chosen start, raise a revision or comment a rule out, with undo for every change.
A safe workflow
- Keep local rules in version control, one rule per line, with sids in your own range starting at 1000000.
- Lint the file on every change.
- Load it with the engine's test mode, suricata -T or snort -T, against your real configuration.
- Replay a pcap that should trigger the rule and one that should not.
- Deploy, watch alert volumes for a day, and tune.
Limits
Static checks cannot prove a rule detects what you intend. They remove the mechanical mistakes, so your testing time goes into the detection logic itself.



