Ubuntu Firewall: Essential List of Rules

Ubuntu, a popular Linux distribution, comes with a built-in firewall called Ufw (Uncomplicated Firewall) that simplifies the process of managing your system's network security. Understanding how to manage Ufw rules is crucial for securing your Ubuntu system. This article will guide you through creating, listing, and managing firewall rules using Ufw.

Home Network Firewall Rules: Minimal Allow/Block List That Still Works
Home Network Firewall Rules: Minimal Allow/Block List That Still Works

Before delving into the rules, let's ensure Ufw is active. You can check its status and enable it if necessary with the following commands:

How to disable the firewall on Ubuntu
How to disable the firewall on Ubuntu

Understanding Ufw Rules

Ufw rules are defined by a set of parameters, including action (allow or deny), protocol (tcp, udp, or any), and port number or range. Understanding these parameters is key to creating effective firewall rules.

an image of a computer screen with the text'open source'in green and purple
an image of a computer screen with the text'open source'in green and purple

By default, Ufw allows established connections and denies incoming traffic. Custom rules supplement this default behavior, allowing or denying specific traffic based on your needs.

Listing Ufw Rules

Linux Firewall Explained: How iptables, firewalld & UFW Secure Your System!
Linux Firewall Explained: How iptables, firewalld & UFW Secure Your System!

To list all active Ufw rules, use the following command:

sudo ufw status verbose

This command displays a list of rules, their status (enabled or disabled), and other relevant information. To list rules in a more compact format, use:

sudo ufw status

Understanding Rule Syntax

Easily check the status of the firewall on Ubuntu
Easily check the status of the firewall on Ubuntu

Ufw rules follow a specific syntax. Here's a breakdown of the basic syntax:

sudo ufw allow|deny protocol port-range|port[:in|out]

For example, to allow incoming SSH connections (which use port 22 by default), you would use:

sudo ufw allow ssh

Or, to deny incoming traffic on port 22:

the ubunt chat sheet is shown in orange and white, with text on it
the ubunt chat sheet is shown in orange and white, with text on it

sudo ufw deny 22

You can also specify the protocol explicitly, like so:

sudo ufw allow tcp 22

Managing Ufw Rules

Advanced Firewall Configurations with ipset
Advanced Firewall Configurations with ipset
the ubuntu chat sheet is shown in orange and black, with text
the ubuntu chat sheet is shown in orange and black, with text
the top 50 linux commands you must know info for beginners to use in windows
the top 50 linux commands you must know info for beginners to use in windows
an image of a computer screen with the words linux permisions on it and other information
an image of a computer screen with the words linux permisions on it and other information
the linux patch checklist is shown in black
the linux patch checklist is shown in black
the linux commands for devops poster
the linux commands for devops poster
How to list users on Ubuntu
How to list users on Ubuntu
an info sheet describing how to use linux commands
an info sheet describing how to use linux commands
the linux command line is shown in this manual
the linux command line is shown in this manual
the router and firewall diagram is shown in red, white, and blue
the router and firewall diagram is shown in red, white, and blue
the linux command commands are displayed in this poster
the linux command commands are displayed in this poster
Essential Basic Linux Commands You Should Know
Essential Basic Linux Commands You Should Know
the linux command commands list is shown in this screenshote, which shows how to use
the linux command commands list is shown in this screenshote, which shows how to use
Different Linux Distributions Explained (Beginner Guide)🚀
Different Linux Distributions Explained (Beginner Guide)🚀
Ubuntu: A Beginner's Guide
Ubuntu: A Beginner's Guide
Linux Commands Cheat Sheet
Linux Commands Cheat Sheet
Linux Commands Cheat Sheet for Beginners 2026
Linux Commands Cheat Sheet for Beginners 2026
Free Up Disk Space in Ubuntu
Free Up Disk Space in Ubuntu
Linux Terminal Cheat Sheet
Linux Terminal Cheat Sheet
Ubuntu Command Line Wallpaper For Newbie
Ubuntu Command Line Wallpaper For Newbie

Ufw provides several commands for managing rules. Here are some of the most common:

Deleting Rules

To delete a rule, use the `delete` command followed by the rule number. First, list the rules to find the number of the rule you want to delete:

sudo ufw status verbose

Then, delete the rule using its number:

sudo ufw delete <rule-number>

Enabling and Disabling Rules

To enable or disable a rule, use the `enable` or `disable` command followed by the rule number:

sudo ufw enable <rule-number>
sudo ufw disable <rule-number>

Deleting All Rules

To delete all rules at once, use the `reset` command:

sudo ufw reset

This command removes all user-defined rules and resets Ufw to its default settings.

In the dynamic world of network security, it's essential to stay informed and proactive. Regularly review and update your Ufw rules to ensure your Ubuntu system remains secure. Happy firewall managing!