beginner

Network Security Basics: Firewalls, ACLs and VPNs

The essential controls that protect a network: the CIA triad and defence in depth, stateless ACLs versus stateful firewalls, rule order and default deny, DMZs and zones, NAT and port forwarding, VPN types and how they work, and hardening of devices. Then evaluate an access control list with real subnet matching and find shadowed rules.

55 min

1. Security goals and principles

Network security protects three properties, the CIA triad:

  • Confidentiality: only authorised parties can read the data (encryption, access control).
  • Integrity: data is not altered without detection (hashes, signatures, change control).
  • Availability: services work when needed (redundancy, DDoS protection, patching).

Core principles:

  • Defence in depth: layer controls (perimeter firewall, internal segmentation, host firewalls, authentication, monitoring) so a single failure is not fatal.
  • Least privilege: grant only the access required.
  • Default deny: block everything, then permit what is needed.
  • Segmentation: split the network into zones so compromise cannot spread.
  • Secure by default and keep it patched.
  • Assume breach: log, monitor and have a response plan.

2. Access control lists (ACLs)

An ACL is an ordered list of permit or deny rules matching packet fields: source and destination IP, protocol (TCP, UDP, ICMP) and ports. Routers and layer 3 switches use ACLs to filter traffic at line rate.

  • Rules are checked top to bottom; the first match wins.
  • An implicit deny all sits at the end of most ACLs, so anything not permitted is dropped.
  • Standard ACLs (Cisco) match only source addresses; extended ACLs match source, destination, protocol and port.
  • Apply an ACL to an interface and a direction: inbound (as packets arrive) or outbound. Place extended ACLs close to the source and standard ACLs close to the destination.
  • Cisco uses wildcard masks (the inverse of subnet masks: 0.0.0.255 for a /24). Modern platforms often accept CIDR.
ip access-list extended TO-SERVERS
 permit tcp 10.1.0.0 0.0.255.255 host 10.9.9.10 eq 443
 deny   ip  any 10.9.9.0 0.0.0.255
 permit tcp any any eq 80
!
interface Vlan10
 ip access-group TO-SERVERS in

ACLs are stateless. They look at each packet alone, so you must allow the return traffic yourself (for example permit tcp any eq 443 any established) and they cannot track protocols that open extra ports.

Shadowed and redundant rules

A rule is shadowed if an earlier rule already matches everything it would match, so it never takes effect. In the example above the rule that would deny 10.1.5.0/24 to the server can never fire if an earlier permit covers all of 10.1.0.0/16. Audit ACLs for shadowed rules, overly broad “permit any” entries, unused rules (check hit counts) and missing logging.

3. Firewalls

A firewall enforces a policy between networks of different trust. Types:

Type Looks at Notes
Packet filter Headers only, stateless Fast, simple (ACLs)
Stateful firewall Connection state: allowed outbound sessions’ replies return automatically Standard for perimeters
Application proxy Full application protocol on behalf of clients Deep inspection, slower
Next-generation firewall (NGFW) Applications, users, content, IPS signatures, TLS inspection, threat feeds Policies by app and identity, not just ports
Web application firewall (WAF) HTTP traffic to web apps Blocks SQL injection, XSS, bots
Host-based firewall Traffic on one computer Last line of defence, stops lateral movement

Zones and the DMZ

Firewalls divide the network into zones with different trust levels:

  • Inside / LAN (high trust)
  • DMZ (demilitarised zone): public-facing servers (web, mail relay, VPN gateway) that must be reachable from the internet but must not be trusted. The internet may reach the DMZ on specific ports; the DMZ may reach only the few internal systems it needs; the inside may reach the DMZ and internet; nothing from the DMZ may freely enter the inside.
  • Outside / internet (untrusted)
  • Further zones: guest, servers, management, IoT.

Policy matrix thinking (“zone A to zone B, which services?”) makes rule sets clear and auditable.

NAT and port forwarding

NAT hides private addresses behind a public one (see the routing lesson). It is not a security control on its own, but it blocks unsolicited inbound connections by default. Port forwarding / destination NAT exposes an internal service (a web server on TCP 443) through the public address; only forward what you must, to hardened hosts, preferably in a DMZ.

