Firewalls & Network SecurityTutorials

IDS and IPS: Detecting and Blocking Suspicious Traffic with OPNsense

What the firewall does not see, IDS on a copy of the traffic and inline IPS, signatures and anomalies, false positives, Suricata in OPNsense and a careful path from alert-only to blocking.

  • Category: Firewalls & Network Security · Tutorials
  • Published:
  • Editorial team: Alba Technology Academy
  • Reading time: about 8 minutes

A well-configured firewall lets through only the expected traffic, but “expected” only means that addresses, protocol and ports match a rule: what travels inside the packets is something the firewall does not look at. IDS and IPS do: they examine the content of the traffic to recognise known attacks and anomalous behaviour. Let us look at the difference between detecting and blocking, signatures and anomalies, false positives and false negatives, and how to use Suricata, the engine built into OPNsense, with care.

What a firewall sees, and what it does not

A firewall rule describes traffic with a few fields: interface, protocol, source and destination addresses and ports. This information sits in the IP, TCP and UDP headers; thanks to the state table, the firewall also knows whether a packet belongs to a connection that has already been allowed. It is a fast check that closes everything that is not needed.

The limit is just as clear. If TCP port 80 of the web server is open to the Internet, the firewall lets through any request to that port: the one from a visitor and the one crafted to exploit a vulnerability in the application. Telling them apart means reading the content: the payload and application protocols such as HTTP, DNS or TLS.

IDS and IPS: watching or acting

An IDS (Intrusion Detection System) analyses a copy of the traffic, received from a switch mirror port or, as in OPNsense, by reading the packets of an interface without holding them. When it recognises something suspicious it raises an alert, but the original packet goes on. An IDS does not slow the network down and, if it fails, traffic keeps flowing.

An IPS (Intrusion Prevention System), on the other hand, sits inline: every packet passes through it and waits for the verdict. If it matches a rule with a blocking action, the IPS discards it (drop). The price: more latency, more processing, and the risk that a mistake interrupts legitimate traffic.

Out-of-band IDS and inline IPS On the left, an IDS: traffic goes from the Internet to the firewall and then to the server; the IDS sensor receives a copy of the traffic, recognises the attack and writes an alert to the log, but the packet still reaches the server. On the right, an IPS: traffic passes through the IPS before reaching the server; a packet that matches a signature is dropped, clean traffic goes on. IDS: out of band, detects and alerts IPS: inline, detects and blocks Internet Firewall Server copy IDS sensor alert in the log the packetreaches the server Internet Firewall+ IPS Server signature matcheddrop: discarded no signaturegoes on every packet waits for the verdict more protection, more latency and CPU load Conceptual diagram: in OPNsense both modes run on the firewall itself
Figure 1 — The IDS works on a copy of the traffic and raises alerts; the IPS sits on the packet path and can drop the packets that match a signature.

Signatures, rules and anomalies

The most common method is signature-based detection: rules that describe a specific kind of traffic, such as a sequence of bytes in the content or an abnormal value in an HTTP field. In Suricata every rule has an action (alert raises an alert, drop discards the packet in IPS mode), a header with protocol, addresses, ports and direction, and the options in brackets, with message, conditions and identifier (sid). Here is a harmless local rule that flags external access to a website's administration area:

alert http $EXTERNAL_NET any -> $HOME_NET any (msg:"External access to the administration area"; flow:established,to_server; http.uri; content:"/admin"; nocase; sid:1000001; rev:1;)

$HOME_NET and $EXTERNAL_NET stand for the networks to protect and everything else; sid values from 1000000 to 1999999 are reserved for local rules. In practice, ready-made rulesets are used, maintained by communities and dedicated projects and updated often, because a signature only recognises what is already known.

Anomaly detection, instead, flags whatever deviates from normal: a protocol on an unusual port, an outsized volume of requests, a sequence that breaks the rules of the protocol. Suricata decodes application protocols and generates events for these violations too. Anomalies can reveal new attacks, but they produce more alerts to interpret.

