Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Set up a Firewall in Linux

Learn how to set up a Firewall in Linux with clear steps, practical tips, and key considerations for completing the task safely and efficiently.

Table of Contents

This guide explains how to set up a Firewall in Linux, with clear steps, practical tips, and important checks before you begin.

In today's article, you will learn how to set up firewalls in Linux and add rules to allow access to other devices on the local network or specific ports.

UFW = Uncomplicated Firewall

You will use UFW to manage the Linux firewall, because it is easy to use and is installed by default in many distributions.

In Ubuntu, ufw is disabled by default. You can check its status with the command:

sudo ufw status

If it doesn't work and you want to check if turning on ufw makes a difference, use the command:

sudo ufw enable

To turn off the firewall, use the command:

sudo ufw disable

Check out the existing application rules

To view the list of applications for which the firewall has set rules, use the command:

sudo ufw app list

You can check which ports are open for those rules by:

sudo ufw app info APP_NAME
Check out the existing application rules screenshot You can check which ports are open for rules

Note : You should enter APP_NAME exactlyas it appears in the results of the previous command.

Create new rule

If you want to enable a firewall but only allow access to the PC from other devices on the local network, enter:

sudo ufw allow from 192.168.178.0/24

Remember to change 192.168.178.0/24 in the example as your local network's IP range.

To grant access only to a specific port, such as port 80, if you are running a local Web server, use:

sudo ufw allow from 192.168.178.0/24 to any port 80

Of course, you can change port 80 to any other port you want.

To open a series of ports on your computer with a single command, you can enter:

sudo ufw allow STARTING_PORT:ENDING_PORT/PROTOCOL

For example, to open all ports from 50,000 to 52,000 for both TCP and UDP to use with the torrent client, use:

sudo ufw allow 50000:52000/tcp sudo ufw allow 50000:52000/udp

Similarly, if you have opened a series of ports, as done here for use with the popular Transmission torrent client and want to close them, change the allow to deny in the above command, as follows:

sudo ufw deny 51413:51500/udp sudo ufw deny 51413:51500/tcp

Disable the rule and reset the firewall

After setting up a new rule, you can reuse the status command to see all the rules.

sudo ufw status
Disable the rule and reset the firewall screenshot 2 Use the status command to see all the rules

To be able to delete rules, you must first use this command:

sudo ufw status numbered
Disable the rule and reset the firewall screenshot 3 The list will now have a number next to each item

The list will now have a number next to each item. To delete a rule, use:

sudo UFW delete RULE_NUMBER

For example:

sudo ufw delete 3

If you want to delete all your custom rules and revert the firewall to the original configuration, start by disabling it with the command:

sudo ufw disable

Then, reset the firewall configuration using:

sudo ufw reset

GUFW = Graphic interface for UFW

If you find the above part a bit complicated, you can use GUFW to manage your firewall graphically.

1. Install GUW (http://gufw. org/) from Package Mananger or Software Center of distro.

2. Launch it.

GUFW = Graphic interface for UFW screenshot 4 Launch GUW

3. To turn on the firewall, simply click the Status switch to activate. The default rule is to block all incoming connections and allow all outgoing connections.

GUFW = Graphic interface for UFW screenshot 5 Click the Status switch to activate

4. Click the Rules tab and press the + button at the bottom. Here, you can add rules to your firewall.

GUFW = Graphic interface for UFW screenshot 6 Click the Rules tab and press the + button to add rules

If you use a PC to access the Internet, you should turn on a firewall, create rules that allow you to use your computer safely, instead of disabling or removing it. If you're really worried, you can also install antivirus software for Linux, to make sure no malware can harm your computer and data.

FAQ

What should I know about Set up a Firewall in Linux?

Focus on the key features, requirements, limitations, and practical use cases explained in this guide.

How do I get the best results with Set up a Firewall in Linux?

Follow the recommended steps, use current software or information, confirm compatibility, and review settings before major changes.

Are there any risks or limitations?

Potential limitations depend on compatibility, data quality, cost, privacy, support, and how the product or method is used.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.