UFW program for managing a netfilter firewall.
To install ufw
sudo apt install ufw
systemctl status ufw
First, check ufw status
ufw status
----
Status: inactive
Let set the default policy
# allow all outgoing and deny all incoming request
sudo ufw default deny incoming
sudo ufw default allow outgoing
After that we can enable ufw, but remember that we still have accessed to the server directly, if you connect to server via ssh you need to set the rule to allow incoming traffic via ssh first before enable the ufw
# allow ssh(port 22)
sudo ufw allow ssh # or sudo ufw allow 22
sudo ufw enable
To check default policy
sudo ufw status verbose
-------
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), deny (routed)
New profiles: skip
To delete the rule
sudo ufw delete allow ssh # or sudo ufw delete allow 22
To allow traffic from a specific IP
sudo ufw allow from <ip> to any port 22
#80 http
#443 https
#22 ssh
To check existed rule
sudo ufw status
To delete a specific rule
sudo ufw status numbered
Status: active
To Action From
-- ------ ----
[1] 22/tcp ALLOW Anywhere
[2] 22/tcp (v6) ALLOW Anywhere (v6)
---------
sudo ufw delete <rule id> #eg: 1
To disable the firewall
sudo ufw disable
To see the manual, type man ufw
Leave a comment if you have any questions.
===========
Please keep in touch
Portfolio
Linkedin
Github
Youtube