What is a firewall? Compare packet-filtering, stateful and application-layer firewalls.
MediumConceptTLS, Firewalls & Load Balancers
Answer
A firewall is hardware or software that allows or blocks traffic according to rules, usually at the boundary between a trusted internal network and an untrusted one such as the internet. A sound default is to deny everything and allow only what is needed.
- Packet-filtering (stateless): checks each packet on its own against rules on source and destination IP address, port and protocol. It is fast but has no memory, so it cannot tell whether an incoming packet is a reply to a request from inside.
- Stateful: tracks each connection in a state table, so it automatically allows replies to connections started from inside and blocks unsolicited inbound packets. Most modern firewalls are stateful.
- Application-layer (proxy): understands protocols such as HTTP and inspects the content, for example to block SQL injection or certain URLs; a web application firewall (WAF) is one kind. It gives the finest control but is the slowest.
Example: A rule set for a web server, checked from top to bottom:
1. ALLOW TCP any -> 10.0.0.5 port 443 (HTTPS from anyone)
2. ALLOW TCP 10.0.1.0/24 -> 10.0.0.5 port 22 (SSH from the admin subnet only)
3. DENY any any -> any (default deny)
An SSH attempt from the internet matches no ALLOW rule and is blocked by rule 3.