Network

The ufw command

Ubuntu's simple firewall. Enables protection and decides which ports are allowed or blocked.

Syntax

sudo ufw status | sudo ufw enable | sudo ufw allow PUERTO

Most useful options

statusShows whether it is active and the rules
enableEnables the firewall
allowAllows a port or service
denyBlocks a port or service

Copy-ready examples

$ sudo ufw statusFirewall status
$ sudo ufw allow 22 && sudo ufw status verboseAllow SSH

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • When enabling it over an open SSH connection, allow port 22 first or you will lock yourself out.

Related commands

FAQ

Does ufw replace iptables?

No: ufw is an easy layer on top of iptables.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course