How to use UFW to manage your firewall

This guide will teach you how to use UFW on Ubuntu to manage your firewall and block or unblock certain ports.

First, install UFW with sudo apt install ufw. If UFW is already installed, you can skip this step.

Next, we need to enable UFW. First we need to make sure that we won't get disconnected from SSH. Type sudo ufw allow ssh then sudo ufw enable. This allows the SSH port and enables the firewall.

Once UFW firewall is enabled, you can unblock (open) a port with sudo ufw allow <port>. Example, to allow the HTTPS port you would use sudo ufw allow 443.

To block (close) a port, you can use sudo ufw deny <port>. To block traffic from incoming on port 50, you would use sudo ufw deny 50.

Last updated