Rule structure
Every rule follows this format:| Field | Description |
|---|---|
action | What Snort does when the rule fires: alert, block, drop, pass, reject, etc. |
proto | Protocol: ip, icmp, tcp, udp, or a service name like http |
source | Sending IP address and port. Use any as a wildcard. |
dir | Direction: -> (unidirectional) or <> (bidirectional) |
dest | Receiving IP address and port. |
body | Detection options and metadata inside parentheses. |
Basic example
192.168.1.1:80 that contains the string attack.
Port-based vs service-based rules
Snort 3 supports two rule styles that differ in how traffic matching works.- Port-based
- Service-based
The protocol and ports in the rule header are always evaluated:Port-based rules are grouped into multipattern search engines keyed on protocol and port.
To match a service-based rule against a specific IP protocol, use the This guards against false positives from the rule also appearing in the “any” port group.
ip_proto IPS option:Common rule options
Identification options
Identification options
| Option | Description |
|---|---|
msg | Human-readable description of the alert |
sid | Signature ID (unique within a GID) |
gid | Generator ID. Text rules default to GID 1; SO rules to GID 3 |
rev | Revision number of the rule |
Flow and detection options
Flow and detection options
| Option | Description |
|---|---|
flow | Constrain to flow state, e.g. established, to_server |
content | Match a literal byte string |
nocase | Make the preceding content match case-insensitive |
fast_pattern | Mark this content as the fast pattern for the rule |
pcre | Match a Perl-compatible regular expression |
http_uri | Match in the HTTP URI buffer |
file_data | Match in the file data buffer |
pkt_data | Match in raw packet/TCP stream bytes |
Metadata options
Metadata options
| Option | Description |
|---|---|
classtype | Alert classification (maps to a priority) |
reference | External vulnerability reference, e.g. reference:cve,2023-1234 |
service | Force assignment to a service group |
metadata | Arbitrary key-value pairs |
Rule identification: gid:sid:rev
Rules are uniquely identified by the tripletgid:sid:rev.
- GID 1 — text rules (the default)
- GID 3 — shared-object (SO) rules
- GID 1xx — internal Snort components (decoder is GID 116, etc.)
Rule comments
Snort rules files support several commenting styles:Fast patterns and rule groups
At startup, Snort compiles rules into multipattern search engines (MPSE). Rules are grouped by protocol, port, and service so that a single parallel search covers all patterns in a group.Selecting the search algorithm
Configure viasearch_engine.search_method:
| Method | Trade-off |
|---|---|
ac_bnfa | Default. Balanced speed and memory. |
ac_full | Fastest search, significantly more memory. |
| Hyperscan | Best performance and reasonable memory. Requires Intel Hyperscan library. |
Fast pattern selection
Snort automatically selects the longest content in a rule as its fast pattern. Addfast_pattern explicitly to override this choice:
Snort 3 automatically skips the fast pattern re-check during rule evaluation when it is redundant. You do not need the old
fast_pattern:only Snort 2 option.- Negated contents that are also relative, case-sensitive, or have a non-zero offset/depth.
Rule group summary
At startup, Snort prints a summary underport rule counts and service rule counts. Use this to verify that rules land in the expected groups.
Stateful evaluation
When a match spans multiple packets (e.g., a file transferred over TCP), Snort pauses rule evaluation at the packet boundary and resumes when more data arrives. This is supported for:| Buffer | Description |
|---|---|
pkt_data | Contiguous TCP session bytes, split by direction (client→server, server→client) |
file_data | Bytes from the same file transfer, across packets |

