How does the lab turn a Suricata detection into prevention, and what does the nftables rule do?
Suricata runs as a passive NIDS and only alerts, so blocking is done separately: an nftables rule drops all TCP packets the VM would forward to the offending server.
Detection and prevention are split. Suricata notices the hit; then the administrator adds a firewall rule on the same VM:
sudo nft insert rule ip filter FORWARD ip protocol tcp ip daddr <server IP> counter drop
| Part | Meaning |
|---|---|
insert rule |
add a rule at the start of the chain (add rule would append it at the end) |
ip |
address family: IPv4 |
filter |
the table |
FORWARD |
the chain for packets routed through this host |
ip protocol tcp |
match TCP |
ip daddr <server IP> |
match the destination address |
counter |
count matching packets and bytes (useful to verify the rule hits) |
drop |
silently discard the packet |
insert matters because nftables evaluates rules in order, and Docker has already created rules in this chain. Appended at the end, the drop might never be reached if an earlier rule accepts the traffic first.
To remove it later, list the chain with handles (nft -a list chain ip filter FORWARD) and delete by handle (nft delete rule ip filter FORWARD handle N).
This is manual prevention. An IPS would do the same automatically by running Suricata inline with drop rules.
Go deeper:
nftables in 10 minutes — tables, chains, hooks, address matches and verdicts on one page.
Simple rule management (nftables wiki) — adding, inserting, listing and deleting rules by handle.