A firewall is a network security system—implemented as software, dedicated hardware, or a cloud service—that monitors and filters incoming and outgoing network traffic based on a predefined set of security rules. It acts as the primary barrier between a trusted internal environment, such as a private server or local network, and untrusted external networks like the public internet. In hosting and DevOps workflows, firewalls prevent unauthorized access, limit the exposed attack surface, and isolate critical infrastructure components.
How it works
Firewalls inspect data packets moving across network boundaries and evaluate them against an ordered list of rules, typically following a default-deny posture where anything not explicitly permitted is dropped. Depending on the architecture, firewalls operate at different layers of the OSI model:
- Packet Filtering: Evaluates individual packets at the network and transport layers based on source and destination IP addresses, protocols, and port numbers without tracking connection history.
- Stateful Inspection: Tracks the state of active network connections, verifying that incoming packets belong to an established, legitimate session before allowing them through.
- Circuit-Level Gateway: Monitors TCP handshakes and session initiation to confirm connection validity without inspecting the actual data payload, keeping resource overhead low.
- Next-Generation Firewalls (NGFW) and Application Firewalls: Operate up to the application layer using Deep Packet Inspection (DPI) to analyze payloads, identify specific applications, and detect threats hidden inside standard protocols like HTTP or DNS.
Beyond perimeter defense, operators use firewalls to create Demilitarized Zones (DMZs) for public-facing web servers and to segment internal networks so attackers cannot easily move laterally if a single host is compromised.
Example
On a Linux virtual private server, administrators frequently use Uncomplicated Firewall (ufw) to manage underlying iptables or nftables rules. A baseline configuration blocks all unsolicited inbound connections, allows outbound traffic, restricts SSH access to a trusted administrative IP address, and permits public web traffic on standard HTTP/HTTPS ports:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 203.0.113.10 to any port 22 proto tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
For a complete walkthrough of baseline rulesets and verification commands, see our UFW Firewall Setup Guide: Hard-Won Data for VPS Security.
What matters when choosing a server or hosting
When evaluating a hosting provider or server setup, look closely at how network filtering is handled at both the infrastructure and operating system levels:
- Edge vs. Host-Based Filtering: Cloud and VPS providers often offer external network firewalls (sometimes called security groups) that drop unwanted traffic before it ever reaches your virtual machine, saving CPU and bandwidth compared to relying solely on an OS-level firewall.
- Stateful Rule Support and Granularity: Ensure the provider's control panel or API supports stateful rules, IP range restrictions, protocol-specific filtering, and custom outbound rules.
- DDoS Mitigation Capacity: Standard host firewalls cannot stop volumetric distributed denial-of-service floods; verify whether upstream network-level filtering is included with your hosting plan.
- Automation and API Access: For modern DevOps pipelines, being able to declare firewall rules as code via Terraform, CLI tools, or REST APIs prevents manual configuration drift across environments.
Common mistakes
- Locking Yourself Out Over SSH: Enabling a default-deny inbound policy before explicitly allowing your current management port immediately severs your remote terminal session.
- Ignoring Outbound (Egress) Traffic: Leaving outbound traffic completely unrestricted makes it easier for compromised applications to download malicious payloads or exfiltrate data.
- Overlooking Docker and Container Bypass Behavior: Container runtimes like Docker often manipulate
iptablesdirectly, unintentionally exposing published container ports to the public internet even when host tools likeufwappear to block them. - Leaving Legacy Ports Open: Failing to block insecure, unencrypted services such as FTP (port 21) or Telnet (port 23) invites automated credential-stuffing and brute-force scans.
To avoid rule conflicts and container networking pitfalls in production, review the Firewall UFW Configuration Guide: Hard-Won Data for Admins.
FAQ
What is the difference between a network firewall and a Web Application Firewall (WAF)?
A traditional network firewall filters traffic based on IP addresses, ports, and protocols at the network and transport layers. A WAF inspects HTTP and HTTPS traffic at the application layer to block web-specific attacks such as SQL injection, cross-site scripting (XSS), and malicious bot requests.
Should I use both a cloud provider firewall and an OS-level firewall?
Using both provides defense in depth, as the cloud firewall stops unwanted traffic at the network edge while the host firewall protects against lateral traffic on private interfaces. However, you must keep rules synchronized so troubleshooting connection issues does not become overly complex.
Why is a firewall still necessary if my server only runs HTTPS?
Even if you intend to serve only HTTPS traffic, operating systems and background services often bind to other ports for administration, databases, or internal metrics. A firewall ensures those auxiliary ports remain unreachable from the public internet.