Lesson 21 intermediate

Network Security

The CIA triad and common attacks, authentication (passwords, MFA, keys, 802.1X, RADIUS), encryption (symmetric, asymmetric, hashing, PKI), stateful firewalls with nftables and cloud security groups, MAC filtering and why it is weak, IDS versus IPS, VPNs with WireGuard and IPsec, segmentation and zero trust.

Every lesson so far has been about getting packets through. Security is about making sure only the right packets get through, that nobody can read or change them on the way, and that you notice when someone tries. No single tool does it; you build layers, so a failure in one is caught by the next (defense in depth).

What we protect: the CIA triad

GoalMeaningBroken by
ConfidentialityOnly authorized parties can read dataSniffing, stolen credentials, leaks
IntegrityData is not changed undetectedTampering, man-in-the-middle
AvailabilityServices keep workingDDoS, ransomware, misconfiguration

Common network attacks

AttackHow it worksMain defenses
SniffingCapturing traffic on a shared or compromised segmentEncryption everywhere (TLS, SSH, VPN)
SpoofingFaking a source IP, MAC, ARP reply or email senderIngress filtering, DAI, SPF/DKIM/DMARC
Man-in-the-middleSitting between two parties, reading or changing trafficTLS with certificate validation, HSTS
DoS / DDoSFlooding a target until it cannot serveCDNs, scrubbing services, rate limits, SYN cookies
Port scanningMapping open services to find a way inClose unused ports, firewalls, IDS alerts
Brute forceGuessing passwords against SSH, VPN or web loginsMFA, keys, lockouts, fail2ban
PhishingTricking users into giving credentialsMFA (phishing-resistant keys), training, mail filtering
Lateral movementSpreading inside after one machine is compromisedSegmentation, least privilege, zero trust

Authentication

Proving identity: something you know (password), have (phone, hardware key) or are (fingerprint).

  • Multi-factor authentication (MFA) combines two or more. Passkeys and FIDO2 hardware keys are phishing-resistant, unlike SMS codes.
  • SSH keys instead of passwords for servers:
$ ssh-keygen -t ed25519 -C "jeff@laptop"
$ ssh-copy-id deploy@server.example.com
$ sudo grep -E '^(PasswordAuthentication|PermitRootLogin)' /etc/ssh/sshd_config
PasswordAuthentication no
PermitRootLogin no
  • 802.1X makes a switch port or Wi-Fi network ask for credentials or a certificate before granting network access, checked by a RADIUS server against the directory. This is “WPA2/WPA3-Enterprise” on Wi-Fi.
  • Kerberos, SAML and OpenID Connect provide single sign-on across services.

Encryption

KindKeysSpeedUsed for
Symmetric (AES, ChaCha20)One shared secret keyVery fastEncrypting the actual data
Asymmetric (RSA, ECDSA, Ed25519, X25519)Public and private key pairSlowKey exchange, signatures, certificates
Hashing (SHA-256, SHA-3)No keyFastFingerprints, integrity checks; password storage with slow hashes like Argon2

Real protocols combine them: TLS, SSH and VPNs use asymmetric crypto to authenticate and agree on a key, then symmetric crypto for the bulk data. PKI (public key infrastructure) is the system of certificate authorities that vouches for which public key belongs to which name.

$ sha256sum ubuntu-24.04-live-server-amd64.iso
$ openssl rand -hex 16
3f9a1c7be0d24f6a8e1b5c9d7a20f413

Checking a download’s SHA-256 against the published value proves it was not corrupted or swapped.

Firewalls

A firewall enforces which traffic may pass between zones of different trust.

  • Packet filter (stateless): matches each packet on addresses, protocol and ports. Fast but naive; you must allow return traffic explicitly.
  • Stateful firewall: tracks connections, so you write “allow outbound”, and replies are let in automatically. Today’s default.
  • Next-generation firewall (NGFW): adds application recognition, user identity, TLS inspection and built-in IPS.
  • Web application firewall (WAF): inspects HTTP for attacks such as SQL injection and XSS, in front of web apps.

The golden rule is default deny: block everything, then allow only what is needed. A minimal stateful host firewall with nftables:

table inet filter {
  chain input {
    type filter hook input priority 0; policy drop;
    ct state established,related accept
    ct state invalid drop
    iif "lo" accept
    meta l4proto { icmp, ipv6-icmp } accept
    tcp dport 22 ip saddr 203.0.113.0/24 accept
    tcp dport { 80, 443 } accept
  }
}
$ sudo nft -f /etc/nftables.conf
$ sudo nft list ruleset
$ sudo ufw status verbose        # Ubuntu's simpler front end
$ sudo firewall-cmd --list-all   # RHEL and Fedora

Note that ICMP is allowed (lessons 7 and 9 explain why) and SSH is limited to one admin network. In the cloud the same ideas appear as security groups (stateful, per instance) and network ACLs (stateless, per subnet).

Check what is actually exposed, from the outside, on systems you are allowed to test:

$ sudo nmap -sS -Pn -p 1-1024 server.example.com
PORT    STATE    SERVICE
22/tcp  filtered ssh
80/tcp  open     http
443/tcp open     https

filtered means the firewall silently dropped the probes (SSH is only open to the admin network); closed would mean the host answered with a reset.

MAC address filtering

