How To Set Up a Firewall with GUFW on Linux


Get real time updates directly on you device, subscribe now.

UFW (Uncomplicated Firewall) is a straightforward to make use of firewall utility with loads of choices for many customers. It’s an interface for the iptables, which is the basic (and tougher to get snug with) method to arrange guidelines on your community.

Do you really want a firewall for desktop?

Firewall LinuxFirewall Linux

A firewall is a method to regulate the incoming and outgoing site visitors in your community. A well-configured firewall is essential for the safety of servers.

However what about regular, desktop customers? Do you want a firewall in your Linux system? Most probably you might be related to web by way of a router linked to your web service supplier (ISP). Some routers have already got built-in firewall. On prime of that, your precise system is hidden behind NAT. In different phrases, you most likely have a safety layer when you find yourself on your private home community.

Now that you realize you need to be utilizing a firewall in your system, let’s see how one can simply set up and configure a firewall on Ubuntu or another Linux distribution.

Setting Up A Firewall With GUFW

GUFW is a graphical utility for managing Uncomplicated Firewall (UFW). On this information, I’ll go over configuring a firewall utilizing GUFW that fits your wants, going over the completely different modes and guidelines.

However first, let’s see the right way to set up GUFW.

Putting in GUFW on Ubuntu and different Linux

GUFW is out there in all main Linux distributions. I counsel utilizing your distribution’s package deal supervisor for putting in GUFW.

In case you are utilizing Ubuntu, be sure to have the Universe Repository enabled. To try this, open up a terminal (default hotkey: CTRL+ALT+T) and enter:

sudo add-apt-repository universe
sudo apt replace -y

Now you may set up GUFW with this command:

sudo apt set up gufw -y

That’s it! If you happen to desire not touching the terminal, you may set up it from the Software program Middle as effectively.

Open Software program Middle and seek for gufw and click on on the search consequence.

Search for GUFW in the Ubuntu Software CenterSearch for GUFW in the Ubuntu Software CenterSeek for gufw in software program middle

Go forward and click on Set up.

Install GUFW from the Ubuntu Software CenterInstall GUFW from the Ubuntu Software CenterSet up GUFW from the Software program Middle

To open gufw, go to your menu and seek for it.

Start GUFWStart GUFWBegin GUFW

It will open the firewall software and also you’ll be greeted by a “Getting Began” part.

GUFWGUFWGUFW Interface and Welcome Display

Activate the firewall

The very first thing to note about this menu is the Standing toggle. Urgent this button will activate/off the firewall (default: off), making use of your preferences (insurance policies and guidelines).

Toggle Status On/Off in GUFWToggle Status On/Off in GUFWActivate the firewall

If turned on, the defend icon flip from gray to coloured. The colours, as famous later on this article, replicate your insurance policies. This may even make the firewall robotically begin on system startup.

Notice: Residence can be turned off by default. The opposite profiles (see subsequent part) can be turned on.

Understanding GUFW and its profiles

As you may see within the menu, you may choose completely different profiles. Every profile comes with completely different default insurance policies. What this implies is that they provide completely different behaviors for incoming and outgoing site visitors.

The default profiles are:

You’ll be able to choose one other profile by clicking on the present one (default: Residence).

Select a Profile in GUFWSelect a Profile in GUFW

Deciding on certainly one of them will modify the default conduct. Additional down, you may change Incoming and Outgoing site visitors preferences.

By default, each in Residence and in Workplace, these insurance policies are Deny Incoming and Permit Outgoing. This allows you to use companies resembling http/https with out letting something get in (e.g. ssh).

For Public, they’re Reject Incoming and Permit Outgoing. Reject, just like deny, doesn’t let companies in, but in addition sends suggestions to the person/service that attempted accessing your machine (as a substitute of merely dropping/hanging the connection).

In case you are a mean desktop person, you may persist with the default profiles. You’ll must manually change the profiles when you change the community.

So in case you are travelling, set the firewall on public profile and the from right here forwards, firewall can be set in public mode on every reboot.

Configuring firewall guidelines and insurance policies [for advanced users]

All profiles use the identical guidelines, solely the insurance policies the principles construct upon will differ. Altering the conduct of a coverage (Incoming/Outgoing) will apply the modifications to the chosen profile.

Notice that the insurance policies can solely be modified whereas the firewall is energetic (Standing: ON).

