UFW Install and Config (APT)

Hello! Today I will be teaching you how to install and configure UFW on Debian or Ubuntu based machines. I hope that some of you find this helpful!

Prerequisites: You will need a root account and/or an account with sudo access. You also will need a machine using the apt package manager (Ubuntu, Debian.)

Installing UFW

For most machines UFW is insalled by default, however if this is not the case. You can install with

sudo apt install ufw

Allowing IPV6 Configuration

In most versions, IPV6 is enabled by default. If it is not however, you can edit the UFW config file to enable it.

sudo nano /etc/default/ufw

And change the value


Setting Default Policies

By default UFW blocks all incoming traffic and allows all outgoing. To set custom policies for applications. For this tutorial we will mostly just deny all traffic to begin with.

sudo ufw deny incoming

sudo ufw deny outgoing

Allowing SSH Connections *Optional

If you want some applications to network, or you use SSH you can enable the OpenSSH profile through UFW by typing

sudo ufw allow openssh


sudo ufw allow ssh

Turning on UFW

You can now start the UFW service by typing the following command

sudo ufw enable

The firewall is now enabled and following our instructions.

Opening/Allowing Applications and Ports Through Firewall

If you want to use a browser like firefox or need to use a certain port you can use this syntax

sudo ufw allow http

sudo ufw allow https

sudo ufw allow [port number]

Allowing Specific IP Addresses

If you have a specific computer that you want to connect to, you can let it through the firewall through

sudo ufw allow from [IP address]

or for a certain port

sudo ufw allow from [IP address]/[port]

Denying connections

You can deny certain services or users with

sudo ufw deny [service]

Deleting Rules

If you want to remove one of your previous rules you can do that with

sudo ufw status numbered

to display all rules

sudo ufw delete [rule number]


I hope that you enjoyed this short guide of UFW. If you want me to add anything, please comment down below! :slight_smile:


1 Like