UFW(Uncomplicated Firewall)
Cheulong Sear

Cheulong Sear @cheulong

About: Hi, I’m Cheulong Sear. Love learning new staff. I will show my journey in the IT field and what I'm building during my free time.

Location:
Bangkok, Thailand
Joined:
Jun 30, 2024

UFW(Uncomplicated Firewall)

Publish Date: Jun 29
1 0

UFW program for managing a netfilter firewall.

To install ufw

sudo apt install ufw
systemctl status ufw
Enter fullscreen mode Exit fullscreen mode

First, check ufw status

ufw status

----
Status: inactive
Enter fullscreen mode Exit fullscreen mode

Let set the default policy

# allow all outgoing and deny all incoming request

sudo ufw default deny incoming
sudo ufw default allow outgoing
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To check default policy

sudo ufw status verbose

-------
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), deny (routed)
New profiles: skip
Enter fullscreen mode Exit fullscreen mode

To delete the rule

sudo ufw delete allow ssh # or sudo ufw delete allow 22
Enter fullscreen mode Exit fullscreen mode

To allow traffic from a specific IP

sudo ufw allow from <ip> to any port 22

#80 http
#443 https
#22 ssh
Enter fullscreen mode Exit fullscreen mode

To check existed rule

sudo ufw status
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

To disable the firewall

sudo ufw disable
Enter fullscreen mode Exit fullscreen mode

To see the manual, type man ufw

(back to top)

Leave a comment if you have any questions.

===========
Please keep in touch
Portfolio
Linkedin
Github
Youtube

Comments 0 total

    Add comment