Course outline

1.12

Firewall, Forward vs Reverse Proxy, and VPN

The guards and go-betweens of a network: what each one hides, allows, blocks and protects.

38 min Reading + animations

Tip: tap or hover any dotted-underlined term to see what it means.

By the end of this lesson you will be able to

  • Explain what a firewall checks, why rule order and “default deny” matter, and how a stateful firewall lets replies back in.
  • Tell a network firewall, a WAF, an IDS and an IPS apart, and design a simple DMZ.
  • Configure cloud security groups and NACLs without the classic ephemeral-port mistake.
  • Explain forward and reverse proxies, who each one represents and hides, and how HTTPS passes through a proxy (CONNECT).
  • Describe what a reverse proxy does in production: load balancing with health checks, TLS termination, caching, routing, rate limiting, X-Forwarded-For, and where an API gateway fits.
  • Explain how a VPN tunnel works, the main protocols, remote-access vs site-to-site, and exactly what a VPN does and does not hide.
  • Name the typical attack at each network layer and the defence that works at that layer, and explain why zero trust and mTLS go beyond a network perimeter.

#Three middlemen, three different jobs

Between your device and a server there are often machines that are not the final destination but still handle your traffic. The three you will meet everywhere:

MiddlemanIts questionTypical place
Firewall“Is this traffic allowed?”At the edge of every network, and on every computer
Proxy“Shall I make this request for you?”In front of clients (forward proxy) or in front of servers (reverse proxy)
VPN“How do I carry this privately across a network I do not trust?”Between a device (or office) and a VPN server

They are often combined: a company network has a firewall at the edge, staff browse through a forward proxy, the website sits behind a reverse proxy, and remote staff connect through a VPN. Keep their jobs separate in your head and the combinations become easy.

#Firewall

A firewall is a network security system that inspects incoming and outgoing traffic and allows or blocks it based on predefined security rules.

[Unfiltered internet] ──► [Firewall: rule inspection] ──► [Secured internal network]
                                    │
                               (block / drop)

#Packet filtering: rules, order and default deny

The most basic firewall job is packet filtering. For every packet it reads a few header fields:

  • Source IP and destination IP: who is sending, and to whom.
  • Source port and destination port: which service (443 = HTTPS, 22 = SSH, 3306 = MySQL…).
  • Protocol: TCP, UDP, ICMP.
  • Direction: inbound (from outside to inside) or outbound (inside to outside).

It compares them with a rule table, from the top down. The first matching rule decides, and the rest are not read. If nothing matches, the default policy applies, which on any well-run firewall is deny.

Firewall rules: every packet against an ordered list

The firewall reads each packet’s source IP, destination IP, port and protocol, and walks the rules from the top. The first rule that matches decides.

Scenario

A normal visitor reaches the website on port 443.

Visitor198.51.100.7
Admin at home192.0.2.50
Attacker / bad host198.51.100.66
Firewallrule table
Web server203.0.113.10
Database10.0.1.20
Office PC10.0.2.15
SYN :443

Header fields the firewall reads

Source IP

198.51.100.7

Destination IP

203.0.113.10

Protocol

TCP

Destination port

443

Step 1 of 4
1

A visitor’s browser sends a TCP SYN to the web server’s public address on port 443 (HTTPS). Every packet must pass the firewall first.

  • Inbound rules filter traffic coming in. Classic example: keep port 22 (SSH) closed to the world, and open it only to the admin’s address or a VPN.
  • Outbound rules (egress filtering) control traffic going out. Examples: stop office computers reaching harmful or banned categories of site, or stop an infected machine connecting to its attacker on an unusual port.
  • Order is part of the policy. A specific allow (“SSH from 192.0.2.50”) must sit above the general deny (“SSH from anyone”). A forgotten “allow any to any” at the top silently disables everything below it.
  • Default deny, then allow what you need is far safer than “allow everything, then block what looks bad”. You cannot list every bad thing; you can list the few good ones.
  • Drop vs reject. Dropping sends nothing back (scanners learn less); rejecting replies with a TCP RST or ICMP error (honest clients fail fast). Internet-facing edges usually drop.

#Stateful inspection

A simple packet filter judges each packet alone. That creates a problem with replies. When your laptop opens a connection to a website, it uses a random high source port (an ephemeral port, say 51000). The website’s answer arrives inbound to port 51000. A stateless filter must have a rule for that, and since the port is random the rule must be broad (“allow inbound to 1024–65535”), which also lets in anything else aimed at those ports.

