Skip to content

Install & Configure UFW

This post explains how to install & configure UFW Firewall on Debian or Ubuntu and which commands are useful.

Installation

  1. Update packages and install UFW
sh
sudo apt update
sudo apt install ufw
  1. Check UFW service status
sh
sudo ufw status
  1. Set default rules
sh
sudo ufw default deny incoming
sudo ufw default allow outgoing

This blocks everything coming in and allows everything going out.

  1. Allow ssh connections
sh
sudo ufw allow ssh

Without this after UFW is active you will be locked out!

  1. Enable UFW
sh
sudo ufw enable

Usefull Commands

Enable UFW

sh
sudo ufw enable

Disable UFW

sh
sudo ufw disable

Reload Rules

sh
sudo ufw reload

Show status and rules (numbered)

sh
sudo ufw status numbered

Delete a Rule

sh
sudo ufw delete <number>