Allowing only listed MAC addresses on a Wi-Fi network or switch port sounds secure but is weak: MAC addresses are sent in clear text and any device can copy one in seconds (ip link set dev wlan0 address …). Random MACs on phones also make lists hard to keep. Use it only as a small extra hurdle; real access control is 802.1X or WPA3 with strong credentials. On switches, port security (limit the number of MACs per port) does help against attached rogue switches.

IDS and IPS

IDS (intrusion detection)IPS (intrusion prevention)
PlacementWatches a copy of traffic (mirror port, TAP)Inline, traffic passes through it
ActionAlertsAlerts and blocks
RiskMissing an attackBlocking good traffic (false positive) or slowing the link

Detection methods: signature-based (known attack patterns, fast and precise, blind to new attacks) and anomaly-based (learns normal behavior, catches novel attacks, noisier). Open-source examples are Suricata and Snort (signatures, can run as IDS or IPS) and Zeek (detailed network logs for analysis). Host-based tools like Wazuh or OSSEC watch individual machines.

$ sudo tail -1 /var/log/suricata/fast.log
11/17/2026-09:14:22.481  [**] [1:2001219:20] ET SCAN Potential SSH Scan [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 198.51.100.77:51122 -> 192.168.1.10:22

VPNs

A VPN builds an encrypted tunnel across an untrusted network.

  • Site-to-site: connects two networks (an office and a cloud VPC), usually router to router.
  • Remote access: connects a user’s device to the company network.
TechnologyNotes
WireGuardModern, small, fast, UDP; keys like SSH. Built into Linux.
IPsec (IKEv2)The standard for site-to-site and cloud VPN gateways; ESP protocol 50 and UDP 500/4500
OpenVPN and TLS VPNsTLS-based, can run over TCP 443 to pass strict firewalls
PPTPBroken; do not use

A WireGuard peer in a few lines:

[Interface]
PrivateKey = <laptop-private-key>
Address = 10.8.0.2/24

[Peer]
PublicKey = <server-public-key>
Endpoint = vpn.example.com:51820
AllowedIPs = 10.20.0.0/16
PersistentKeepalive = 25
$ sudo wg-quick up wg0
$ sudo wg show wg0 latest-handshakes
Hs5vJ0Yq0bX2fP4cZ9mO1cR7tK3yW8nL6dE2aB4sG1Q=	1763372041

AllowedIPs doubles as the routing table: only traffic for 10.20.0.0/16 enters the tunnel (a split tunnel). Use 0.0.0.0/0, ::/0 to send everything through it (full tunnel).

Segmentation and zero trust

A flat network lets an attacker who compromises one laptop reach every server. Segmentation (VLANs, subnets and firewall rules between them; micro-segmentation with host or Kubernetes network policies) limits the blast radius.

Zero trust goes further: no device or user is trusted for being “inside”. Every request is authenticated, authorized and encrypted based on identity and device health, wherever it comes from. In practice: SSO with MFA in front of every app, identity-aware proxies instead of broad VPN access, mTLS between services and least-privilege rules everywhere.

Exercise

Why is a stateful firewall easier to configure correctly than a stateless packet filter?

  1. It does not need any rules
  2. It encrypts traffic automatically
  3. It blocks all ICMP by default
  4. It tracks connections and allows reply traffic automatically, so you only write rules for who may start a connection
Show answer

Answer: D. With ct state established,related accept, returning packets of allowed connections pass. A stateless filter needs extra rules for every reply direction.

Exercise

An office restricts Wi-Fi with a MAC address allow list. Why is that weak protection?

  1. MAC addresses are visible in the air and can be copied by any device
  2. MAC addresses change every hour on all devices
  3. Access points cannot read MAC addresses
  4. MAC filtering only works with IPv6
Show answer

Answer: A. An attacker sees allowed MACs in captured frames and sets the same address on their own card. Use WPA3 or 802.1X for real access control.

Exercise

What is the key difference between an IDS and an IPS?

  1. An IDS uses signatures and an IPS uses anomaly detection
  2. An IPS only protects hosts and an IDS only protects networks
  3. An IDS must be inline and an IPS uses a mirror port
  4. An IDS only alerts on a copy of traffic, while an IPS sits inline and can block it
Show answer

Answer: D. Both can use signatures or anomaly detection. Placement and action differ: detection only versus inline prevention.

Key takeaways

  • Security aims at confidentiality, integrity and availability, in layers.
  • Use MFA and keys; 802.1X with RADIUS controls who gets on the network.
  • Asymmetric crypto authenticates and exchanges keys; symmetric crypto encrypts the data.
  • Firewalls should be stateful and default-deny; never block all ICMP.
  • MAC filtering is weak; IDS alerts, IPS blocks; WireGuard and IPsec build VPNs; zero trust removes “trusted inside”.

FAQ

Is a VPN enough to secure remote work?

It encrypts the path, but once connected a user often reaches far more than needed. Combine it with MFA, device checks and segmentation, or move to identity-aware access per application (zero trust).

Do I need a firewall on a server behind a cloud security group?

It is good practice. Security groups protect the edge; a host firewall still protects the server if a group is misconfigured or an attacker gets onto a neighbor in the same subnet.

What is the difference between WPA2 and WPA3?

WPA3-Personal uses SAE instead of a pre-shared key handshake, so captured traffic cannot be used for offline password guessing, and it requires protected management frames. Use WPA3 (or WPA2/WPA3 mixed mode) wherever devices support it.

Is it legal to run nmap?

Scanning your own systems, or systems you have written permission to test, is normal practice. Scanning other people’s networks without permission may break laws and terms of service.

↑ ↓ navigate Enter open Esc close