False positives and false negatives

A false positive is an alert on legitimate traffic: an overly broad rule mistakes a software update for an attack. With an IDS the damage is a useless alert; with an IPS something stops working. A false negative is a real attack that raises no alert, because no signature describes it, because it is encrypted, or because the right interface is not being monitored.

Reducing one tends to increase the other: enabling every rule fills the log with false positives, disabling too many opens the door to false negatives. Tuning looks for the balance: rules relevant to the services in place, and fixes for the ones that get it wrong.

Firewall, IDS and IPS compared

FeatureFirewallIDSIPS
What it examinesHeaders: addresses, protocol, ports, stateHeaders and content, on a copyHeaders and content, on the real traffic
PositionInlineOut of bandInline
ResponsePass, Block or Reject according to the rulesAlert and loggingAlert and packet drop
Effect of a mistakeService unreachable or overexposedUseless or missed alertLegitimate traffic blocked or attack not stopped
System loadLowMedium, no added latencyMedium or high, with added latency
Typical useAlways, as the first line of defenceStart-up, observation, networks where availability is criticalAfter tuning, on exposed services

Suricata in OPNsense

OPNsense includes Suricata, an open-source detection and prevention engine from the Open Information Security Foundation. Its configuration is under Services › Intrusion Detection › Administration, split into tabs. In the general settings you enable the service, choose whether to turn on IPS mode and select the interfaces to analyse; the advanced options include the internal networks, which correspond to $HOME_NET.

In the download tab you choose, enable and download the relevant rulesets, and updates can be scheduled. Individual rules are browsed and enabled in another tab; policies change the action of many rules at once, by ruleset or by category: this is how, when the time is right, a group moves from alert to drop. Alerts have their own tab. Menu items can change between releases: the official documentation for the installed version is the reference.

IPS mode, netmap and network cards

In IDS mode Suricata reads packets without holding them. In IPS mode it must sit on the path of the traffic: OPNsense uses netmap, a FreeBSD framework through which a program receives packets directly from the network card, inspects them and decides whether to forward them.

Netmap works best with drivers that support it natively; with others it runs in emulation, which is slower and sometimes unstable, so check the network card's compatibility before enabling the IPS. The OPNsense documentation recommends disabling hardware offloading (checksum, segmentation and reassembly) under Interfaces › Settings; with VLANs, the IPS goes on the physical interface that carries them. A mistake can stop traffic on the interface: test in a maintenance window, with management access that does not depend on that interface.

Which interface to protect

Suricata analyses the traffic of the interface it runs on, in both directions. The instinctive choice is the WAN, but it has two drawbacks. On the WAN the engine sees everything that arrives, including attempts that the firewall rules would drop anyway, and wastes CPU. Moreover, incoming packets carry the public address as their destination, because NAT has not happened yet, and outgoing ones already carry it as their source: the alerts do not show which internal device is involved.

This is why the internal interface is often chosen, the LAN or the DMZ of published servers: only traffic already admitted by the rules reaches it, with the real addresses. The firewall does the first filtering, the IPS inspects what is left. The WAN is analysed when you also want to see the rejected attempts.

Path of a packet with the IPS on the internal interface A packet arrives from the Internet on the WAN interface. The firewall rules come first: if no rule allows it, it is blocked. If it passes, it is translated by NAT and routed towards the DMZ. On the DMZ interface the IPS inspects the content: if it matches a signature with the drop action it is discarded and logged; if it matches a signature with the alert action it is logged and goes on; otherwise it reaches the server. Packet from the Internet on the WAN 1. Firewall rules (WAN)addresses, ports, state no Block Pass 2. NAT and routing towards the DMZ 3. IPS inspection on the DMZ interfacecontent compared with the signatures drop signaturediscarded and logged alertpasses no signaturereaches the server Traffic already blocked by the rules never reaches inspection: less load, alerts with internal addresses
Figure 2 — With the IPS on the internal interface, the firewall rules decide first, then content inspection examines only the admitted traffic.

Performance and CPU