Profiles can simply be added, deleted and renamed from the Preferences menu.


Within the prime bar, click on on Edit. Choose Preferences.

Open Preferences Menu in GUFWOpen Preferences Menu in GUFWOpen Preferences Menu in GUFW

It will open up the Preferences menu.

GUFW Preferences MenuGUFW Preferences Menu

Let’s go over the choices you will have right here!

Logging means precisely what you’d suppose: how a lot info does the firewall write down within the log information.

The choices below Gufw are fairly self-explanatory.

Within the part below Profiles is the place we will add, delete and rename profiles. Double-clicking on a profile will assist you to rename it. Urgent Enter will full this course of and urgent Esc will cancel the rename.

Rename a Profile in GUFWRename a Profile in GUFW

To add a brand new profile, click on on the + below the listing of profiles. It will add a brand new profile. Nevertheless, it received’t notify you about it. You’ll additionally must scroll down the listing to see the profile you created (utilizing the mouse wheel or the scroll bar on the precise aspect of the listing).

Notice: The newly added profile will Deny Incoming and Permit Outgoing site visitors.

Add a New Profile in GUFWAdd a New Profile in GUFW

Clicking a profile spotlight that profile. Urgent the button will delete the highlighted profile.

Delete a Profile in GUFWDelete a Profile in GUFW

Notice:You’ll be able to’t rename/take away the at present chosen profile.

Now you can click on on Shut. Subsequent, I’ll go into organising completely different guidelines.


Again to the primary menu, someplace in the course of the display you may choose completely different tabs (Residence, Guidelines, Report, Logs). We already lined the Residence tab (that’s the fast information you see while you begin the app).

GUFW Home TabGUFW Home Tab

Go forward and choose Guidelines.

GUFW Rules TabGUFW Rules Tab

This would be the bulk of your firewall configuration: networking guidelines. It’s worthwhile to perceive the ideas UFW is predicated on. That’s permitting, denying, rejecting and limiting site visitors.

Notice: In UFW, the principles apply from prime to backside (the highest guidelines take impact first and on prime of them are added the next ones).

Permit, Deny, Reject, Restrict:These are the obtainable insurance policies for the principles you’ll add to your firewall.

Let’s see precisely what every of them means:

Permit: permits any entry site visitors to a portDeny: denies any entry site visitors to a portReject: denies any entry site visitors to a port and informs the requester concerning the rejectionRestrict: denies entry site visitors if an IP tackle has tried to provoke 6 or extra connections within the final 30 seconds

Including Guidelines

There are 3 ways so as to add guidelines in GUFW. I’ll current all three strategies within the following part.

Notice: After you added the principles, altering their order is a really tough course of and it’s simpler to simply delete them and add them in the precise order.

However first, click on on the + on the backside of the Guidelines tab.

Add a Rule in GUFWAdd a Rule in GUFW

This could open a pop-up menu (Add a Firewall Rule).

Add a Firewall Rule in GUFWAdd a Firewall Rule in GUFW

On the prime of this menu, you may see the 3 ways you may add guidelines. I’ll information you thru every methodology i.e. Preconfigured, Easy, Superior. Click on to increase every part.

Preconfigured Guidelines

That is probably the most beginner-friendly approach so as to add guidelines.

Step one is selecting a coverage for the rule (from those detailed above).

Select Policy of a Preconfigured Rule in GUFWSelect Policy of a Preconfigured Rule in GUFW

The subsequent step is to decide on the route the rule will have an effect on (Incoming, Outgoing, Each).

Select Direction of a Preconfigured Rule in GUFWSelect Direction of a Preconfigured Rule in GUFW

The Class and Subcategory decisions are a lot. These slim down the Functions you may choose

Selecting an Software will arrange a set of ports based mostly on what is required for that individual software. That is particularly helpful for apps that may function on a number of ports, or when you don’t need to trouble with manually creating guidelines for handwritten port numbers.

If you happen to want to additional customise the rule, you may click on on the orange arrow icon. It will copy the present settings (Software with it’s ports and so forth.) and take you to the Superior rule menu. I’ll cowl that later on this article.

For this instance, I picked an Workplace Database app: MySQL. I’ll deny all incoming site visitors to the ports utilized by this app.
To create the rule, click on on Add.

Finish Adding a Preconfigured Rule in GUFWFinish Adding a Preconfigured Rule in GUFW

