• Wed. May 22nd, 2024

Scorebigwinners

Fuel Your Curiosity.

Basic UFW Firewall Configuration on Ubuntu 24.04 – Easy Steps

ByAdministrator

May 21, 2024

This guide intends to teach you a Basic UFW Firewall Configuration on Ubuntu 24.04. UFW (Uncomplicated Firewall) is a user-friendly tool for managing firewall rules in Ubuntu. It is designed to be a simple firewall configuration. It is more accessible and easy to use for users rather than iptables.

Here are some key Features of the UFW Firewall:

Simplicity: UFW provides an easy-to-use interface for managing firewall rules.Default Deny Policy: By default, UFW denies all incoming connections and allows all outgoing connections.Predefined Profiles: UFW includes predefined application profiles for common services like SSH, HTTP, and HTTPS.Logging: UFW supports logging, enabling users to monitor and record firewall activity.IPv4 and IPv6 Support: UFW supports both IPv4 and IPv6.

UFW firewall is a great option for those who need to perform basic firewall rules rather than using comprehensive iptables rules. It provides an easy way to increase the security of your Ubuntu OS by controlling incoming and outgoing traffic.

Now you can proceed to the following steps to start setting up a firewall with UFW on Ubuntu 2404.

Learn Basic UFW Firewall Configuration on Ubuntu 24.04

At this point, you need to log in to your system as a root or non-root user with sudo privileges. Then, follow the steps below to start Basic UFW Firewall Configuration on Ubuntu 24.04.

Step 1 – Enable UFW on Ubuntu 24.04

First, you must open your terminal and run the system update with the following command:

sudo apt update

By default, UFW is installed on Ubuntu 24.04. If you don’t have it, you can use the following command to install UFW:

sudo apt install ufw

Then, check your UFW status on Ubuntu 24.04 with the following command:

sudo ufw status

You should see that, your UFW status is inactive:

Example Output
status: inactive

To enable the UFW firewall, you can easily run the command below:

sudo ufw enable

Next, verify your UFW status again, and in your output, you must see the active status:

Example Output
status: active

Now proceed to the next step to learn Basic UFW Firewall Configuration on Ubuntu 24.04.

Step 2 – Allow Connections Through UFW Firewall on Ubuntu 24.04

At this step of Basic UFW Firewall Configuration on Ubuntu 24.04, you will learn to allow traffic through your UFW firewall.

Allow a specific service: To allow a predefined service like SSH, OpenSSH, HTTP, etc, you can use the following syntax:

sudo ufw allow service-name

For example, to allow SSH, you can easily run the following command:

sudo ufw allow ssh

Allow TCP and UDP Ports: Also, you can easily allow TCP and UDP ports through your UFW firewall by using the following syntax:

sudo ufw allow port/tcp-or-udp

For example, open port 80 and 443 in Ubuntu 24.04 with the following commands:

# sudo ufw allow 80/tcp
# sudo ufw allow 443/tcp

For UDP ports, you can use the same syntax, for example:

sudo ufw allow 1194/udp

Also, you can allow port ranges through the UFW firewall with TCP and UDP connections. The syntax looks like:

sudo ufw allow port-range/tcp-or-udp

For example:

# sudo ufw allow 3000:4000/tcp
# sudo ufw allow 3000:4000/udp

Allow All Connections from Specific IP Addresses: You can easily allow all connections from an IP address by using the command below:

sudo ufw allow from your-ip

Note: After changing your UFW rules, you must reload your UFW firewall. To do this, you can run the command below:

sudo ufw reload

After you have added your rules, you may want to know how I check my firewall configuration in Ubuntu. To do this, you can easily, run the following command:

sudo ufw statusStep 3 – Deny and Delete Connections From UFW Firewall on Ubuntu 24.04

At this point of Basic UFW Firewall Configuration on Ubuntu 24.04, if you plan to deny a connection, you can easily use the following syntax on Ubuntu 24.04:

sudo ufw deny service-or-port

For example, to deny port 80, you can run the command below:

sudo ufw deny 80/tcp

Or, to deny a service, you can run the following command:

sudo ufw deny ssh

Also, you can deny all connections from a specific IP address by using the following command:

sudo ufw deny from ip-address

Remember to reload your firewall after any changes by using the command below:

sudo ufw reload

You can use the numbered option to delete a rule from UFW on Ubuntu 24.04 completely. This will list your firewall rules and you can easily delete them by using the rule numbers. For this purpose, you can run the following command:

sudo ufw status numberedExample Output
Status: active

To Action From
— —— —-
[ 1] 22/tcp ALLOW IN Anywhere
[ 2] OpenSSH ALLOW IN Anywhere
[ 3] 80/tcp ALLOW IN Anywhere
[ 4] 1194/udp ALLOW IN Anywhere
[ 5] 22/tcp (v6) ALLOW IN Anywhere (v6)
[ 6] OpenSSH (v6) ALLOW IN Anywhere (v6)
[ 7] 80/tcp (v6) ALLOW IN Anywhere (v6)
[ 8] 1194/udp (v6) ALLOW IN Anywhere (v6)

Then, you can easily use the line number to delete a rule. For example, delete rule number 1 by using the following command:

sudo ufw delete 1

This will ask you for confirmation, if you are sure, press y to continue.

Next, check your firewall configuration, your rule must be deleted from the firewall rules.

Reset and Back to Default Firewall Config in Ubuntu 24.04

At this step of Basic UFW Firewall Configuration on Ubuntu 24.04, you will learn to reset your firewall settings and back to the default config. To do this, you can easily run the following UFW reset command:

sudo ufw reset

This will ask you to reset all rules to installed defaults, if you are sure, press y to continue.

Note: By default, all UFW entries are logged into /var/log/ufw.log file. You can view this file by using the command below:

# sudo more /var/log/ufw.log
# sudo tail -f /var/log/ufw.log

Note: You can visit this guide on Essential UFW Firewall Commands and Rules to learn more advanced usage of UFW. Also, if you are looking for a GUI version of UFW, you can check this link.

Conclusion

At this point, you have learned Basic UFW Firewall Configuration on Ubuntu 24.04 including enabling UFW, allowing and denying connections, deleting rules by using numbered options, resetting rules, and back to default settings. UFW is an easy-to-use tool that you can improve your Ubuntu security by knowing the rules. Hope you enjoy using it.

To get more information, you can visit the official page.

Leave a Reply

Your email address will not be published. Required fields are marked *