Comparing every packet with thousands of signatures is heavy work: the firewall alone handles the full bandwidth of the connection, but with the IPS enabled the limit is often the CPU. Suricata uses multiple threads, yet performance depends on processor, memory, number of rules and type of traffic. Before blocking, measure the load at peak times and the real speed with a transfer test. The most effective way to lighten the engine is to enable only the relevant rules.

Encrypted traffic: what remains visible

Most web traffic is encrypted with TLS. An IDS or IPS that does not decrypt does not see the content: neither the page requested nor the data sent. It does see the metadata: the requested server name (SNI), in clear text in the client's first message unless Encrypted Client Hello is used; handshake fingerprints such as JA3, which characterise the client; protocol version, duration and volume of the connections. The server certificate is visible with TLS 1.2, while with TLS 1.3 it travels encrypted.

This is enough to recognise connections to known malicious domains or suspicious clients, but not to find an attack inside an HTTPS request. Decrypting traffic in transit is possible but complex and sensitive for privacy. For published services, the IPS should be paired with up-to-date applications and checks on the server itself.

From alert-only to blocking: a method

Enabling the IPS straight away with every rule set to drop is the quickest way to bring your own network to a halt. It is better to proceed step by step:

  1. Alert only. Suricata without IPS mode, or with the rules set to alert, on the chosen interface and with a few rulesets.
  2. Observation. For a few days, read the alerts: which signatures fire, on which devices, how often.
  3. Tuning. Disable the rules for systems you do not have, fix the false positives, check the declared internal networks.
  4. Blocking. Turn on IPS mode and use policies to move the verified categories to drop.
  5. Maintenance. Check updates and alerts regularly; every new service may call for new tuning.

Logs and alerts

An IDS whose alerts nobody reads protects nobody. For each event OPNsense shows date, interface, addresses, ports, signature message and identifier, and the action applied; from there you can go back to the rule to disable it or change its action. Suricata also writes a detailed log in JSON. It is worth sending the events to a log collection server, so that they remain available even if the firewall is compromised, and notifying the most serious alerts at once.

Conclusions

The firewall decides on addresses, ports and state; IDS and IPS look inside the admitted traffic. The IDS analyses a copy and alerts, the IPS sits inline and blocks, at the cost of latency, CPU and the risk of stopping legitimate traffic. With Suricata in OPNsense you start in alert-only mode, choose interface and rules carefully, fix the false positives and only then block. In encrypted traffic only the metadata remains visible: inspection is an extra layer of defence, not a substitute for sound rules and up-to-date systems.

The video

IDS and IPS: Detecting and Blocking Suspicious Traffic with OPNsense — Animation without voice-over, with on-screen text in English and sound effects.

Technical sources

  • Open Information Security Foundation — Suricata User Guide (Rules, Setting up IPS/inline, TLS keywords) — Rule structure (action, header, options), the alert and drop actions, the HOME_NET and EXTERNAL_NET variables, the sid range for local rules, IDS and inline IPS modes with netmap, keywords for SNI and JA3 in TLS traffic.
  • Documentazione ufficiale di OPNsense — Intrusion Prevention System (Services › Intrusion Detection) — Enabling the service, IPS mode, interfaces, internal networks, downloading and updating rulesets, policies to change rule actions, alerts; disabling hardware offloading and placing the IPS on the physical interface with VLANs.
  • FreeBSD — pagina di manuale netmap(4) — Direct access by programs to the network card's packets, native support in some drivers and emulated mode for the others.
  • RFC 6066 — The Server Name Indication (SNI) extension: the requested server name travels in the client's first message.
  • RFC 8446 — TLS 1.3: after the initial negotiation the messages, including the server certificate, are encrypted.
  • RFC 1918 e RFC 5737 — Private addresses and addresses reserved for documentation used in the video examples (192.168.20.10, 203.0.113.25, 198.51.100.44).

Standards and official documentation available from the respective organisations.

OPNsense® is a registered trademark. Alba Technology does not represent the OPNsense project.