Now you can Shut the pop-up (when you don’t need to add another guidelines). You’ll be able to see that the rule has been efficiently added.

Added a Preconfigured Rule in GUFWAdded a Preconfigured Rule in GUFW

The ports have been added by GUFW, and the principles have been robotically numbered. You might surprise why are there two new guidelines as a substitute of only one; the reply is that UFW robotically provides each a typical IP rule and an IPv6 rule.

Superior Guidelines

I’ll now go into the right way to arrange extra superior guidelines, to deal with site visitors from particular IP addresses and subnets and focusing on completely different interfaces.

Let’s open up the Guidelines menu once more. Choose the Superior tab.

Add an Advanced Rule in GUFWAdd an Advanced Rule in GUFW

By now, you must already be conversant in the essential choices: Identify, Coverage, Path, Protocol, Port. These are the identical as earlier than.

Select Name, Policy, Direction, Protocol, Ports for an Advanced Rule in GUFWSelect Name, Policy, Direction, Protocol, Ports for an Advanced Rule in GUFW

Notice:You’ll be able to select each a receiving port and a requesting port.

What modifications is that now you will have further choices to additional specialize our guidelines.

I discussed earlier than that guidelines are robotically numbered by GUFW. With Superior guidelines you specify the place of your rule by getting into a quantity within the Insert choice.

Notice: Inputting place zero will add your rule in spite of everything present guidelines.

Interface let’s you choose any community interface obtainable in your machine. By doing so, the rule will solely have impact on site visitors to and from that particular interface.

Log modifications precisely that: what is going to and what received’t be logged.

You may also select IPs for the requesting and for the receiving port/service (From, To).

All it’s a must to do is specify an IP tackle (e.g. or a complete subnet (e.g. for IPv4 addresses starting from to

In my instance, I’ll arrange a rule to permit all incoming TCP SSH requests from techniques on my subnet to a particular community interface of the machine I’m at present operating. I’ll add the rule in spite of everything my normal IP guidelines, in order that it takes impact on prime of the opposite guidelines I’ve arrange.

Finish Creating an Advanced Rule in GUFWFinish Creating an Advanced Rule in GUFW

Shut the menu.

Added an Advanced Rule in GUFWAdded an Advanced Rule in GUFW

The rule has been efficiently added after the opposite normal IP guidelines.

Edit Guidelines

Clicking a rule within the guidelines listing will spotlight it. Now, when you click on on the little cog icon on the backside, you may edit the highlighted rule.

Edit Highlight Rule in GUFWEdit Highlight Rule in GUFW

It will open up a menu trying one thing just like the Superior menu I defined within the final part.

Edit Rule Menu in GUFWEdit Rule Menu in GUFW

Notice: Enhancing any choices of a rule will transfer it to the tip of your listing.

Now you can ether choose on Apply to change your rule and transfer it to the tip of the listing, or hit Cancel.

Delete Guidelines

After choosing (highlighting) a rule, you can even click on on the icon.

Delete a Rule in GUFWDelete a Rule in GUFW


Choose the Report tab. Right here you may see companies which can be at present operating (together with details about them, resembling Protocol, Port, Handle and Software title). From right here, you may Pause Listening Report (Pause Icon) or Create a rule from a highlighted service from the listening report (+ Icon).

GUFW Report TabGUFW Report Tab


Choose the Logs tab. Right here is the place you’ll must examine for any errors are suspicious guidelines. I’ve tried creating some invalid guidelines to point out you what these would possibly appear like while you don’t know why you may’t add a sure rule. Within the backside part, there are two icons. Clicking the first icon copies the logs to your clipboard and clicking the second icon clears the log.

GUFW Log TabGUFW Log Tab

Wrapping Up

Having a firewall that’s correctly configured can enormously contribute to your Ubuntu expertise, making your machine safer to make use of and permitting you to have full management over incoming and outgoing site visitors.

I’ve lined the completely different makes use of and modes of GUFW, going into the right way to arrange completely different guidelines and configure a firewall to your wants. I hope that this information has been useful to you.

In case you are a newbie, this could show to be a complete information; even in case you are extra versed within the Linux world and possibly getting your ft moist into servers and networking, I hope you discovered one thing new.

Tell us within the feedback if this text helped you and why did you resolve a firewall would enhance your system!

Source link

Leave A Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More