Writing good firewall rules

  1. Start from default deny.
  2. Write rules by business need: source zone/group, destination, service, with owner and ticket in the comment.
  3. Be as specific as possible (no any any).
  4. Put specific rules above general ones.
  5. Log denies and important allows.
  6. Review regularly; remove stale rules.
  7. Test changes in a window with a rollback plan; keep configuration under version control.

4. VPNs

A Virtual Private Network carries private traffic over an untrusted network (the internet) using encryption and authentication.

  • Site-to-site VPN: two gateways (firewalls or routers) create an always-on encrypted tunnel so two offices share their private address spaces. Typically IPsec (IKE negotiates keys, ESP encrypts) or WireGuard.
  • Remote-access VPN: an individual’s laptop connects to the company network through a client (IPsec/IKEv2, SSL/TLS VPN, WireGuard). Use multi-factor authentication and check device health.
  • Split tunnelling sends only company traffic through the VPN; full tunnelling sends everything (more control, more load).
  • Zero Trust Network Access (ZTNA) is the modern alternative: grant access to specific applications per user and device, not to a whole network.
  • VPN security depends on strong algorithms, certificate or key management, up-to-date gateways (VPN appliances are a favourite target, so patch them promptly) and firewall rules after the tunnel.

5. Other essential controls

  • Authentication and AAA: strong passwords, MFA, 802.1X for network access, TACACS+/RADIUS for administrators.
  • Device hardening: change default passwords, disable unused services and ports (Telnet, HTTP management), use SSH and HTTPS, restrict management to a management VLAN, keep firmware patched, back up configurations.
  • Port security and DHCP snooping on access switches; disable unused ports.
  • Intrusion detection/prevention (IDS/IPS): detect and block known attack patterns.
  • Logging and monitoring: send logs to a central server or SIEM, synchronise clocks with NTP, alert on anomalies.
  • Encryption of data in transit (TLS, SSH, IPsec) and at rest.
  • Backups and recovery that are tested and kept offline or immutable.
  • User awareness: phishing is still the most common entry point.
  • Physical security: locked cabinets and controlled access to network rooms.

6. Hands-on: evaluate an ACL

Implement packet filtering with real subnet matching using Python’s ipaddress.

  • acl_decision(acl, src, dst, port): each rule has src and dst ("any" or a CIDR such as "10.1.0.0/16"), port ("any" or a number) and action. Return the action of the first matching rule, or "deny" if nothing matches.
  • shadowed_rules(acl): return the list of indexes of rules that can never fire because an earlier rule matches everything they match (source and destination covered by the earlier rule’s network, and the earlier port is any or the same).
ACL decisions and shadowed rules — Python 3
YOUR CODE (edit here, then press Run)
Ctrl/⌘ + Enter
OUTPUT
You must let the internet reach a public web server while protecting the internal network. Describe a safe design.

Place the web server in a DMZ behind a firewall. Allow inbound TCP 443 (and 80 redirecting to 443) from the internet to that server only, allow the server to reach only the specific internal services it needs (such as a database on one port, ideally through a further firewall), and deny the DMZ from initiating connections to the inside otherwise. Harden and patch the server, add a WAF if possible, log and monitor, and use default deny on every zone boundary.

Can You Explain It?

Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.

  • Explain the difference between ACLs, stateful firewalls and next-generation firewalls.
  • Describe a DMZ and the traffic that should be allowed to and from it.
  • Compare site-to-site and remote-access VPNs and the controls that protect each.

7. Key takeaways

  • Protect confidentiality, integrity and availability with layered controls and default deny.
  • ACLs are stateless, ordered, first-match filters; stateful firewalls track connections; NGFWs understand applications and users.
  • Use zones and a DMZ so a compromised public server cannot reach the inside.
  • VPNs encrypt traffic over untrusted networks (site-to-site and remote access); secure and patch the gateway.
  • Audit rules for shadowing, harden devices, log centrally and test your changes.

🧪 Want to practise this on your own computer? See how to set up your lab →

🤖

Need clarification? Ask GT

Hi, I'm GT — your AI tutor for Network Security Basics: Firewalls, ACLs and VPNs. What would you like to know?
📝

Knowledge Check

1 of 4

What is the difference between a stateless ACL and a stateful firewall?

Report a problem

About: /lessons/network-security-basics-firewalls-acls-and-vpns