Network Security
Network security is the practice of controlling what flows between systems, and of noticing when something flows that should not. Two facts shape everything in this lesson. First, most networks were designed for connectivity, not for containment, so they happily forward an attacker's traffic from the machine they broke into to the machine that matters. Second, encrypted traffic is now the norm, which shifts detection away from inspecting payloads and toward inspecting metadata â who talked to whom, how often, and how much data moved. The controls below address both facts.
What actually travels on your wire
Before choosing tools, be precise about the assets. Data in transit is exposed at several points: on the local segment where ARP spoofing and port mirroring work, in the data center fabric, at the edge router, and across every hop of a VPN or public link. Infrastructure itself is an asset â a compromised switch or router rewrites where traffic goes, which is why management planes deserve their own out-of-band network.
Threats split into three groups. Eavesdropping and man-in-the-middle attacks target confidentiality and integrity of the flow itself; denial-of-service attacks target availability by exhausting bandwidth, connection tables or application resources; and lateral movement abuses the fact that a network usually lets any internal host talk to any other. The third group causes most real-world breaches, and it is solved by architecture rather than by a product.
| Control | Layer | Catches | Blind spot |
|---|---|---|---|
| Packet-filter firewall | Network/transport | Ports, protocols, IPs | Payload content, connection context |
| Stateful firewall | Session | Unexpected return traffic | Application-layer abuse |
| NGFW | Application | Apps, users, TLS inspection | Encrypted malware inside allowed apps |
| IDS/IPS | Traffic stream | Known exploit patterns | Encrypted payloads, novel attacks |
| NDR / NetFlow | Metadata | Anomalous conversations | Content of allowed sessions |
Firewalls: the three generations
A packet-filtering firewall reads headers and applies rules â source, destination, port, protocol. It is fast and stateless: it does not remember that a packet is part of an established conversation, so rules must be written symmetrically for both directions, and mistakes are easy to make. Stateful inspection tracks the connection table, allows replies only to connections the internal host initiated, and removes most of that foot-gun.
Next-generation firewalls add application awareness, user identity from directory services, sandboxing of suspicious files, and TLS inspection so that "port 443 open" is no longer a synonym for "safe". Deep packet inspection is only possible when you terminate or inspect TLS; if you do not have the private key or the endpoint agent, the firewall sees an encrypted stream and can only guess.
# nftables: default-deny inbound, allow established flows, expose only the web tier
nft add table inet firewall
nft add chain inet firewall input { type filter hook input priority 0 \; policy drop \; }
nft add rule inet firewall input ct state established,related accept
nft add rule inet firewall input ct state invalid drop
nft add rule inet firewall input iif lo accept
nft add rule inet firewall input ip saddr 10.0.0.0/24 tcp dport 22 accept comment "mgmt subnet only"
nft add chain inet firewall forward { type filter hook forward priority 0 \; policy drop \; }
nft add rule inet firewall forward ip saddr 10.0.10.0/24 ip daddr 10.0.20.10 tcp dport 443 accept
nft list ruleset
Read that as policy, not syntax. The order of the rules is the security decision: everything is refused unless a rule names it, replies ride on connection state instead of a mirror rule, and SSH is reachable from one management subnet rather than from anywhere.
Segmentation: containing the compromise you have not had yet
Segmentation is the single highest-leverage network control, because it converts "an attacker is inside" from a catastrophe into an incident. The classic pattern puts public services in a DMZ, terminates inbound connections on an outer firewall, and allows a narrow, inspected path from the DMZ into the internal tiers â web tier to application tier to database, one hop at a time.
Flat networks defeat all of this. When every workstation can reach every server on every port, a single phishing payload can scan and pivot freely. Microsegmentation takes the idea further: policy is enforced per workload or per identity rather than per subnet, so two virtual machines on the same host can be isolated from each other. In cloud environments this is expressed as security groups and network policies; on premises it needs VLANs plus a firewall that can enforce policy by identity rather than by address.
Three practical rules keep segmentation real. Write the allowed flows down as a matrix before touching equipment â most organizations discover they cannot name their own traffic patterns. Test the negative case, not the positive one: verify that the database port is unreachable from the user VLAN, because a rule that "should" block still gets forgotten. And review the matrix when applications change, since new integrations are exactly the traffic nobody documented.
IDS and IPS: signatures, anomalies and their limits
An intrusion detection system watches a copy of the traffic and alerts; an intrusion prevention system sits inline and can drop what it matches. Both rely primarily on signatures â byte patterns with context that describe a known exploit. Signatures are precise and cheap, which is why they still catch commodity attacks years after publication, and they are brittle: a trivial change to an exploit, or simply a different encoding, defeats a pattern written against one variant.
# Snort/Suricata rule: outbound SQL-injection probing against the web tier
alert http $EXTERNAL_NET any -> $HOME_NET $HTTP_PORTS (
msg:"SQL injection attempt in URI";
flow:established,to_server;
http.uri; content:"%27"; nocase;
http.uri; content:"union"; nocase;
http.uri; content:"select"; nocase;
classtype:web-application-attack;
sid:1000001; rev:3;
)
Note what makes the rule work: flow:established,to_server keeps it off replies, the three content matches in the URI keep false positives down compared with matching select alone, and the rev field lets you manage the rule's history. Signature tuning is where most IDS deployments succeed or fail â an untuned IDS produces thousands of alerts a day and gets muted within a month.
Behavioral detection covers what signatures miss: a workstation that suddenly transfers gigabytes at 3am, one host contacting an IP range it has never touched, DNS queries with suspicious entropy. These detections are weaker individually but catch novelty. Mature networks run both, plus flow telemetry, because metadata survives encryption.
Remote access and virtual private networks
A VPN extends a network across an untrusted link by building an encrypted tunnel, then deciding what the tunnel may carry. Site-to-site IPsec tunnels connect offices; SSL/TLS or WireGuard tunnels serve remote employees. The security questions are the same for all of them: what authenticates the peer, what cipher suite is negotiated, and â the question people skip â what the user can reach once the tunnel is up.
| Type | Common protocol | Strength | Typical risk |
|---|---|---|---|
| Site-to-site | IPsec (IKEv2) | Stable, hardware-offloaded | Misconfigured crypto domains |
| Remote access | TLS-based (OpenVPN, vendor clients) | Works behind NAT, easy rollout | Client device is untrusted |
| WireGuard | UDP, modern ciphers | Small attack surface, fast | Key distribution is manual |
| Zero-trust access | mTLS per application | No broad network exposure | Requires app-level proxying |
Split tunneling deserves explicit review: a client that routes only your corporate prefixes through the tunnel keeps internet traffic on the local network, which improves performance but means corporate devices are simultaneously on two networks with different protections. Whether that is acceptable depends on whether you treat the endpoint or the network as the security boundary.
Watching the traffic you allowed
Allowing a flow is not the end of the job. NetFlow, sFlow and packet metadata give you conversation records â endpoints, ports, byte counts, timing â that remain visible even inside TLS. DNS logs are similarly valuable, because every request names its destination before the connection starts.
# Capture a targeted slice without drowning in packets
sudo tcpdump -i eth0 -nn 'host 10.0.20.10 and not port 22' -w /var/tmp/incident-204.pcap
# Quick reconnaissance view: who is talking to the database tier?
sudo tcpdump -i eth0 -nn -c 2000 'tcp dst port 3306' | awk '{print $3}' | cut -d. -f1-4 | sort | uniq -c | sort -rn
# Flow-level summary when full capture is too heavy
sudo nfdump -R /var/log/nfdump -q dst ip 10.0.20.10 | head -20
Rotate captures, cap their size, and treat the storage itself as sensitive: packet captures contain credentials in cleartext protocols and the full shape of your internal traffic.
Common Mistakes
Shipping an IDS with default rules and never tuning it
Fix: Baseline alert volume for a week, then silence known-benign scanners and tune content matches until daily alerts are reviewable.
Writing firewall rules that allow a whole subnet 'temporarily'
Fix: Name the specific host and port, put an expiry date in the rule comment, and review rule comments monthly.
Segmenting the network but leaving the management plane on the production VLAN
Fix: Give management interfaces an isolated path with jump hosts, because compromising a switch console defeats segmentation.
Assuming encrypted traffic needs no inspection
Fix: Inspect metadata â endpoints, volumes, timing, DNS â and decrypt only where you have clear legal authority and key access.
Treating the VPN as a trust boundary without checking what it exposes
Fix: Apply least privilege to tunnel routes and prefer per-application access over full-network reachability.
Best Practices
- Document the allowed-flow matrix first, then encode it as rules; infrastructure should express policy, not invent it.
- Default-deny inbound, allow established replies, and permit outbound by exception for anything that is not a server.
- Keep an out-of-band management network so a compromised data plane cannot reach switch and firewall consoles.
- Collect NetFlow and DNS logs even when you cannot capture full packets â encryption does not hide conversation shape.
- Re-test segmentation quarterly with the same negative checks you ran at rollout.
Key Takeaways
- Firewalls evolved from header filtering to stateful sessions to application awareness; each generation closes a blind spot the previous one had.
- Segmentation is the highest-leverage network control because it bounds the blast radius of a compromise you have not yet detected.
- Signatures catch known attacks precisely but break on trivial mutations, so pair them with behavioral and metadata detection.
- VPNs encrypt the link; they do not decide what the peer may reach once connected â authorization is a separate design decision.
- Packet captures and flow records are sensitive evidence; store them with the same care as the systems they watch.