A stateful firewall solves this by tracking whole connections in a state table (also called a connection table). Outbound connections create an entry; inbound packets are allowed only if they belong to an existing entry. Modern firewalls work this way, as the notes say: they do not decide from one packet alone, they track the whole session, and let traffic in only if it is the response to a valid request started from inside.

Stateless vs stateful: how return traffic gets back in

A stateless filter judges every packet alone. A stateful firewall keeps a connection table and lets in only replies to conversations started from inside.

Scenario

Your laptop192.168.1.10
Firewall
Web server203.0.113.80
Attacker198.51.100.66
SYN :51000 → :443
Step 1 of 8
1

Your laptop opens a connection to a website: source port 51000 (a random “ephemeral” port), destination port 443. The outbound rule allows web traffic.

Two practical consequences:

  • Home routers and cloud security groups are stateful, which is why “block all inbound, allow all outbound” just works: replies come back, unsolicited connections do not.
  • State tables are finite, so idle entries expire. A long-lived connection that sends nothing (a database pool, a chat socket) can be silently cut by a firewall or NAT device in between. Keepalives shorter than the idle timeout prevent it.

#Hardware and software firewalls

TypeWhat it isExamplesProtects
Hardware (network) firewallA dedicated physical appliance, usually at the edge between the internet connection and the internal network (often doing routing and NAT too)Fortinet FortiGate, Palo Alto Networks, CiscoA whole network
Software (host) firewallA program running in the operating systemWindows Defender Firewall, Linux ufw (a friendly front end to nftables/iptables), macOS firewallOne computer
Cloud firewallRules enforced by the cloud platform around virtual serversAWS security groups and NACLs, Azure network security groups, Google Cloud firewall rulesCloud servers and subnets

Use both layers: the network firewall stops most junk at the edge, and the host firewall still protects a machine if something inside the network is compromised or a laptop joins café Wi-Fi.

#Beyond packet filters: WAF, IDS/IPS and the DMZ

A packet filter sees addresses and ports. Many attacks arrive on port 443, inside perfectly valid connections. Other layers catch those:

  • WAF (Web Application Firewall): works at the application layer. It terminates TLS, reads the HTTP request and blocks attacks such as SQL injection, cross-site scripting (XSS) and abusive bots. Cloudflare, AWS WAF and open-source rule sets are common.
  • IDS (Intrusion Detection System): watches a copy of the traffic for known attack signatures and unusual behaviour, and alerts. It is not in the path, so it cannot stop anything by itself.
  • IPS (Intrusion Prevention System): sits inline and blocks what it detects. More protective, but a false positive blocks real users, and it must keep up with full traffic speed.
  • NGFW (next-generation firewall): one appliance combining stateful filtering, IPS, application awareness (“this is Facebook video”) and often TLS inspection.
  • DMZ (demilitarised zone): a separate network zone for servers the internet must reach (web servers, mail relays). The internet can reach the DMZ; the DMZ can reach the inside only through narrow, specific rules. If a DMZ server is broken into, the attacker is still outside the database network.

Defence in depth: firewall, WAF, IDS/IPS and a DMZ

Each layer catches what the one before cannot see. Public-facing servers sit in a separate zone (DMZ) so a break-in there does not reach the database.

Scenario

Visitor
Attacker
Edge firewallports + IPs
WAFreads HTTP
IDS / IPSwatches traffic
Web server (DMZ)
Internal firewall
App serverprivate
Databaseprivate
HTTPS
Step 1 of 5
1

A visitor’s HTTPS request reaches the edge firewall. Port 443 to the web tier is allowed.

#Firewalls in the cloud: security groups and NACLs

In AWS (and similarly in other clouds) every packet to a server passes two filters:

Security groupNetwork ACL (NACL)
Applies toEach instance (its network interface)A whole subnet
StateStateful: replies are allowed automaticallyStateless: replies need their own rule
RulesAllow onlyAllow and deny, evaluated by rule number, lowest first
Typical useYour main filter: “443 from anywhere, 5432 only from the app servers’ group”Coarse subnet guard, or blocking a specific abusive range

In the cloud: security groups vs network ACLs

On AWS (and similar clouds) a packet to a server passes two filters: the subnet’s NACL (stateless) and the instance’s security group (stateful).

Scenario

