guides-resources

Firewall: Meaning, Types, How It Works, and Basic Rules

Firewall: Meaning, Types, How It Works, and Basic Rules

Firewall: what it is, meaning, how it works, what it does, types (stateful, NGFW, WAF), basic rules, ufw and Windows commands and how a pentester sees it with Nmap.

  • Posted on 2026-10-11
  • Reading time: 7 min

Firewall: What It Is, How It Protects a Network, and How to Configure It #

A firewall is a security system that monitors incoming and outgoing network traffic and decides what to allow and what to block based on predefined rules . It can be a physical device, computer software, or a cloud service. Its job is to filter networks with different levels of trust, such as between the Internet and a corporate network.

It's one of the basic tools of cybersecurity, but it's not complete protection: it doesn't stop phishing, it doesn't detect insiders, and if it's misconfigured or out of date, it can itself become an entry point.

Firewall meaning: what it means and why it's called that #

Firewall literally means "firewall" : in construction, it's the wall that prevents a fire from spreading from one area to another. In IT, it has the same function: if one part of the network is compromised, the firewall limits the spread of damage to the other areas.

Simple example: In a company, the firewall allows employees to surf the web and connect to internal servers, but blocks anyone from the Internet from trying to connect directly to the customer database.

What is a firewall for? #

A firewall is used to:

  • block unauthorized access from outside to internal services;
  • reduce the attack surface, exposing only what needs to be reachable;
  • limit movements within the network between different zones (users, servers, guests);
  • control outgoing traffic, to prevent malware, data exfiltration, and communications with command and control servers;
  • log connection attempts, useful for detecting scans and attacks.

Firewall for home and business #

At home, the firewall is usually already integrated into the router and the operating system: it should be left enabled and ports forwarded to the Internet should be avoided unnecessarily. A company needs a network firewall at the perimeter (often an NGFW), host-based firewalls on servers, zone segmentation, and a process for managing and reviewing rules.

How a firewall works #

The firewall examines each network packet and compares it to a list of rules. Each rule essentially says: if the traffic meets these characteristics, then allow or block . The most commonly used characteristics are:

  • IP address of origin and destination;
  • port e protocol (TCP, UDP, ICMP);
  • direction: incoming (inbound) or outgoing (outbound);
  • in the most advanced devices, application, user e content.

Two fundamental principles:

  1. The rules are read from top to bottom: In most firewalls, the first rule that matches the traffic applies.
  2. Default denyIf no rules allow traffic, it's blocked. This is the most secure configuration: it blocks everything and only opens what's needed.

A typical rule might look like this: Allow TCP to 203.0.113.10 on port 443 from any source . To understand what ports and protocols mean, see the TCP and UDP port guide in pentest.

Types of Firewalls #

TypeWhat are you looking at?Feature
Packet filteringIP, port, protocol of each single packetFast and simple, but doesn't know which connection a packet belongs to
Stateful inspectionAs above, plus the connection statusAllows responses only to internally initiated connections. This is the basic standard today.
Proxy / application gatewayThe content of a specific protocol (application layer)It acts as an intermediary: the connection is not direct. More control, slower.
Next Generation Firewall (NGFW)Applications, users, content, often even encrypted trafficCombines firewall, IPS, application filtering, and threat intelligence

Stateful vs. stateless #

Stateless (pure packet filtering)stateful
What do you evaluate?Each package aloneThe packet and the state of the connection it belongs to
Internal traffic responsesThey must be explicitly authorizedThey are automatically recognized and allowed
TodayRare as the only defenseThe basic standard of almost every modern firewall

By position and shape #

  • Network firewall (hardware or virtual): protects an entire network, usually at the perimeter.
  • Host-based firewall: runs on a single computer or server (Windows Defender Firewall, ufw, nftables).
  • Cloud Firewall: filters like security group o firewall as a service, which protect resources in the cloud.

Firewall vs. WAF: What's the Difference? #

