UFW Command Reference
Published: 02 November 2024
Please note that for anything you may need to change (port number, IP address,
etc), the
contenteditable
attribute has been added. You may click on this content and edit it as if it
were a text box, while retaining highlight & copy functionalities.
Basic Commands
- Enable UFW:
sudo ufw enable - Disable UFW:
sudo ufw disable - Reset UFW (removes all rules):
sudo ufw reset - Check UFW status (and list rules):
sudo ufw status - List UFW rules (numbered)
sudo ufw status numbered - List app profiles:
sudo ufw app list
Default behavior
By default, UFW is set to deny all incoming and allow all outgoing traffic. This is a good starting point
for most users.
To change this, you can use the following commands:
-
Deny all incoming traffic:
sudo ufw default deny incoming -
Allow all outgoing traffic:
sudo ufw default allow outgoing
Allowing Traffic on a specific port
-
Allow traffic on a specific port:
sudo ufw allow 22 -
Allow from a program profile:
sudo ufw allow ssh -
Allow a range of ports:
sudo ufw allow 6000:6007/tcp
Filter by protocol
-
Allow traffic on a specific port and protocol:
sudo ufw allow 22/tcp -
Allow traffic on a specific port and protocol:
sudo ufw allow 22/udp
Deleting Rules
-
Delete a rule by number:
sudo ufw delete 1 -
Delete a rule by specifying it:
sudo ufw delete allow 22
Logging
-
Enable logging:
sudo ufw logging on -
Disable logging:
sudo ufw logging off
Block an interface
-
Block an interface:
sudo ufw deny in on eth0
Block an IP address
-
Block an IP address:
sudo ufw deny from 1.234.31.117
Command with (most) UFW elements included
-
Allow traffic on a port & protocol from an IP address on eth0:
sudo ufw allow 22/tcp from 203.0.113.102 on eth0