What Is a Firewall, and How Does It Relate to Operating System Security?

What is a firewall, and how does it relate to operating system security

A firewall is one of the oldest and most fundamental concepts in network security — a control point that decides what network traffic is allowed to pass and what gets blocked. The term borrows its imagery from the physical fire-resistant walls used in buildings and cars to prevent fire from spreading from one compartment to another, and the metaphor holds up well: a network firewall exists to contain and control the spread of malicious or unwanted traffic between different zones of trust. This article covers what firewalls actually do, the different architectural types, how they’re implemented at the OS level across platforms, and how they fit into a broader defense-in-depth security strategy.

What a Firewall Does

At its core, a firewall inspects network traffic — packets flowing in and out of a device or network segment — and makes an allow/deny decision for each one, based on a configured set of rules. Those rules typically match on some combination of source and destination IP address, source and destination port, protocol (TCP, UDP, ICMP), and, in more sophisticated firewalls, application identity or the actual content of the traffic.

Incoming packet:
  Source: 203.0.113.45:51000
  Destination: 192.168.1.10:22 (SSH)
  Protocol: TCP

Firewall rule evaluation:
  Rule 1: Allow TCP to port 443 (HTTPS) — no match
  Rule 2: Allow TCP to port 80 (HTTP) — no match
  Rule 3: Deny all other inbound — MATCH → packet dropped

Types of Firewalls by Inspection Depth

Packet-filtering firewalls are the earliest and simplest type, examining each packet in isolation against static rules (source/destination IP, port, protocol) without tracking any relationship between packets. They’re fast and lightweight but have no concept of “this packet is part of an established conversation,” which limits their sophistication.

Stateful inspection firewalls track the state of active connections (a TCP handshake in progress, an established session) and make decisions based on that context — critically, allowing return traffic for a connection that was legitimately initiated from inside the network, without needing an explicit rule permitting every possible inbound response. This is the dominant model in modern host-based and network firewalls, including Windows Firewall and Linux’s iptables/nftables (via the kernel’s conntrack connection tracking subsystem).

Application-layer (proxy) firewalls operate at Layer 7, understanding the actual application protocol being used (HTTP, DNS, SMTP) well enough to inspect and filter based on content, not just addresses and ports — capable of blocking a specific malicious URL pattern or a disallowed file type in an email attachment, not just a blanket port block.

Next-Generation Firewalls (NGFW) combine stateful inspection with deep packet inspection, application awareness (identifying traffic by the actual application generating it, not just the port it happens to use), integrated intrusion prevention, and often threat intelligence feeds — the standard for modern enterprise network perimeter security.

Where Firewalls Sit: Network vs. Host-Based

Network firewalls are dedicated appliances or virtual appliances sitting at a network boundary (between an internal network and the internet, or between network segments), inspecting all traffic that crosses that boundary regardless of which specific device sent or receives it.

Host-based firewalls run directly on an individual operating system, controlling traffic to and from that specific device. This is where firewalls become directly an operating system security topic rather than purely a network infrastructure topic — every major OS ships with a built-in host-based firewall today.

Internet
   │
   ▼
[Network Firewall]  ← perimeter defense, protects the whole network
   │
   ▼
Internal Network
   │
   ├── [Host Firewall] ── Server A
   ├── [Host Firewall] ── Server B
   └── [Host Firewall] ── Workstation C

This layered approach — a network firewall at the perimeter and host firewalls on individual machines — is a textbook example of defense in depth: even if an attacker gets past the perimeter (through a compromised VPN account, a malicious insider, or lateral movement from an already-compromised machine), host-based firewalls still constrain what that attacker can reach from any single compromised device, preventing trivial lateral movement across the internal network.

How Firewalls Are Implemented at the OS Level

Windows Firewall with Advanced Security is a stateful, host-based firewall built into Windows since XP SP2, tightly integrated with Network Location Awareness, applying different default rule profiles depending on whether the current network is classified Public, Private, or Domain. It supports both inbound and outbound rule filtering, can be scoped to specific applications/services rather than just ports, and is centrally manageable via Group Policy in enterprise Active Directory environments.

netsh advfirewall firewall add rule name="AllowRDP" dir=in action=allow protocol=TCP localport=3389
New-NetFirewallRule -DisplayName "BlockTelnet" -Direction Outbound -Protocol TCP -RemotePort 23 -Action Block

Linux implements firewalling at the kernel level through Netfilter, the underlying packet-filtering framework, exposed to administrators via user-space tools — historically iptables, and increasingly its modern successor nftables, which offers a cleaner syntax and better performance. Many distributions layer a friendlier abstraction on top: ufw (Uncomplicated Firewall, common on Ubuntu) or firewalld (common on Red Hat-family distributions, which introduces the concept of named “zones” representing different trust levels, conceptually similar to Windows’ Public/Private/Domain profiles).

ufw allow 22/tcp
ufw deny from 203.0.113.0/24
firewall-cmd --zone=public --add-service=https --permanent
nft add rule inet filter input tcp dport 22 accept

macOS includes a built-in Application Firewall, which takes a notably different, simpler approach than Windows/Linux — rather than granular port/protocol rules, it primarily controls which applications are permitted to accept incoming connections, reflecting Apple’s general philosophy of abstracting low-level network configuration away from typical users while still relying on the underlying BSD pf (packet filter) framework for more advanced, script-configurable filtering.

Android and iOS don’t expose traditional user-configurable firewalls to typical users at all — network access control is instead enforced primarily through the app permission and sandboxing model (an app must declare and be granted the INTERNET permission on Android, for instance) rather than port-based firewall rules, reflecting the app-centric rather than service-centric security model of mobile platforms. Enterprise MDM solutions and certain third-party VPN-based apps can implement more traditional firewall-like network filtering on these platforms when needed.

