Firewalls and Network Security Basics
Learn how firewalls protect networks: packet filtering, stateful inspection, next-gen firewalls, WAFs, DMZ design, defense in depth and common network attacks.
A firewall controls which network traffic is allowed to pass between networks, based on a set of rules. It's the classic first line of defense – but modern network security layers many controls on top of it.
Where firewalls sit#
A typical design separates three zones:
- Untrusted – the internet.
- DMZ (demilitarised zone) – public-facing servers such as web, mail and VPN gateways. If one is compromised, the attacker still isn't inside the internal network.
- Trusted – the internal LAN with employees, databases and internal apps.
Rules are strictest from the internet to the LAN, looser from the LAN outward, and the DMZ can only reach the specific internal services it needs.
Types of firewalls#
| Type | Inspects | Notes |
|---|---|---|
| Packet filter (stateless) | IP, port, protocol of each packet | Fast but blind to connection state |
| Stateful firewall | Tracks connections in a state table | Allows replies automatically; the standard today |
| Proxy / application gateway | Terminates and re-creates connections | Deep control, more overhead |
| Next-generation firewall (NGFW) | Applications, users, IPS, TLS inspection | Identifies apps regardless of port |
| Web application firewall (WAF) | HTTP requests | Blocks SQL injection, XSS and bad bots |
How rules work#
Rules are evaluated top to bottom; the first match wins. Good practice is default deny: block everything, then explicitly allow what's needed.
# ufw (Ubuntu): default deny inbound, allow SSH and HTTPS
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 443/tcp
sudo ufw enableAWS security groups, Azure NSGs and GCP firewall rules are stateful firewalls attached to each instance or subnet. Keep them as tight as possible – never open databases to 0.0.0.0/0.
Defense in depth#
No single control is perfect. Defense in depth stacks independent layers so an attacker who gets past one still faces the next:
- People and policy – security training, strong passwords, MFA.
- Perimeter – firewalls, WAFs, DDoS protection.
- Segmentation – VLANs and internal firewalls limit lateral movement.
- Detection – IDS/IPS and log monitoring (SIEM) spot suspicious behaviour.
- Endpoints – patching, EDR, least privilege.
- Data – encryption in transit and at rest, plus tested backups.
This is the idea behind Zero Trust: don't trust anything just because it's "inside" the network – verify every user and device on every request.
Common network attacks#
- DDoS – floods a target with traffic to take it offline.
- Man-in-the-middle – intercepts traffic, e.g. via ARP spoofing or rogue Wi-Fi.
- Port scanning – maps open services before an attack.
- DNS spoofing – redirects users to malicious sites.
- Phishing – tricks users into giving up credentials, bypassing the network perimeter entirely.
Only scan or test networks you own or have written permission to test. Unauthorised scanning can be illegal.
Key takeaways#
- Firewalls filter traffic by rules; stateful firewalls are the modern baseline.
- A DMZ isolates public servers from the internal network.
- Use default-deny rules and keep cloud security groups tight.
- Defense in depth and Zero Trust layer many controls instead of relying on one.