Before enabling ufw, be sure to add appropriate rules to allow remote access
to necessary services such as SSH, HTTP/S, and any other required service.
Installation and simple ufw commands
- Install ufw (if it’s not already installed):
sudo apt-get install ufw - Enable ufw:
sudo ufw enable - Configure default policies: By default, ufw allows all outgoing traffic and denies all incoming traffic. You can change these policies by typing:
sudo ufw default allow outgoingto allow all outgoing traffic.sudo ufw default deny incomingto deny all incoming traffic.
- Add rules for incoming traffic:
sudo ufw allow <port>to allow incoming traffic on a specific port, for example:sudo ufw allow 80/tcpto allow incoming HTTP traffic.sudo ufw allow from <IP address>to allow incoming traffic from a specific IP address.sudo ufw allow from <IP address> to any port <port>to allow incoming traffic from a specific IP address on a specific port.
- Delete rules:
sudo ufw delete <rule>to delete a specific rule. For example, sudo ufw delete allow 80/tcp to delete a rule that allows incoming HTTP traffic.
- See the status of ufw:
sudo ufw statusto see the firewall status and enabled rules.
- Disable ufw:
sudo ufw disableto disable the firewall.