What Is a Firewall? Types, Rules & How They Protect You

The first line of defense between your network and the internet — explained from packet filtering to next-generation firewalls

Firewall Fundamentals: What They Do and Why You Need One

A firewall is a network security device — hardware, software, or cloud-based — that monitors and controls incoming and outgoing network traffic based on a defined set of rules. It sits at the boundary between a trusted internal network and an untrusted external network (typically the internet), acting as a gatekeeper that allows legitimate traffic while blocking threats.

The concept dates to the late 1980s, when the internet was young and security was an afterthought. Today, firewalls are foundational to every organization's security posture, and modern home routers include basic firewall functionality built in. Without a firewall, every device on your network would be directly exposed to internet-based attacks, port scans, and exploitation attempts.

Firewalls operate at different layers of the OSI model. Early packet filters worked at Layer 3 (network) and Layer 4 (transport), examining IP addresses and ports. Modern next-generation firewalls (NGFWs) operate up to Layer 7 (application), understanding protocols like HTTP, DNS, and TLS and making decisions based on application identity and user context.

Key protection capabilities firewalls provide:

Types of Firewalls: From Packet Filters to NGFWs

Packet filtering firewalls are the simplest type. They inspect each packet in isolation, comparing source/destination IP, port, and protocol against a ruleset. They're fast and lightweight but have no concept of connection state — a packet claiming to be part of an established TCP session looks identical to a new connection.

Stateful inspection firewalls maintain a connection state table, tracking the state of every active TCP/UDP session. When an inbound packet arrives, the firewall checks whether it belongs to a known, established connection. This closes the gaps that packet-filtering firewalls leave open and is the baseline expectation for any modern firewall.

Application-layer gateways (ALGs) / proxy firewalls terminate the connection at the firewall and proxy it to the destination. They can inspect the application-layer payload — detecting malware in files, blocking specific URLs, and inspecting encrypted traffic via SSL inspection. The trade-off is higher latency and CPU requirements.

Next-Generation Firewalls (NGFWs) combine stateful inspection with deep packet inspection (DPI), intrusion prevention (IPS), application identification, URL filtering, and user-identity awareness. Products like Palo Alto Networks PA-Series, Fortinet FortiGate, and Cisco Firepower are leading NGFW platforms used in enterprise environments.

Web Application Firewalls (WAFs) specifically protect HTTP/HTTPS applications by inspecting web traffic for SQL injection, cross-site scripting (XSS), CSRF, and other OWASP Top 10 threats. They operate inline in front of web servers and are essential for any internet-exposed application. Use a headers check to verify what your web application exposes to potential attackers.

Understanding Firewall Rules and Rule Order

Firewall rules are processed top-to-bottom, with the first matching rule applied and processing stopped (except in some implementations that use "last match wins"). This means rule order matters enormously. A common mistake is placing a broad "allow all" rule before a specific "deny" rule, rendering the deny rule unreachable.

Each rule typically specifies: source IP/range, destination IP/range, protocol (TCP/UDP/ICMP), port or port range, direction (inbound/outbound), and action (allow, deny, drop, log).

Best practices for firewall rule management:

Use a port checker to verify that your firewall rules are actually enforced — rule misconfigurations are common and often only discovered externally. Run it from outside your network to see what an attacker would observe.

Host-Based vs. Network-Based Firewalls

Network-based firewalls protect entire network segments, sitting at the perimeter between your LAN and the internet or between internal segments. They're managed centrally and enforce policy for all devices behind them. However, they provide no protection against lateral movement after an attacker has already gained a foothold inside the network.

Host-based firewalls run directly on individual machines (Windows Defender Firewall, iptables on Linux, pf on macOS/BSD) and protect that specific device regardless of what network it's on. They're essential for laptops that roam between corporate networks, coffee shops, and home networks. Even behind a network firewall, a host firewall adds an independent layer of defense.

The recommended architecture is "defense in depth": perimeter firewalls plus host firewalls plus network segmentation. This means an attacker who bypasses one layer still faces others. Internal network segmentation — enforced by firewalls between VLANs — limits the blast radius of any breach by preventing an attacker from moving freely through the environment.

Cloud environments require a different approach. AWS Security Groups, Azure NSGs, and GCP VPC Firewall Rules are stateful virtual firewalls applied at the instance level, replacing the traditional perimeter model in cloud-native deployments. Combine these with a WAF and cloud-native threat detection for comprehensive protection.

🛡️

See What's Open on Your Network

Use our port checker to audit your exposed services — the same view an attacker has from the internet

Hide My IP Now
Special Offer

Frequently Asked Questions

Is Windows Firewall good enough for home use?

Windows Defender Firewall is adequate for most home users when properly configured. It blocks unsolicited inbound connections by default. However, it provides minimal outbound filtering, so malware that does get installed can still phone home. Supplement it with a quality router firewall and keep the OS and all software patched.

Can a firewall block all cyberattacks?

No firewall can block all attacks. Firewalls excel at blocking network-based threats like port scans and unauthorized connections, but they can't stop phishing emails, malicious downloads, or compromised software. They're one essential layer in a defense-in-depth strategy that also includes endpoint protection, email security, and user training.

What ports should I always block at the firewall?

Unless explicitly needed, block inbound traffic on: 22 (SSH) from external IPs, 3389 (RDP), 445 (SMB), 1433 (MSSQL), 3306 (MySQL), and 23 (Telnet). For outbound, blocking port 25 from non-mail servers prevents spam relaying. Use a <a href='/port-checker'>port checker</a> to verify your rules are working.

What's the difference between a firewall and an IDS/IPS?

A firewall enforces allow/deny rules based on traffic characteristics. An Intrusion Detection System (IDS) passively monitors traffic for attack signatures and anomalies, generating alerts. An Intrusion Prevention System (IPS) does the same but can automatically block malicious traffic. NGFWs often integrate IPS functionality alongside traditional firewall capabilities.

Special Offer×