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:
| Middleman | Its question | Typical 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.
Header fields the firewall reads
Source IP
198.51.100.7
Destination IP
203.0.113.10
Protocol
TCP
Destination port
443
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 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
| Type | What it is | Examples | Protects |
|---|---|---|---|
| Hardware (network) firewall | A 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, Cisco | A whole network |
| Software (host) firewall | A program running in the operating system | Windows Defender Firewall, Linux ufw (a friendly front end to nftables/iptables), macOS firewall | One computer |
| Cloud firewall | Rules enforced by the cloud platform around virtual servers | AWS security groups and NACLs, Azure network security groups, Google Cloud firewall rules | Cloud 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
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 group | Network ACL (NACL) | |
|---|---|---|
| Applies to | Each instance (its network interface) | A whole subnet |
| State | Stateful: replies are allowed automatically | Stateless: replies need their own rule |
| Rules | Allow only | Allow and deny, evaluated by rule number, lowest first |
| Typical use | Your 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
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
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
Upstream pool (the proxy’s view of the backends)
| Backend | Health | Active connections |
|---|---|---|
| web1 10.0.0.11 | healthy | 0 |
| web2 10.0.0.12 | healthy | 0 |
| web3 10.0.0.13 | healthy | 0 |
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
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
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
| Criterion | Forward proxy | Reverse proxy |
|---|---|---|
| Acts for | The client | The server |
| Hides | The client’s real IP | The origin servers’ IPs and architecture |
| Set up by | The client side (user, company admins) | The website owner |
| Client aware of it? | Usually yes (configured), unless transparent | Usually no |
| Main benefits | Privacy, access control, filtering | Load balancing, security, TLS termination, caching |
| Popular examples | Corporate proxies (Squid, Zscaler), anonymising proxies | Cloudflare, 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:
- 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.
- 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.
- 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
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
The browser produces an HTTP request.
#Protocols
| Protocol | Notes |
|---|---|
| WireGuard | Modern 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. |
| OpenVPN | Mature and flexible, uses TLS, runs over UDP or TCP (TCP 443 helps it pass restrictive firewalls). Slower and more complex than WireGuard. |
| IPsec | The 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
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
| Proxy | VPN | Tor | |
|---|---|---|---|
| Works at | Application (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 server | Yes, in three layers, across three relays |
| Who can see your destinations | The proxy operator | The VPN provider | No single relay sees both you and your destination |
| Speed | Fast | Fast (small overhead) | Slow |
| Typical use | Office filtering, scraping, geo-access for one app | Public Wi-Fi privacy, remote work, linking offices | Strong 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.
| Layer | Typical attacks | How they work | Defence at that layer |
|---|---|---|---|
| 1 Physical | Cable tapping, radio jamming, device theft | Copy the signal, drown Wi-Fi in noise, walk off with a laptop or disk | Locked comms rooms, spare ports switched off, cameras, disk encryption; encryption in transit makes a tap useless |
| 2 Data link | ARP spoofing, MAC spoofing and flooding, VLAN hopping | Claim 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 VLANs | Dynamic 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 Network | IP spoofing, ICMP floods, route hijacks | Forge source addresses; fill the link with junk; announce someone else’s prefix | Ingress (anti-spoofing) filtering, ACLs, ICMP rate limits, upstream DDoS scrubbing, RPKI (lesson 1.7), IPsec between sites |
| 4 Transport | SYN flood, port scanning | Fill the table of half-open connections; map which ports are open | SYN cookies, stateful firewall, default deny, connection rate limits, IDS alerts on scans |
| 5–6 Session, presentation | Session hijacking, weak or missing encryption | Steal a session cookie or token; read traffic sent in clear or with broken ciphers | TLS 1.2 or newer (prefer 1.3), secure cookie flags and new session IDs at login (lesson 1.3) |
| 7 Application | SQL injection, XSS, HTTP floods, password attacks | Smuggle code in through input; flood with valid-looking requests; try leaked passwords | WAF, 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
Attacks by layer
| Layer | Attack | Stopped by |
|---|---|---|
| L1 | cable tap, radio jamming, theft | locked rooms, disabled ports, encryption |
| L2 | ARP spoofing, MAC flooding, VLAN hopping | Dynamic ARP Inspection, port security, no auto-trunking |
| L3 | IP spoofing, ICMP flood, route hijack | ingress filtering, rate limits, upstream scrubbing, RPKI |
| L4 | SYN flood, port scan | SYN cookies, stateful firewall, default deny |
| L7 | SQL injection, XSS, HTTP flood | WAF, parameterised queries, rate limits |
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
/healthzthat 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.
Answer on your own first, then read the explanation, even when you got it right.
Self-checkQuestion
Your cloud server works, but users get timeouts. The security group allows inbound 443. The subnet’s NACL allows inbound 443 and outbound 443 only. What is wrong?
Self-checkQuestion
You connect to a reputable VPN on café Wi-Fi and log in to your email. Which statement is true?
Self-checkQuestion
Staff on one office floor complain that the internet is slow, and a security tool shows that their laptops map the gateway 192.168.1.1 to the MAC address of an unknown device. Which defence stops this at the layer where it happens?
Self-checkQuestion
A server’s logs show thousands of half-open TCP connections from random addresses, and real users cannot connect. Its firewall allows port 443 from anywhere, as it should. What is the most effective defence at this layer?
Self-checkQuestion
An attacker sends an SQL injection inside a normal HTTPS request on port 443. Which two measures actually stop it? (Choose two.)
Choose 2
Self-checkQuestion
Attackers break into a public web server inside a company VPC. From there they call the internal payments API and the database, which trust anything from inside the VPC. Which design would have stopped this lateral movement?
Self-checkQuestion
A firewall’s rule table starts with “allow any to any”, followed by “deny SSH from anywhere” and “allow SSH from 192.0.2.50”. What happens to an SSH attempt from a random internet address?
Self-checkQuestion
What does “default deny” mean on a firewall?
Self-checkQuestion
An internet-facing firewall can either drop or reject packets to closed ports. Which is usually chosen at the edge, and why?
Self-checkQuestion
A router ACL (stateless) allows outbound TCP to port 443. Web pages still fail to load from inside. What rule is missing?
Self-checkQuestion
A database connection pool works all day, but every morning the first queries hang and then fail. A firewall between the app and the database has a 30-minute idle timeout. What is the fix?
Self-checkQuestion
A team must choose between an IDS and an IPS for a busy payment API. Which statement is correct?
Self-checkQuestion
Why do companies put public web and mail servers in a DMZ?
Self-checkQuestion
One abusive address range keeps hammering your AWS servers. You want to block it for the whole subnet. Which control can do that?
Self-checkQuestion
A company sends all staff web traffic through a proxy that blocks gambling sites and logs who visited what. What kind of proxy is this?
Self-checkQuestion
A browser uses a configured proxy and opens https://bank.example/accounts. Without TLS interception, what can the proxy see?
Self-checkQuestion
A company enables TLS interception on its proxy. Which statement is true?
Self-checkQuestion
Your site is behind a DDoS-protecting reverse proxy service, yet attackers still flood the origin directly. What was missed?
Self-checkQuestion
A load balancer health check calls /healthz, which always returns 200. The database goes down and users get errors, but the balancer keeps sending traffic to every server. What is wrong?
Self-checkQuestion
A proxy is set up for TLS passthrough to keep private keys on the backends. Which feature is no longer possible on the proxy?
Self-checkQuestion
Which two concerns belong in an API gateway rather than in the services behind it? (Choose two.)
Choose 2
Self-checkQuestion
Your VPN shows “connected”, yet a leak test reports that DNS queries go to your ISP’s resolver. What does that mean?
Self-checkQuestion
What does a VPN kill switch do?
Self-checkQuestion
A company uses a split-tunnel VPN. Which trade-off comes with it?
Self-checkQuestion
A hotel network allows only outbound TCP 443. Which VPN choice is most likely to connect?
Self-checkQuestion
Which two can still see your destinations or know who you are while you use a reputable VPN on café Wi-Fi? (Choose two.)
Choose 2
Self-checkQuestion
A company links its office network to its cloud network with a site-to-site VPN. What do the office computers need to install?
Self-checkQuestion
An edge router receives a packet from the internet whose source address is 10.0.0.5, one of the company’s own internal addresses. What should happen?
Self-checkQuestion
Which two statements about zero trust and mTLS are true? (Choose two.)
Choose 2
Self-checkQuestion
A tool on the office LAN floods a switch with frames from thousands of fake MAC addresses. Soon every port receives every other port’s traffic. What happened, and what stops it?