16: Firewalls and Intrusion Detection Systems
Course: Networking - Security Advanced · Updated: October 2026 Literature: K&R chapter 8: operational security: firewalls and intrusion detection systems; NF chapter 7 (Network Intrusion Detection and Analysis) Related labs: Lab: Introduction Snort, Lab: Snort
Learning objectives
After studying this article you can:
- explain what a firewall does, and the differences between stateless packet filters, stateful filters and application gateways / next-generation firewalls
- read and write firewall rules (ACLs,
nftables) - explain what an IDS and an IPS are, and the difference between NIDS and HIDS
- explain the detection methods: signature-based, protocol/anomaly-based and behavioural
- write simple Snort/Suricata rules, and explain the role of Zeek
- know the difference between commercial and "roll-your-own" IDS solutions, and name examples
1. Firewalls
A firewall isolates an organisation's internal network from the Internet. It lets some packets through and blocks others.
Its three goals:
- All traffic from outside to inside, and the other way round, passes through the firewall.
- Only authorised traffic, as defined by the local security policy, is allowed.
- The firewall itself must be immune to attacks.
1.1 Stateless packet filters
These decide per packet, based on header fields:
- source/destination IP address
- TCP/UDP source/destination port
- ICMP message type
- TCP flags (SYN, ACK, ...)
Example access control list (ACL):
| Action | Source address | Dest. address | Protocol | Source port | Dest. port | Flag bit |
|---|---|---|---|---|---|---|
| allow | 222.22/16 | outside 222.22/16 | TCP | > 1023 | 443 | any |
| allow | outside 222.22/16 | 222.22/16 | TCP | 443 | > 1023 | ACK |
| allow | 222.22/16 | outside 222.22/16 | UDP | > 1023 | 53 | — |
| allow | outside 222.22/16 | 222.22/16 | UDP | 53 | > 1023 | — |
| deny | all | all | all | all | all | all |
Rules are checked from top to bottom, and the first match wins. The last rule is default deny.
Problem: a stateless filter doesn't remember anything. It will accept a packet with the ACK flag set that doesn't belong to any connection (used in ACK scans).
1.2 Stateful packet filters
A stateful filter tracks every TCP connection (SYN, established, FIN) and every UDP "flow":
- It only allows packets that belong to a known, established connection.
- Connections are removed after FIN or after a timeout.
- Rules become much simpler: "allow outgoing HTTPS connections, and allow replies to them automatically".
Example with nftables (Linux, the successor to iptables):
1 2 3 4 5 6 7 8 9 10 11 | |
1.3 Application gateways and next-generation firewalls
- An application gateway (proxy) filters at the application layer. For example, a web proxy that allows only certain users and websites, or an e-mail gateway that scans for malware. All traffic goes through the proxy, which opens its own connection to the server.
- Next-Generation Firewalls (NGFW) (Palo Alto, Fortinet, Check Point, Cisco) combine a stateful firewall with:
- application identification (deep packet inspection: "this is Teams", "this is BitTorrent", regardless of the port)
- user identification (integration with Active Directory)
- an integrated IPS, URL filtering, malware sandboxing
- TLS inspection (see article 13)
- Web Application Firewalls (WAF) protect web applications against SQL injection, XSS and so on (e.g. ModSecurity/Coraza, Cloudflare WAF).
- Cloud firewalls: security groups, network ACLs, Azure Firewall, and Firewall-as-a-Service in SASE (see article 14).
- Host firewalls: Windows Defender Firewall,
nftables/ufw, macOS. They are important for Zero Trust and micro-segmentation.
1.4 Limitations of firewalls
- IP spoofing: a firewall can't tell whether a source address is real.
- Firewalls don't see inside encrypted traffic unless they do TLS inspection.
- Insider threats and traffic that never passes the firewall (e.g. between two hosts in the same VLAN, or over a 4G/5G hotspot) are invisible to it.
- Tunnelling: attackers hide traffic in allowed protocols (DNS, HTTPS).
- A firewall is only as good as its rules. Rule sprawl and "temporary" exceptions build up over time.
1.5 The DMZ
1 | |
Servers that must be reachable from the Internet sit in a separate zone. If one is compromised, the internal network is still protected.
2. Intrusion Detection and Prevention Systems
Firewalls mainly look at headers. An IDS goes further, with deep packet inspection (looking at the content) and correlation across multiple packets, to detect attacks such as:
- port scans and network mapping
- exploits for known vulnerabilities, worms and malware traffic
- DoS attacks (e.g. floods)
- policy violations (e.g. Telnet in use, or an unknown TLS certificate)
| IDS (Intrusion Detection System) | IPS (Intrusion Prevention System) | |
|---|---|---|
| Placement | Passive, receives a copy of the traffic (SPAN/mirror port or a network TAP) | Inline: all traffic passes through it |
| Action | Alert (log, send to SIEM) | Block malicious traffic in real time |
| Risk | Doesn't stop an attack itself | False positives block legitimate traffic, and it can become a bottleneck |
| NIDS (Network-based) | HIDS (Host-based) | |
|---|---|---|
| Monitors | Network traffic on a segment | Activity on a single host: logs, file integrity, processes |
| Examples | Snort, Suricata, Zeek | Wazuh, OSSEC, and EDR (Microsoft Defender for Endpoint, CrowdStrike, SentinelOne) |
2.1 Detection methods
| Method | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Signature-based | Compares traffic with a database of known attack patterns (signatures/rules) | Accurate for known attacks, few false positives, easy to understand | Doesn't detect new (zero-day) attacks. Signatures must be kept up to date. Evasion is possible by changing the attack slightly. |
| Protocol analysis / protocol awareness | Reassembles streams and checks whether protocols follow the standard ("normal traffic") | Detects abnormal protocol use and evasion through fragmentation | More complex |
| Anomaly-based / behavioural | Builds a baseline of normal traffic and alerts on deviations (e.g. sudden large uploads at night, or new connections to a country) | Can detect unknown attacks | Many false positives, and the baseline needs time to learn |
Modern systems combine all three, increasingly with machine learning (NDR: Network Detection and Response, e.g. Vectra, Darktrace, ExtraHop, Corelight) and threat intelligence (lists of known malicious IPs, domains and TLS fingerprints).
3. Snort, Suricata and Zeek
3.1 Snort
- An open-source NIDS/IPS, created in 1998 by Martin Roesch, now owned by Cisco (Talos).
- Snort 3 (generally available since 2021) is the current version. It is a complete rewrite with multithreading, configuration in Lua (
snort.luain place ofsnort.conf), and better performance. The 2017 lab used Snort 2, which is now legacy. - Rules: the community ruleset (free), and the Talos subscriber ruleset (free with a 30-day delay for registered users, or paid for immediate updates).
3.2 Snort rule syntax
1 | |
Examples (Snort 3 syntax; the ICMP, ping-flood and SYN-scan rules also work in Snort 2 and Suricata):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
| Part | Meaning |
|---|---|
alert / log / pass / drop / reject |
Action (drop/reject only in inline IPS mode) |
msg |
Text in the alert |
content |
Byte pattern to search for in the payload |
flags, itype, flow |
Header conditions |
detection_filter / threshold |
Rate-based detection |
sid |
Unique rule ID (≥ 1,000,000 for your own local rules) |
rev |
Revision number |
classtype |
Category (used for priority) |
Running Snort 3:
1 2 | |
3.3 Suricata
- An open-source IDS/IPS from the Open Information Security Foundation (OISF), first released in 2010.
- Multithreaded from the start, with strong performance.
- Largely compatible with Snort rules, and it also has its own keywords.
- Produces rich EVE JSON logs: alerts, plus metadata about HTTP, DNS, TLS (including JA3/JA4 fingerprints), file extraction and flows. Ideal for a SIEM.
- Popular rulesets: Emerging Threats Open (free) and ET Pro (Proofpoint).
- Current version: Suricata 8 (2025). Parts of it are written in Rust for memory safety.
3.4 Zeek (formerly Bro)
- It is not a signature IDS but a network security monitor. It turns traffic into detailed logs per protocol:
conn.log,dns.log,http.log,ssl.log,files.log,x509.log, ... - It has its own scripting language, for detection logic and policies.
- It is indispensable for threat hunting and network forensics (see article 17).
- It is often used together with Suricata, e.g. in Security Onion or Corelight.
3.5 Commercial vs roll-your-own
As the NF book puts it, there are commercial products and "roll-your-own" solutions:
| Commercial | Open source / roll-your-own |
|---|---|
| Cisco Secure Firewall (Firepower, built on Snort), Palo Alto Networks, Fortinet FortiGate IPS, Trellix (formerly McAfee/FireEye), Check Point | Snort, Suricata, Zeek |
| NDR: Vectra AI, Darktrace, ExtraHop, Corelight (commercial Zeek) | Distributions: Security Onion, SELKS (Stamus), pfSense/OPNsense with Suricata/Snort plug-ins |
4. Summary
- Firewalls enforce a policy: stateless (per packet), stateful (per connection), or NGFW/application gateways (per application and user). Always end with default deny.
- An IDS detects and alerts, and an IPS blocks inline. A NIDS looks at the network, a HIDS/EDR looks at the host.
- Detection is signature-based (known attacks), protocol-based or anomaly/behaviour-based (unknown attacks, more false positives).
- Snort 3 and Suricata use rules. Zeek produces rich logs for analysis. Together they are the basis of many security operations centres (SOCs).
References
Videos
- Jim Kurose: Operational security: firewalls and IDS (chapter 8 video lectures): https://gaia.cs.umass.edu/kurose_ross/lectures.php
- Cisco Talos: Snort 3 tutorials and webinars: https://www.snort.org/resources
- Security Onion Solutions: video tutorials (YouTube search; tutorials on Suricata, Zeek, threat hunting): https://www.youtube.com/results?search_query=Security+Onion+Solutions
- Zeek: YouTube channel (ZeekWeek talks, tutorials): https://www.youtube.com/@zeekurity
- Professor Messer: Firewalls, IDS/IPS (Security+): https://www.professormesser.com/
Articles
- Snort 3 documentation and rule-writing guide: https://docs.snort.org/
- Suricata documentation: https://docs.suricata.io/
- Zeek documentation: https://docs.zeek.org/
- nftables wiki: https://wiki.nftables.org/
- Cheswick, Bellovin & Rubin, Firewalls and Internet Security (a classic)
- Chris Sanders & Jason Smith, Applied Network Security Monitoring (Syngress, 2013)
- Richard Bejtlich, The Practice of Network Security Monitoring (No Starch Press, 2013)
Standards and guidelines
- NIST SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy
- NIST SP 800-94: Guide to Intrusion Detection and Prevention Systems (IDPS)
Tools
- Snort 3: https://www.snort.org/ · Suricata: https://suricata.io/ · Zeek: https://zeek.org/
- Security Onion (free, complete NSM distribution): https://securityonion.net/
- OPNsense / pfSense (open-source firewall with IDS plug-ins): https://opnsense.org/
- Emerging Threats Open ruleset: https://rules.emergingthreats.net/
- hping3, nmap (to generate test traffic in your own lab)
Cyber Security
Why it matters
Firewalls and IDS are core components of defence in depth:
- Prevention (firewall): reduce the attack surface. Most automated Internet attacks hit only exposed services.
- Detection (IDS/NDR/EDR): no prevention is perfect. The dwell time (how long an attacker goes unnoticed) decides how much damage is done. With good detection, attacks are stopped before data is stolen or ransomware is deployed.
- Evidence: IDS alerts and NSM logs are often the first and most important source in an investigation (see article 17).
They also have weak points:
- Misconfigured firewalls (rules that allow too much, such as "any any", forgotten test rules, management interfaces exposed to the Internet) are among the most common audit findings.
- The firewall itself is a target: edge devices from Fortinet, Palo Alto (CVE-2024-3400), Cisco ASA (ArcaneDoor, 2024) and SonicWall have been attacked by state actors and ransomware groups (see article 14).
- Alert fatigue: an IDS that produces thousands of alerts a day gets ignored. The Target breach (2013) was actually detected, but the alerts weren't acted on.
- Evasion: attackers use encryption, fragmentation, slow scans, or "living off the land" (legitimate tools and cloud services) to stay under the radar.
- Encrypted traffic limits what signature-based IDS can see. Metadata (JA4 fingerprints, certificate data, flow behaviour) is becoming more important.
How to make it safe
- Default deny inbound and outbound (egress filtering). Allow only what you need. Blocking outbound traffic stops much malware C2 and data exfiltration.
- Review rules regularly: remove unused rules, document the owner and reason for every rule, and use change management. Tools such as
nmapand firewall analysers help check the actual exposure. - Keep firewall and IDS firmware and rules up to date: automatic rule updates (Talos, ET), and fast patching of the devices themselves.
- Never expose management interfaces to the Internet, and use MFA for administrators.
- Place sensors carefully: at the Internet edge, and internally between segments (east-west traffic), and in the cloud (VPC traffic mirroring).
- Tune the IDS for your environment: disable irrelevant rules, set
HOME_NETandEXTERNAL_NETcorrectly, and use thresholds to reduce noise. Each alert should lead to an action. - Send alerts and logs to a SIEM, correlate them with other sources (EDR, authentication logs), and use playbooks for response (SOAR).
- Combine network detection (Suricata/Zeek/NDR) with endpoint detection (EDR). Each sees what the other misses.
- Test your detection: run attacks in a lab (or a purple-team exercise) and check that they are detected, e.g. with Atomic Red Team or by replaying PCAPs from malware-traffic-analysis.net.
- Use IPS mode carefully: start in detection mode, check for false positives, and only then block.
Extra references
- CIS Critical Security Controls v8.1, Control 12 (Network Infrastructure Management) and Control 13 (Network Monitoring and Defense): https://www.cisecurity.org/controls
- MITRE ATT&CK, Defense Evasion (TA0005) and Command and Control (TA0011): https://attack.mitre.org/
- Atomic Red Team (tests to check detections): https://github.com/redcanaryco/atomic-red-team
- Malware-Traffic-Analysis.net (PCAPs and exercises for training your IDS skills): https://www.malware-traffic-analysis.net/
- Bloomberg Businessweek, Missed Alarms and 40 Million Stolen Credit Card Numbers: How Target Blew It (2014)
- NCSC-NL, Factsheet: Bescherm uw edge devices: https://www.ncsc.nl/