Abusive IP198.51.100.66
User198.51.100.7
NACLsubnet, stateless
Security groupinstance, stateful
Server10.0.1.10
TCP :51000 → :443
Step 1 of 6
1

A user’s request enters the subnet. The NACL checks its inbound rules in number order: rule 100 allows TCP 443.

The bug in the second scenario catches almost everyone once: a NACL that allows only port 443 outbound drops every response, because responses go to the client’s ephemeral port, not to 443.

Self-checkQuestion

Your stateful firewall allows all outbound traffic and has no inbound rules except the default deny. You open a website. Why does the page load?

#Proxy servers

Proxy means “representative”: someone who acts on another’s behalf. A proxy server is a middleman that receives requests and makes them itself. There are two kinds, and their purposes are opposite:

Forward proxy:
[Client A, B, C] ──► [Forward proxy] ──► [Internet] ──► [Destination server]
(hides the clients and sends requests on their behalf)

Reverse proxy:
[Internet clients] ──► [Reverse proxy] ──► [Server 1 / Server 2 / Server 3]
(hides the servers and receives requests on their behalf)

The quick test: whose side is it on? A forward proxy is configured and run by (or for) the clients. A reverse proxy is run by the website owner, and clients usually do not know it exists.

#Forward proxy

A forward proxy sits in front of the clients. When a client wants a site, it does not connect directly: it asks the proxy, and the proxy fetches the data from the site and hands it back.

Forward proxy: speaking for the client

The client sends its requests to the proxy, and the proxy fetches from the internet on its behalf. Websites see the proxy, not the client.

Scenario

Employee laptop10.0.2.15
Forward proxy203.0.113.5
Website198.51.100.30
GET http://example.com/news
Step 1 of 8
1

The browser is configured to use the proxy, so it sends the full URL to the proxy instead of connecting to example.com itself.

Its main purposes:

  • Anonymity: the destination server sees the proxy’s IP, not the client’s real IP.
  • Bypassing geo-restrictions: a proxy in another country makes you appear to be there. The same trick bypasses office or school restrictions, which is why organisations block known proxies.
  • Content filtering and access control: an office can stop staff using Facebook or irrelevant sites, block malware and phishing sites for everyone, and log who went where.
  • Caching: popular files are served from the proxy, saving bandwidth (much less effective today, because most traffic is HTTPS and cannot be cached by a proxy that does not decrypt it).

