Skip to main content
Networking Commands

UFW Firewall Command in Linux: 6 Practical Examples

In this article, use the ufw command to set default firewall policies, allow SSH, open ports, restrict IP addresses, manage rule order, and delete firewall rules on a Linux server.

β€” Ravi Saive

Every Linux server connected to a network is exposed to constant connection attempts, most of them automated scans looking for open SSH, database, or web ports.

If you do not control which ports accept traffic, any service you install, even one meant only for local use, can end up reachable from the outside world.

UFW (Uncomplicated Firewall) is a command-line frontend that makes managing firewall rules much simpler. Under the hood, the Linux kernel filters packets with netfilter, while UFW manages the underlying iptables or nftables rules for you.

This lets you use commands such as ufw allow 80/tcp instead of building long firewall chains by hand.

UFW ships with Ubuntu and is popular on Debian-based servers, although it can also be installed on other Linux distributions.

In this guide, we will walk through six practical examples covering the firewall tasks you are most likely to perform on a real server.

Prerequisites

Before you start, make sure you have the following:

  • A Linux server running Ubuntu, Debian, Fedora, or a RHEL-based distribution.
  • A user account with sudo privileges.
  • Console access, such as a VPS web console or physical access, in case a firewall rule locks you out of SSH. This provides a safety net while you test and modify firewall rules.

Install UFW in Linux

Updated on Sep 24, 2026