Firewall (UFW) Basics and Configuration on Ubuntu
- Get link
- X
- Other Apps
Firewall (UFW) Basics and Configuration on Ubuntu
When using Linux or Ubuntu systems, you will frequently encounter the term firewall.
A firewall is a core component of system security and plays an important role not only on servers but also on personal computers connected to a network.
Ubuntu provides UFW (Uncomplicated Firewall) as a built-in tool that allows users to configure firewall rules easily.
1. What Is a Firewall?
A firewall is a system that controls network traffic.
It examines incoming and outgoing data packets and decides whether they should be allowed or blocked based on predefined rules.
The main purposes of a firewall are:
-
Allow only approved network communication
-
Block unnecessary or suspicious access
-
Control the network exposure of the system
In simple terms, a firewall acts as a gatekeeper for network traffic.
2. Why a Firewall Is Important
Once an operating system is connected to a network, it becomes visible to external requests.
This is especially true for servers, which are designed to accept connections from other systems.
Using a firewall helps:
-
Block unused ports
-
Limit access to essential services only
-
Clarify network communication paths
-
Improve system predictability and control
Rather than being only about protection, a firewall helps keep the system organized and manageable.
3. What Is UFW?
UFW stands for Uncomplicated Firewall.
It is a firewall management tool developed to simplify network filtering on Ubuntu systems.
Internally, UFW uses the Linux kernel’s netfilter (iptables) framework.
However, UFW hides the complexity of low-level rule management and provides an easy-to-use command-line interface.
Key characteristics of UFW include:
-
Simple and readable commands
-
Easy rule management
-
Strong integration with Ubuntu
-
Suitable for both server and desktop environments
4. How UFW Works by Default
UFW follows a simple default policy:
-
Incoming traffic: denied
-
Outgoing traffic: allowed
This default behavior makes sense for most systems.
Only services that are explicitly allowed can receive external connections, reducing unnecessary exposure.
5. Checking UFW Installation
On most Ubuntu installations, UFW is installed by default.
You can check its status using the following command:
sudo ufw status
If UFW is not installed, it can be installed through the package manager.
![]() |
| ufw status |
6. Enabling and Disabling UFW
6.1 Enabling the Firewall
sudo ufw enable
Once enabled, UFW begins enforcing the configured firewall rules.
![]() |
| ufw enable |
![]() |
| ufw status verbose |
6.2 Disabling the Firewall
sudo ufw disable
Disabling UFW stops all firewall filtering temporarily.
7. Checking Firewall Status
To view the current firewall status and active rules:
sudo ufw status
For more detailed information:
sudo ufw status verbose
This output displays whether the firewall is active and shows the default policies.
8. Understanding Ports and Firewall Rules
Network communication uses ports as endpoints.
Each service listens on specific ports, and firewalls use these ports to control access.
For example:
-
Allowing a port enables access to a service
-
Blocking a port prevents external connections
UFW makes port-based filtering straightforward.
9. Allowing Specific Ports
To allow traffic on a specific port:
sudo ufw allow 22
This rule permits connections to that port.
![]() |
| ufw allow 22 |
![]() |
| sudo ufw ststus verbose |
10. Using Service Names
UFW also allows rules to be defined using service names instead of port numbers.
sudo ufw allow ssh
This approach is easier to read and automatically applies the correct port settings.
11. Removing Firewall Rules
If a rule is no longer needed, it can be removed.
sudo ufw delete allow 22
Rule management helps keep the firewall configuration clean and understandable.
![]() |
| ufw delete allow 22 |
12. Considerations When Configuring a Firewall
A firewall is not about blocking everything.
The goal is to allow only what is necessary and block everything else.
Important considerations include:
-
Understanding which services are actually used
-
Avoiding unnecessary open ports
-
Being aware of the impact of rule changes
This mindset supports stable and predictable system behavior.
13. Learning Benefits of Using UFW
Configuring a firewall with UFW is a valuable learning experience.
It helps users understand:
-
The relationship between ports and services
-
How network traffic flows through a system
-
How server access is structured
These concepts are essential for anyone learning Linux system administration.
14. Summary
A firewall is a fundamental part of network control in Linux systems, and UFW provides a simple way to manage it on Ubuntu.
-
It simplifies complex firewall concepts
-
It works well for both desktop and server environments
-
It helps clarify how network access is controlled