They're both firewalls, but they look at different things. A traditional network firewall filters based on IP, port, and protocol: it doesn't understand the content of an HTTP request. A WAF ( Web Application Firewall ), on the other hand, works at the application level, analyzing HTTP/HTTPS traffic to a website or app and recognizing attack patterns like SQL injection or XSS . In practice, the network firewall decides who can knock on the door, while the WAF checks what's written in the request once it's in.

Many web applications use both: network firewalls at the perimeter and WAFs in front of the application.

Firewall, Antivirus, IDS/IPS, and VPN: The Differences #

These tools get confused all the time, but they do different things:

ToolWhat does he do
FirewallFilter network traffic based on rules
Antivirus / EDRDetect and block malware and suspicious behavior on the device
IDSDetect suspicious traffic and warns
IPSDetect suspicious traffic and block
WAFIt specifically protects the web applications
VPNCreates an encrypted channel between two points: no filtering, protects transit

They work together: the firewall restricts what can get in, the EDR protects devices, the IDS/IPS observes traffic, the VPN secures remote connections.

Firewall, NAT and port forwarding #

You often hear about "port mapping" on your firewall. This involves NAT and port forwarding : the router or firewall forwards traffic arriving on a public port to an internal device (for example, port 443 for a web server).

Warning: NAT is not a firewall . It hides internal addresses but does not filter for security. Every port forwarded to the Internet is an exposed service: a server with RDP open on port 3389 is a classic target. Before opening a port, ask yourself if it's really needed, who needs it, and whether it can be supported by a VPN.

Firewall Configuration: Rules, Default Deny, and Best Practices #

Default deny vs. default allow #

PolicyBehavior
Default denyBlocks everything that isn't explicitly allowed. More secure: This is the recommended standard.
Default allowIt allows everything that isn't explicitly blocked. More convenient, much riskier.

Principles that apply to any product:

  1. Block all by default (default deny), then open only what is necessary.
  2. Minimum privilege: rules as specific as possible (exact IP, port and protocol) instead of “any-any”.
  3. It also filters outgoing traffic (egress): a compromised machine must be able to contact only what it needs to.
  4. Segment the network: separates servers, users, guests and IoT devices into different zones, with a DMZ for the services displayed.
  5. Secure the admin interface: don't expose it on the Internet, use MFA, strong credentials and dedicated logins.
  6. Update the firmware: Firewalls are targets for attackers.
  7. Record logs and bring them into a monitoring system.
  8. Review the rules every so many months: over time, temporary, obsolete, or overly permissive rules remain.
  9. Back up your configuration.

base command #

On Linux with ufw , a minimal configuration:

bash
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status verbose

To see the actual low-level rules:

bash
sudo nft list ruleset
sudo iptables -L -n -v

On Windows (PowerShell), profile status and active inbound rules:

powershell
Get-NetFirewallProfile | Select-Object Name, Enabled
Get-NetFirewallRule -Direction Inbound -Action Allow -Enabled True | Select-Object DisplayName, Profile

The second line is a good starting point for finding input rules you didn't remember creating.

Firewall in penetration testing #

In penetration testing, the firewall is one of the first obstacles to understand. Nmap distinguishes three states: open port , closed (the system responds that nothing is present), and filtered (no response or rejection: likely presence of a firewall).

Only on your own systems, those of a lab, or with written authorization. If the host doesn't respond to the ping, skip the host discovery phase.

bash
nmap -Pn -p 1-1000 <IP-autorizzato>

To understand if a firewall is stateful and which ports it allows through, you can use ACK scanning:

bash
nmap -sA <IP-autorizzato>

A door unfiltered with ACK it means that the packets reach it (not filtered by stateful rules); filtered This means Nmap can't determine if the port is open because a network filter is blocking probes from reaching it or responses from returning. This doesn't necessarily mean a firewall is present, but it's the most common sign of one.

On the attacker 's side, outbound filtering is often crucial: a reverse shell must exit the network anyway, and a firewall that blocks unnecessary traffic makes a technique like Chisel or pivoting more difficult or noisy . A firewall with "anything goes" outbound rules makes life easier for those already inside.

