What Is a Firewall?

Category: Security & SSL ยท Updated 2026-11-04

A firewall is a system that filters network traffic in and out of a server according to a set of rules, typically based on port number, protocol and source or destination address. On a hosting server it is normally configured to allow expected traffic, such as web traffic on ports 80 and 443, while blocking everything else by default, reducing the number of services an attacker can even attempt to reach.

What a firewall filters and how

A firewall inspects network packets arriving at or leaving a server and compares them against an ordered list of rules. A typical rule matches on some combination of protocol (TCP or UDP), port number, and source or destination IP address, then either allows or drops the packet. Most hosting setups follow a "default deny" approach: explicitly allow the specific ports a service needs, and block everything else automatically, rather than trying to list every bad thing to block.

Network firewalls vs. host-based firewalls

TypeWhere it runsExample
Network firewallAt the edge of a network, in front of multiple serversA hardware appliance or a cloud provider's security group
Host-based firewallOn the server itself, filtering its own trafficiptables, nftables, ufw on Linux; Windows Defender Firewall
Web application firewall (WAF)Inspects HTTP request content, not just portsA separate layer that filters malicious requests like SQL injection attempts

Many hosting environments use more than one layer at once: a provider-level network firewall, a host-based firewall on the server itself, and sometimes a WAF in front of the web application, each filtering a different kind of traffic.

A typical rule set for a web server

A simple, common firewall setup for a server running a website looks like this, written for the ufw tool on Linux:

ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

This allows SSH, plain HTTP and HTTPS, and silently drops everything else arriving from outside. A more cautious setup also restricts port 22 to a specific administrator IP address or disables password login entirely in favor of SSH keys.

What a firewall does not protect against

  • Attacks inside allowed traffic: if port 443 is open, a firewall alone does not stop malicious input sent over that legitimate connection, such as SQL injection or a vulnerable plugin being exploited; that needs application-level security or a WAF.
  • Large-scale DDoS traffic: a firewall can drop unwanted packets, but a flood large enough can still exhaust a server's bandwidth or connection capacity before the firewall's rules even matter; that typically needs dedicated DDoS mitigation upstream.
  • Compromised credentials: a firewall does not stop someone logging in with a stolen password through a port it was told to allow.

Frequently asked questions

What does a firewall actually do?

It filters network traffic according to rules, typically allowing or blocking connections based on port number, protocol and source address, so only expected traffic reaches a server's services.

Does my hosting provider already have a firewall, or do I need my own?

Many providers run a network-level firewall or security groups in front of their servers, but it is still common practice to also run a host-based firewall on the server itself for an extra, independently managed layer.

What is the difference between a firewall and a WAF?

A standard firewall filters traffic mainly by port, protocol and IP address without looking at the content of a web request. A web application firewall inspects the actual HTTP request content to catch attacks like SQL injection that would otherwise pass straight through an open port.

Can a firewall stop a DDoS attack?

A firewall can drop some unwanted traffic, but a sufficiently large flood of traffic can still overwhelm a server's bandwidth or connections before firewall rules help much, which is why serious DDoS protection typically happens further upstream.

Which ports does a typical web server firewall need open?

Commonly 80 and 443 for web traffic, plus 22 for SSH administration, often restricted to specific trusted IP addresses. Any other port should stay closed unless a specific service actually needs it.

Is a firewall the same as antivirus software?

No. A firewall filters network connections based on rules like port and address; antivirus software scans files and running processes for known malicious code. They address different parts of a server's security and are commonly used together.

Related topics