How to set up a firewall in Linux
To keep your computer safe, you should set up a firewall to prevent others from accessing your computer and protecting you from network attacks. However, if you are a new Linux user, you may not know how to configure a firewall in your system.
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

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

To be able to delete rules, you must first use this command:
sudo ufw status numbered

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.

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.

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

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.
You should read it
- 5 reasons why you should use a firewall
- What is a firewall? Overview of Firewall
- 10 free firewall software is most worthwhile
- How to check the firewall
- Instructions to reset Windows Firewall Rules to the initial default state
- How to turn on the router's built-in firewall
- How to turn on / off Windows Firewall in Windows 7, 8 / 8.1 and Windows 10
- Instructions allow applications to communicate with each other via Windows Firewall
May be interested
- Instructions allow applications to communicate with each other via Windows Firewallwindows firewall acts as a barrier to prevent your computer from connecting to the rest of the internet. the firewall retains unwanted network traffic and allows applications on your computer to communicate with the outside world. but each fence needs a gate, and that's where exceptions come in.
- How to turn firewall (Firewall) on Win 7how to turn off the firewall (firewall) on windows 7. a firewall is a software that comes with windows and it is responsible for filtering information on and off the computer. firewalls are also an advantage of windows 7 when they protect against malicious files. viruses invade their computers
- Learn about Cloud Firewallas the technology around us grows, firewalls also need to be brought to the cloud to keep up with the trend. that's why the term cloud firewall was born.
- 3 ways to turn off the Windows 11 firewall, steps to turn off the firewall on windows 11windows 11 is a new operating system released by microsoft in 2021. of course, it still has a built-in windows firewall (firewall) to ensure user safety. but if you want to turn off the firewall on windows 11, how do you do it?
- Overview of the TMG Firewall Troubleshooting featureone of the most recognizable enhancements in the tmg firewall is what is available in the isa 2006 firewall, which is the troubleshooting section.
- How to turn on and off Windows 10 firewall, Windows 10 Firewall fastestto enable or disable the firewall on windows 10, you can access the security and firewall settings in control center. this allows you to manage network access for software and services. follow the steps to toggle windows 10 firewall to adjust windows defender firewall settings, windows 10 firewall and protect your computer.
- 3 ways to turn off the Windows 10 firewall, steps to turn off the firewall on Windows 10windows firewall, also known as firewall, is responsible for ensuring the safety of your windows computer. it will filter and prevent malicious data streams from attacking the computer.
- How to Customize Windows Firewall with Windows Firewall Controlwindows' default firewall and anti-virus program should be more than enough for most people. however, there is one thing these programs lack, and that is customizability. and that's where malwarebyte's windows firewall control comes into play.
- Instructions to enable / disable Windows Firewall with Command Prompta firewall is like a barrier between a local network (local network) and another network (such as the internet), controlling incoming and outgoing data traffic.
- ZoneAlarm Free Firewall 158_181_18901, download ZoneAlarm Free Firewall herezonealarm free firewall is software that provides advanced layers of protection to monitor and block unwanted traffic, protect personal data, and prevent hackers and malware from performing bad behavior with the system. .