Firewall Rule Design: Default Deny vs. Default Allow

A central design decision in any firewall configuration is the default policy — what happens to traffic that doesn’t match any explicit rule:

Virtually every serious security framework and hardening guide recommends default-deny inbound policy as the baseline, with explicit, narrowly scoped allow rules for exactly the services that genuinely need to be reachable.

Inbound vs. Outbound Filtering

Most discussion of firewalls focuses on inbound filtering — blocking unwanted traffic from reaching a device or network. Outbound filtering (controlling what a device is permitted to send to the outside world) is equally important but far less commonly configured strictly in practice, because it’s operationally harder to get right (legitimate applications need diverse, often unpredictable outbound connectivity) — yet it’s a critical control for containing malware: a compromised device that can’t establish outbound command-and-control connections or exfiltrate data is dramatically less useful to an attacker, even if the initial compromise itself wasn’t prevented.

Firewalls and the Broader Security Stack

A firewall alone doesn’t provide complete protection, and understanding its limitations matters:

A Practical Example: Segmenting a Small Business Network

Internet
   │
[Perimeter Firewall/Router]
   │
   ├── VLAN 10 (Employee workstations) ── outbound internet, blocked from server VLAN except specific ports
   ├── VLAN 20 (Servers)               ── inbound only from workstation VLAN on required app ports
   ├── VLAN 30 (Guest Wi-Fi)           ── outbound internet only, fully isolated from internal VLANs
   └── Host firewalls on every device  ── additional layer, even within "trusted" VLANs

This design uses the perimeter firewall to control internet-facing exposure, internal firewall/router rules to segment trust zones from each other (so a compromised guest device or workstation can’t freely reach the server VLAN), and host-based firewalls on individual machines as a final layer, so that even lateral movement within an allowed VLAN faces additional friction.

Firewalls in Cloud Environments: Security Groups and NACLs

Cloud computing introduced its own take on firewall concepts, worth distinguishing from traditional on-premises firewalls since the terminology and enforcement points differ meaningfully:

This layered cloud model — security groups at the instance level, NACLs at the subnet level, and optionally a managed NGFW at the VPC perimeter — mirrors the same defense-in-depth philosophy as traditional on-premises host-plus-network firewall layering, adapted to a world where “the network” is itself software-defined rather than physical cabling and dedicated hardware appliances.

Web Application Firewalls (WAF): A Specialized Application-Layer Complement

Because traditional firewalls, even sophisticated NGFWs, generally can’t distinguish a legitimate HTTP request from a malicious SQL injection payload riding on the same allowed port 443, Web Application Firewalls exist as a specialized, application-protocol-aware complement, sitting in front of web applications and inspecting HTTP/HTTPS request content specifically for attack patterns — SQL injection syntax, cross-site scripting payloads, path traversal attempts, and known exploit signatures targeting common web frameworks. WAFs are typically deployed as a reverse proxy or a cloud-based service (AWS WAF, Cloudflare, Azure Application Gateway WAF) positioned specifically to inspect and filter application-layer traffic that a traditional network or host firewall would simply pass through as “allowed traffic on an allowed port.” This distinction — network/host firewalls controlling which connections are permitted, WAFs controlling what those permitted connections actually contain — is a useful mental model for understanding why modern web-facing architectures typically deploy both rather than treating either as sufficient on its own.

Best Practices

Summary

A firewall is a network security control that inspects traffic and enforces allow/deny decisions based on configured rules, ranging from simple packet filtering to sophisticated application-aware Next-Generation Firewalls. It relates directly to operating system security because every major OS — Windows, Linux, macOS — ships with a built-in, kernel-integrated host-based firewall (Windows Firewall, Netfilter/iptables/nftables, the macOS Application Firewall/pf), forming a critical layer of defense in depth alongside network-level perimeter firewalls. Mobile platforms take a different, app-permission-centric approach rather than exposing traditional port-based rules. Regardless of implementation, firewalls remain one of the most foundational and consistently recommended security controls precisely because they reduce attack surface at a fundamental level — blocking unwanted network access before it ever reaches a vulnerable service or application.

FAQs

Do I still need a firewall if I have antivirus software? Yes — they address entirely different threat vectors; a firewall controls network access before traffic reaches a vulnerable service, while antivirus detects malicious files and behavior after they’ve already reached the device, and neither substitutes for the other.

What’s the difference between a hardware firewall and a software firewall? A hardware (or network) firewall is typically a dedicated appliance protecting an entire network segment at the perimeter; a software (host-based) firewall runs on an individual device protecting just that device — most well-secured environments use both, layered together.

Why do mobile operating systems not have traditional firewalls? Because their security model is built around app-level sandboxing and explicit permission grants (like Android’s INTERNET permission) rather than the service/port-centric model that traditional desktop and server operating systems use, reflecting a fundamentally different and generally more restrictive default security posture.

Should outbound traffic be filtered too, or just inbound? Ideally both — inbound filtering prevents unwanted external access from reaching internal services, while outbound filtering limits what a compromised device can do (like reaching command-and-control infrastructure or exfiltrating data), even though outbound filtering is operationally more complex to configure without breaking legitimate application functionality.

Can a firewall stop all cyberattacks? No — firewalls are one important layer among many; they don’t protect against application-layer vulnerabilities in traffic they’re configured to allow, insider threats, malware already present on a trusted device, or attacks that don’t cross the network boundary the firewall monitors at all.

References

Exit mobile version