Network Defense Basics
Defense in depth for the modern network: stateful vs. next-gen firewalls, IDS vs. IPS, and why Zero Trust replaced the castle-and-moat model.
1. Executive Summary & Objective
No single control stops every attack, so defenders layer them — defense in depth. If one control fails, another is waiting behind it. This lesson covers the three workhorses of network defense and the modern model (Zero Trust) that ties them together.
Objective: Distinguish stateful vs. next-gen firewalls, IDS vs. IPS, and explain why Zero Trust replaced castle-and-moat.
2. Core Concept & Theory (The “Why”)
Firewalls
- Stateful (L4): tracks connection state; filters on IP/port.
- Next-Generation (L7): inspects inside packets — identifies the application and content, blocking e.g. an executable download over HTTP.
IDS vs. IPS
- IDS (detection): passive; matches signatures and alerts a SOC analyst.
- IPS (prevention): inline; drops malicious packets and terminates the connection.
A blocked malicious packet at the IPS looks like this:
3. The Zero Trust Model
The old castle-and-moat model trusted anything inside the perimeter. Phishing one internal laptop gave attackers trusted internal access and free lateral movement.
Zero Trust = “Never trust, always verify”:
- Every request — even from an internal laptop in HQ — is authenticated and authorized.
- The network is micro-segmented: HR’s VLAN can’t reach the IT server VLAN unless explicitly permitted, so a breach is contained.
An attacker phishes a finance laptop and tries to reach the domain controller. How does Zero Trust limit the damage that castle-and-moat would not?
Under Zero Trust the laptop’s internal location grants no implicit trust: the connection to the domain controller must still authenticate and be authorized, and micro-segmentation likely blocks that path entirely — containing the breach instead of allowing free lateral movement.
4. Firewalls in Practice
| Type | What it inspects | Notes |
|---|---|---|
| Packet filter (stateless) | Each packet’s addresses, ports and protocol, with no memory | Fast and simple; cannot tell a reply from a new connection |
| Stateful firewall | Tracks connection state, so replies to allowed outbound connections are allowed automatically | The baseline for almost every network |
| Next-generation firewall (NGFW) | Adds application awareness, user identity, intrusion prevention, URL filtering, TLS inspection and threat intelligence | Controls by application (allow “Teams”, block “BitTorrent”) rather than only by port |
| Web application firewall (WAF) | HTTP and HTTPS requests to a web app | Blocks injection and similar attacks; a layer, not a cure |
| Host firewall | Traffic to and from one device | Protects even when the device is on an untrusted network |
| Cloud firewalls / security groups | Instance and subnet rules in the cloud | See the Cloud course |
Good rule hygiene
- Default deny: block everything, then allow what is needed (inbound and, where possible, outbound).
- Be specific: exact sources, destinations and ports; avoid
any. - Order matters: rules are evaluated top to bottom, first match wins. Put specific rules before general ones.
- Document each rule with an owner, a purpose and an expiry or review date.
- Review regularly: remove unused, overlapping and temporary rules (rule bloat is a major source of exposure).
- Control outbound traffic too, to limit malware command-and-control and data exfiltration.
- Change control and logging: every change reviewed and recorded; log denied and sensitive allowed traffic to the SIEM.
- Manage the firewalls themselves: patch them, restrict and MFA-protect administration, back up configurations.
5. Segmentation, DMZs and Zones
A flat network where every device can reach every other lets an attacker who compromises one laptop roam freely. Network segmentation divides the network into zones with controlled paths between them.
Internet --[Firewall]-- DMZ (public web, mail relay) --[Firewall]-- Internal LAN (staff)
|
Server zone (databases) Management zone Guest Wi-Fi (isolated)
- A DMZ (demilitarised zone) holds services that must be reachable from the internet (web servers, mail gateways). If one is compromised, the attacker is still outside the internal network.
- Separate zones for staff, servers, databases, management interfaces, guests, IoT and voice, with firewall rules between them that allow only the traffic each needs.
- VLANs and subnets provide the separation, and a firewall or layer 3 policy enforces it (VLANs alone are not a security boundary without filtering).
- Microsegmentation applies fine-grained rules between individual workloads, often by software policy in data centres and clouds.
- Benefits: limits lateral movement, reduces blast radius, simplifies compliance (isolating card data), and makes monitoring easier because expected flows are known.
6. IDS, IPS and Network Detection
Intrusion detection and prevention systems watch for attacks:
| IDS | IPS | |
|---|---|---|
| Action | Detects and alerts | Detects and blocks (sits inline) |
| Risk | Misses nothing it is not looking at, but needs people to respond | A false positive can block legitimate traffic |
- Signature-based detection matches known attack patterns (fast and precise for known threats, blind to new ones).
- Anomaly / behaviour-based detection flags deviations from a learned baseline (can find new attacks, but produces false positives).
- Network-based (NIDS/NIPS) sensors watch traffic at key points (internet edge, between zones); host-based (HIDS) agents watch a single machine’s logs, files and processes.
- Placement: at the internet edge, between zones, in front of critical servers, and monitoring east-west traffic inside the data centre. Encrypted traffic is invisible without TLS inspection or endpoint visibility.
- Network detection and response (NDR) tools analyse metadata (flows, DNS, certificates) with machine learning to spot beaconing and lateral movement.
- Tune, or alerts become noise: disable irrelevant signatures, add context, and start in detection mode before blocking.
- Common open-source tools: Snort, Suricata (IDS/IPS) and Zeek (network analysis).
7. VPNs and Secure Remote Access
A VPN (virtual private network) creates an encrypted tunnel across an untrusted network.
| Type | Use |
|---|---|
| Site-to-site | Connects two networks (head office and branch, or office and cloud) permanently, usually with IPsec |
| Remote-access | A user’s device connects to the corporate network (IPsec/IKEv2, SSL/TLS VPN, WireGuard) |
Good practice: MFA on every VPN login; keep VPN appliances patched (they are a favourite internet-facing target); limit what a VPN user can reach with firewall rules (least privilege, not “the whole network”); consider split tunnelling carefully (it saves bandwidth but lets traffic bypass corporate controls); log connections; and prefer zero trust network access (ZTNA), which grants access to specific applications after verifying the user and device, instead of broad network access.
Remote administration needs extra care: expose RDP and SSH only through a VPN or a gateway/bastion with MFA, never directly to the internet (a leading ransomware entry point).
8. DNS, Web and Email Filtering
- DNS filtering / protective DNS blocks lookups of known malicious and newly registered domains, stopping many phishing and malware callbacks cheaply. Log all DNS queries: they reveal infected hosts.
- Web proxies and secure web gateways enforce acceptable use, block malicious sites and scan downloads, and can inspect HTTPS where policy and law allow.
- Email security gateways filter spam, phishing and malware, with SPF, DKIM and DMARC to authenticate mail (see the social engineering lesson).
- Egress filtering: restrict outbound connections to what is needed, so compromised hosts cannot freely call home.
9. Network Access Control and Monitoring
- NAC (network access control) decides which devices may connect, using 802.1X and device posture (patched, encrypted, managed). Unknown devices are denied or placed in a quarantine VLAN. This is covered in the Layer 2 security lessons.
- Flow and traffic monitoring (NetFlow/IPFIX, packet capture at key points) supports detection and investigation.
- Asset discovery: keep an inventory of what is on the network; unknown devices are findings.
- Time-bound and logged administrative access to network gear (TACACS+/RADIUS, MFA, config backups).
10. Putting Layers Together
A reasonable baseline for a small organisation: a stateful NGFW at the edge with default deny and egress control; segmented zones (staff, servers, guest, IoT); MFA-protected VPN or ZTNA; protective DNS and email filtering; EDR on endpoints; central logging and alerts; patching; and tested backups. None of these is perfect alone, which is exactly why defence in depth works.
11. Key Takeaways
- Defense in depth layers controls so one failure isn’t fatal.
- Stateful firewalls filter IP/port+state; NGFWs add L7 application/content control.
- IDS alerts; IPS blocks (inline).
- Zero Trust removes implicit internal trust and uses micro-segmentation to contain breaches.
Hands-on practice
Write the functions marked TODO. The checks read the variables your program leaves behind, so keep the lines at the bottom as they are, run it, then press Check my work.
🧪 Want to practise this on your own computer? See how to set up your lab →