How the client reaches the proxy:

  • Configured proxy: the browser or OS has the proxy’s address. For plain HTTP it sends the full URL to the proxy (GET http://example.com/news).
  • HTTPS through a proxy: the browser sends CONNECT example.com:443, the proxy opens a TCP connection and then just relays encrypted bytes. TLS stays end to end; the proxy knows the host name, not the page. Seeing inside requires TLS interception: the company installs its own root certificate on staff devices and the proxy decrypts and re-encrypts. That is powerful and risky, and apps that pin certificates break.
  • PAC file (proxy auto-config): a small JavaScript file that tells the browser which proxy to use for which URL (“internal sites direct, everything else via the proxy”). Companies push it to all devices.
  • Transparent (intercepting) proxy: nothing is configured; the network gateway silently redirects traffic into the proxy. Hotel Wi-Fi login pages and some ISP caches work this way.
  • SOCKS proxy: a lower-level proxy that relays any TCP (and SOCKS5 also UDP) connection, not just HTTP. SSH can create one (ssh -D).

#Reverse proxy

A reverse proxy sits in front of the servers. Users think they are hitting the real web server, but they are actually hitting the reverse proxy, which accepts the request and passes it to a suitable internal server (a backend node).

Reverse proxy: one front door for many servers

Clients only ever talk to the reverse proxy’s address. Behind it, the proxy decides which server handles each request.

Scenario

User A198.51.100.7
User B192.0.2.44
Attacker198.51.100.66
Reverse proxyapi.example.com → 203.0.113.10
web110.0.0.11
web210.0.0.12
web310.0.0.13
Orders API10.0.0.21
GET /

Upstream pool (the proxy’s view of the backends)

BackendHealthActive connections
web1 10.0.0.11healthy0
web2 10.0.0.12healthy0
web3 10.0.0.13healthy0
Step 1 of 5
1

User A’s request arrives at the proxy. DNS for the site points only at the proxy, so this is the only address users know.

What it does for you:

  • Load balancing: spreads millions of users across several backend servers (round robin, least connections, IP hash), using health checks to stop sending traffic to a server that fails.
  • Security and DDoS protection: the origin servers’ real IPs stay hidden, so attackers can only hit the proxy, which is built to absorb floods (Cloudflare is the famous example). This only works if the origin also refuses traffic that does not come from the proxy.
  • TLS (SSL) termination: the heavy encryption work happens between client and proxy, so backend servers are free for application work, and certificates live in one place.
  • Caching: static content (images, files, CSS) is served from the proxy without bothering the servers.
  • Plus, in practice: compression, rate limiting (429 Too Many Requests), path- and host-based routing to different services, adding X-Forwarded-For and X-Forwarded-Proto headers so backends know the real client, request size limits and timeouts, and zero-downtime deploys by draining one server at a time.

Popular software: Nginx, HAProxy, Envoy, Traefik, Caddy; managed: Cloudflare, AWS Application Load Balancer, Google Cloud Load Balancing. How these programs work inside is the subject of Web Servers and App Servers.

#Where TLS ends

Where the encryption stops decides what the proxy can do. Termination gives it full visibility (cache, route, add headers); re-encryption keeps every hop encrypted, as compliance or zero-trust networks require; passthrough keeps the keys on the backend but turns the proxy into a blind layer 4 relay that routes only on the server name (SNI).

TLS termination, re-encryption and passthrough

Where the encryption ends decides what the proxy can do: cache, route on paths, add headers, or nothing but forward bytes.

Scenario

Browser
Reverse proxypublic certificate
App server10.0.0.11
TLS Client Hello (SNI: shop.example.com)
Step 1 of 6
1

The browser starts a TLS handshake with the proxy. The proxy holds the site’s certificate and private key.

#The API gateway: a specialised reverse proxy

An API gateway (Kong, AWS API Gateway, Apigee, Envoy-based gateways) sits where a reverse proxy sits, but understands APIs: it verifies tokens (JWT, API keys), enforces per-client quotas, routes /v1/orders and /v1/users to different microservices, transforms or combines responses, and gives one place for API logs and metrics.

API gateway: a reverse proxy that understands your API

Same position as a reverse proxy, plus API concerns: checking tokens, per-client rate limits, routing to microservices, combining responses.

Scenario

Mobile app
API gatewayapi.example.com
Users service
Orders service
GET /v1/orders (Bearer token)
Step 1 of 5
1

The app calls the API with a JWT access token in the Authorization header.

Rule of thumb: put cross-cutting concerns in the gateway (authentication, rate limits, routing, logging), and keep business logic in the services. A gateway that knows too much becomes a bottleneck every team has to change.

#Forward vs reverse proxy

CriterionForward proxyReverse proxy
Acts forThe clientThe server
HidesThe client’s real IPThe origin servers’ IPs and architecture
Set up byThe client side (user, company admins)The website owner
Client aware of it?Usually yes (configured), unless transparentUsually no
Main benefitsPrivacy, access control, filteringLoad balancing, security, TLS termination, caching
Popular examplesCorporate proxies (Squid, Zscaler), anonymising proxiesCloudflare, Nginx, HAProxy, Envoy, cloud load balancers

The notes list “VPN services” as a forward-proxy example. The role is similar (a middleman that hides your IP), but a VPN works at the network layer for all traffic from every app, while a proxy usually works per application. The comparison table in the VPN section below makes the difference precise.

Self-checkQuestion

A backend behind Nginx logs every request as coming from 10.0.0.5. What is the correct way to log the real client IP?

#VPN (Virtual Private Network)

A VPN creates an encrypted, secure virtual tunnel across an open, untrusted public network such as the internet.

                     Unsecured public network
[Client] ═══ encrypted VPN tunnel (e.g. AES-256) ═══► [VPN server] ──► [Target website]

How it works:

  1. Tunnelling protocol: VPN client software (WireGuard, OpenVPN, IPsec) sets up a tunnel between your device and the VPN server, after both sides authenticate and agree keys.
  2. Encryption: every packet leaving your device is encrypted (with AES-256, or ChaCha20 in WireGuard) and wrapped inside a new packet addressed to the VPN server. Your ISP, a hacker on the same Wi-Fi or the Wi-Fi owner cannot see what you send or receive, or which sites you visit.
  3. IP masking: your traffic reaches the website via the VPN server, which forwards it from its own address. The website sees the VPN server’s IP instead of yours.

VPN: an encrypted tunnel through networks you do not trust

Watch the packet header in each scenario: who can read what, and which address the website sees.

Scenario

You (café Wi-Fi)192.168.0.23
Café router203.0.113.200sees: shop.example
ISP
ISP DNS resolver
VPN server203.0.113.50
Website198.51.100.30
A? shop.exampleA? shop.example
Step 1 of 3
1

First your laptop looks up shop.example. Classic DNS is plain text, so the café and the ISP can read every name you look up.

Inside the tunnel it is literally a packet inside a packet:

Inside a VPN packet: a packet inside a packet

Your normal packet is encrypted and becomes the payload of a new outer packet addressed to the VPN server (WireGuard shown).

Scenario

HTTPGET /account
Step 1 of 5
1

The browser produces an HTTP request.

#Protocols

ProtocolNotes
WireGuardModern and small (a few thousand lines of code), very fast, UDP only, fixed modern cryptography (ChaCha20-Poly1305, Curve25519). Reconnects quickly when you switch networks. The default in most new VPN products.
OpenVPNMature and flexible, uses TLS, runs over UDP or TCP (TCP 443 helps it pass restrictive firewalls). Slower and more complex than WireGuard.
IPsecThe long-standing standard for site-to-site links between company gateways and for built-in phone and laptop VPN clients (usually with IKEv2 key exchange). Widely supported by hardware firewalls.

Older protocols such as PPTP are broken and should not be used.

#Remote-access vs site-to-site

Remote-access vs site-to-site VPN

Scenario

Employee at homeVPN app
Branch PC10.2.0.15
Branch gatewayChattogram
Internet
Head-office VPN gatewayDhaka
File server10.1.0.20
Accounts app10.1.0.30
tunneltunnel
Step 1 of 4
1

An employee at home opens the VPN app and signs in (password plus a second factor). The app builds a tunnel to the office’s VPN gateway.

  • Remote-access VPN: one user’s device connects to the company network, gets an internal address, and can reach private servers. Needs client software and strong sign-in (with a second factor).
  • Site-to-site VPN: two gateways keep a permanent tunnel so two offices (or an office and a cloud network) act as one network. Devices need no VPN software. Cloud providers sell this as a managed service.
  • Consumer VPN services (NordVPN and similar) are remote-access VPNs whose “company network” is simply the internet, used for privacy on public Wi-Fi or to appear in another country.

#Full vs split tunnel, DNS leaks and kill switches

  • Full tunnel: all traffic goes through the VPN. Most private, lets a company filter everything, but slower and loads the VPN.
  • Split tunnel: only some traffic (company networks) goes through the VPN; the rest goes directly. Faster, but the device is on the open internet and the private network at the same time.
  • DNS leak: the tunnel is up but DNS queries still go to the ISP’s resolver outside it, revealing every name you visit. A good VPN client pushes its own resolver and blocks DNS outside the tunnel. WebRTC in browsers can similarly reveal your real IP.
  • Kill switch: if the tunnel drops, a local firewall rule blocks all traffic until it reconnects, instead of silently falling back to your real connection.

#VPN vs proxy vs Tor

ProxyVPNTor
Works atApplication (per app or per browser)Network layer (all apps, all traffic)Application (Tor Browser)
Encrypts your traffic?Not by itself (HTTPS still protects content)Yes, device to VPN serverYes, in three layers, across three relays
Who can see your destinationsThe proxy operatorThe VPN providerNo single relay sees both you and your destination
SpeedFastFast (small overhead)Slow
Typical useOffice filtering, scraping, geo-access for one appPublic Wi-Fi privacy, remote work, linking officesStrong anonymity and censorship resistance

#Attacks by layer, and the defence at each

Firewalls, proxies and VPNs are each one layer of protection. Attacks arrive at every layer of the network model, and each layer has its own defence. The rule of thumb: an attack can only be stopped by something that sees its layer. A packet filter cannot see an SQL injection inside a valid HTTPS request, and a WAF in the data centre cannot see ARP spoofing on an office LAN.

LayerTypical attacksHow they workDefence at that layer
1 PhysicalCable tapping, radio jamming, device theftCopy the signal, drown Wi-Fi in noise, walk off with a laptop or diskLocked comms rooms, spare ports switched off, cameras, disk encryption; encryption in transit makes a tap useless
2 Data linkARP spoofing, MAC spoofing and flooding, VLAN hoppingClaim the gateway’s IP to become a man-in-the-middle; overflow the switch’s MAC table so it floods every frame like a hub; trick a user port into a trunk to reach other VLANsDynamic ARP Inspection with DHCP snooping, port security (a MAC limit per port), no automatic trunking on user ports, port authentication before a device may join
3 NetworkIP spoofing, ICMP floods, route hijacksForge source addresses; fill the link with junk; announce someone else’s prefixIngress (anti-spoofing) filtering, ACLs, ICMP rate limits, upstream DDoS scrubbing, RPKI (lesson 1.7), IPsec between sites
4 TransportSYN flood, port scanningFill the table of half-open connections; map which ports are openSYN cookies, stateful firewall, default deny, connection rate limits, IDS alerts on scans
5–6 Session, presentationSession hijacking, weak or missing encryptionSteal a session cookie or token; read traffic sent in clear or with broken ciphersTLS 1.2 or newer (prefer 1.3), secure cookie flags and new session IDs at login (lesson 1.3)
7 ApplicationSQL injection, XSS, HTTP floods, password attacksSmuggle code in through input; flood with valid-looking requests; try leaked passwordsWAF, parameterised queries, output encoding, rate limits and bot checks, MFA

Two ideas come out of that table:

  • Defence in depth. No layer is enough on its own. The edge firewall cuts out most junk so the expensive layers above are not overwhelmed; the WAF is a safety net for buggy code; the code itself is the real fix for injection. If one layer fails, the next one still stands.
  • Encryption protects everything below it. An ARP-spoofing attacker or a cable tap gets only ciphertext if the traffic is TLS or a VPN. That is why modern networks encrypt even inside traffic, which leads straight to zero trust.

Defence in depth: every attack is stopped at the layer where it can be seen

An office LAN and a public web app. Pick a layer to watch its typical attack, then the defence that works at that layer.

Scenario

Attacker on the internet
Edge router + firewallL3 / L4
WAF / reverse proxyL7
Web app
Rogue device in the office
Access switchL2
Staff laptop192.168.1.20
spare wall port

Attacks by layer

LayerAttackStopped by
L1cable tap, radio jamming, theftlocked rooms, disabled ports, encryption
L2ARP spoofing, MAC flooding, VLAN hoppingDynamic ARP Inspection, port security, no auto-trunking
L3IP spoofing, ICMP flood, route hijackingress filtering, rate limits, upstream scrubbing, RPKI
L4SYN flood, port scanSYN cookies, stateful firewall, default deny
L7SQL injection, XSS, HTTP floodWAF, parameterised queries, rate limits
Step 1 of 3
1

Layer 1 attacks need physical access: plugging a device into a spare wall socket, tapping a cable in the ceiling, or jamming Wi-Fi with a radio transmitter. No packet filter can see any of this.

#Between services: mTLS and zero trust

The classic company network is a castle with a moat: a firewall at the edge, and everything inside trusted. Its weakness shows the day an attacker gets one machine inside, through a phished laptop or a vulnerable web server: from there they can reach everything else, because the inside trusts the inside. This lateral movement is part of most serious breaches.

Zero trust drops the idea of a trusted network. Every request must prove who it comes from and be authorised, wherever it comes from:

  • Between services, the proof is mutual TLS (mTLS). Both sides present certificates, so the payments service knows the caller really is the orders service, not just “something at 10.0.3.7”. The certificates are short-lived and issued automatically, usually by a service mesh (Istio, Linkerd) or the platform, so nobody handles keys by hand.
  • Identity is followed by policy: “orders may call payments; nothing else may”. A compromised web server can no longer reach the database just because it sits on the same network.
  • For people, the same idea replaces the VPN with an identity-aware proxy: every internal app checks the user and the device on every request (Google runs its own staff access this way).

Firewalls and network segmentation still matter as extra layers; zero trust only stops treating the network location as proof of anything. Identities, certificates, tokens and access policies get their full treatment in chapter 33, Identity and Access.

#How these appear in system design

A typical production request path combines all three ideas:

User ─► DNS ─► CDN / WAF / DDoS protection ─► load balancer (reverse proxy, TLS termination)
     ─► API gateway ─► services (in private subnets, security groups)
     ─► database (reachable only from the services)

Engineers ─► VPN or zero-trust access ─► private admin tools (never SSH open to the internet)
Services  ─► NAT gateway / egress proxy ─► third-party APIs (outbound allow list)

Design points interviewers and incidents ask about:

  • The reverse proxy is a single point of failure unless it is redundant: run at least two load balancer nodes (or use a managed, multi-zone one) behind one DNS name or a floating IP.
  • Health checks must test something real. A /healthz that returns 200 while the database is unreachable sends users to a broken server; a check that is too strict can take every server out at once.
  • Keep servers private. Only the load balancer has a public address; security groups allow the app port only from the load balancer’s group, and the database port only from the app’s group.
  • Admin access through a VPN, a bastion host or a zero-trust access service, never port 22 open to the world.
  • Egress control limits what a compromised service can reach and gives a stable outbound IP that partners can allow-list.
  • Preserve the client IP through every proxy (X-Forwarded-For, or HAProxy’s proxy protocol for plain TCP) and trust it only from your own proxies.
  • Automate certificate renewal at the TLS termination point; expiry is one of the most common self-inflicted outages.
  • Layer the defences: DDoS scrubbing and the edge firewall for layers 3–4, a WAF and rate limits for layer 7, and mTLS with per-service policy inside, so one breached machine is not a breached system.

#Try it yourself

# Linux (Ubuntu): a sensible host firewall in five lines
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 443/tcp
sudo ufw allow from 192.0.2.50 to any port 22 proto tcp   # SSH only from one address
sudo ufw enable && sudo ufw status numbered               # rules in order

# Windows (PowerShell): firewall profiles and a rule
Get-NetFirewallProfile | Select-Object Name, Enabled, DefaultInboundAction
New-NetFirewallRule -DisplayName "Block 3306 in" -Direction Inbound -Protocol TCP -LocalPort 3306 -Action Block
# Watch a forward proxy's CONNECT tunnel (any proxy you have access to)
curl -v -x http://proxy.example.com:3128 https://example.com/ 2>&1 | grep -i connect

# Look for reverse proxies and caches in response headers
curl -sI https://www.cloudflare.com | grep -iE "server|cf-cache-status|age"

# Your public IP, with and without the VPN connected
curl https://ifconfig.me

A minimal Nginx reverse proxy with load balancing and the usual headers:

upstream web_pool {
    server 10.0.0.11:8080 max_fails=3 fail_timeout=10s;
    server 10.0.0.12:8080 max_fails=3 fail_timeout=10s;
}
server {
    listen 443 ssl;
    server_name shop.example.com;
    ssl_certificate     /etc/ssl/shop.crt;   # TLS terminates here
    ssl_certificate_key /etc/ssl/shop.key;

    location /api/orders/ { proxy_pass http://10.0.0.21:8080; }   # path-based routing
    location / {
        proxy_pass http://web_pool;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host              $host;
    }
}

#Summary

Key takeaways

  • A firewall allows or blocks traffic using rules on IPs, ports, protocol and direction. Rules are checked top to bottom, first match wins, ending in default deny. Inbound rules guard services (close port 22 to the world); outbound rules stop data and malware getting out.
  • Stateful firewalls track connections, so replies come back without broad inbound rules. Stateless filters (router ACLs, cloud NACLs) need explicit rules for return traffic on ephemeral ports. Idle state expires: use keepalives.
  • Hardware firewalls protect networks, software firewalls protect hosts; use both. NAT is not a firewall. A WAF reads HTTP, an IDS alerts, an IPS blocks inline, a DMZ isolates public servers. In the cloud, security groups are stateful, NACLs stateless.
  • A forward proxy acts for clients: anonymity, geo-bypass, filtering, caching. HTTPS passes through it with CONNECT, end to end, unless the company intercepts TLS.
  • A reverse proxy acts for servers: load balancing with health checks, hiding the origin and absorbing DDoS, TLS termination, caching, routing, rate limiting, X-Forwarded-For. An API gateway is a reverse proxy specialised for APIs.
  • A VPN wraps encrypted packets inside packets to a VPN server (WireGuard, OpenVPN, IPsec): the local network and ISP see only the tunnel, and websites see the VPN’s IP. It does not hide you from the VPN provider or from sites you log in to. Watch for DNS leaks; use a kill switch.
  • Every layer has its own attacks and defences: tapping (physical security, encryption), ARP spoofing (Dynamic ARP Inspection), IP spoofing and floods (ingress filtering, scrubbing), SYN floods and scans (SYN cookies, default deny), SQL injection and HTTP floods (WAF, safe code, rate limits). Zero trust adds mTLS and per-service policy so being inside the network proves nothing.