Common configuration errors #

ErrorRisk
“Any any” or too broad rulesThe firewall lets through more than necessary
No output filterMalware and reverse shells communicate freely
Management interface exposed on the InternetDirect access to the heart of the firewall
Default or no MFA credentialsTaking control of the device
Firmware not updatedKnown exploitable vulnerabilities
Temporary rules never removedOpen doors forgotten
No logs or anyone reading themAn intrusion goes unnoticed
Flat network without segmentationA compromised machine achieves everything

The Limits of the Firewall: When It's Not Enough #

A firewall does not protect against:

  • phishing and social engineering: a user who hands over credentials is not stopped by network rules;
  • malicious encrypted traffic, if there is no TLS inspection;
  • internal threats: an employee already within the network;
  • vulnerability of the firewall itself.

This last point is true. Firewalls and other edge devices are frequent targets of zero-days : in 2024, for example, a command injection vulnerability in the GlobalProtect component of Palo Alto PAN-OS (CVE-2024-3400) was actively exploited before being patched. According to Google Threat Intelligence, in 2025, nearly half of the exploited zero-days involved enterprise technologies, often edge devices without EDR. A firewall should therefore be treated as a system to be monitored and updated, not as a box to be installed and forgotten.

If an attacker gets past the perimeter, the damage becomes a data breach , with notification obligations under the GDPR and, for the subjects involved, the NIS 2 directive , which requires adequate network security measures.

Firewall FAQs #

What is a network firewall? #

A firewall that protects an entire network, usually placed at the perimeter between the internal network and the Internet, as opposed to a host-based firewall that protects a single device.

What is a stateful firewall? #

A firewall that evaluates not just the individual packet but the state of the connection to which it belongs, automatically recognizing responses to traffic initiated from within. This is standard on most modern firewalls.

What is the difference between stateful and stateless firewalls? #

Stateless evaluates each packet in isolation; stateful keeps track of active connections and automatically allows legitimate responses, with simpler and more secure rules.

Which ports should a firewall have open? #

There's no universal list: it depends on the services the system needs to offer. The rule is to open only the ports for the necessary services and block everything else (default deny).

What is a firewall? #

A system that filters incoming and outgoing network traffic based on rules, allowing or blocking connections. It can be hardware, software, or cloud-based.

What does firewall mean? #

Literally “firewall”: like a wall that prevents a fire from spreading, the firewall limits the spread of an attack between different networks.

How does a firewall work? #

It compares each packet against a list of rules (IP, port, protocol, direction, sometimes application, and user) and decides whether to allow or block it. With the default deny option, anything not explicitly allowed is blocked.

What are the types of firewalls? #

Packet filtering, stateful inspection, proxy or application gateway, next-generation firewall (NGFW), and WAF for web applications. They can be network-based, host-based, or cloud-based.

What is the difference between a firewall and an antivirus? #

The firewall filters network traffic; the antivirus or EDR detects malware and suspicious behavior on the device. They complement each other.

What is a WAF? #

A Web Application Firewall protects web applications from HTTP/HTTPS attacks such as SQL injection and XSS. It is different from a traditional network firewall.

Is a firewall enough to be protected? #

No. It doesn't stop phishing, insider threats, and malicious encrypted traffic without inspection, and it may have vulnerabilities. It's useful in conjunction with updates, MFA, EDR, segmentation, and monitoring.

Is NAT a firewall? #

No. NAT translates addresses and can hide the internal network, but it's not designed for secure filtering. Port forwarding, in fact, exposes services to the Internet.

What is default deny? #

A policy whereby any traffic not explicitly permitted is blocked. This is the basis of a secure configuration.

What does filtered port mean in Nmap? #

That Nmap can't determine if the port is open because something, usually a firewall, is dropping or rejecting the packets.

#Firewall #NetworkFirewall #NetworkSecurity #WAF #NGFW

leave a message

I'm not a robot