Information Technology Tips

Innotechtips_logo_v4
Menu
  • Home
  • Linux
  • Programming
  • Other Tech Tips
    • Windows
    • Security
Youtube
Home Linux

How to Configure the Firewall on Ubuntu Linux using ufw

Inno by Inno
July 27, 2023

Network traffic filtering on Ubuntu Linux

or Debian-based distros can be achieved using iptables. However, iptables is a somewhat advanced or complicated approach to managing firewall rules. Ubuntu provides a simplified tool for manipulating firewall rules and is referred to as ufw (Uncomplicated firewall). Ufw was created as an easier alternative for configuring the firewall. Ufw provides a user-friendly approach for creating IPv4 and IPv6 host-based firewall rules. It is worth noting that ufw provides the ability to add or remove simple firewall rules but it is not intended to provide full firewall functionality.

The following sections will demonstrate some examples of how we can utilize ufw on an Ubuntu machine.

Ufw is disabled by default. To check the status of the ufw firewall we can use the below command:

sudo ufw status

The below command is used to enable ufw:

sudo ufw enable

To view the status ufw in verbose format use:

sudo ufw status verbose

To view the ufw firewall in its numbered format:

sudo ufw status numbered

If ufw was enabled and we wanted to disable it, we can use the following command:

sudo ufw disable

To allow a given application (for instance, SSH on port 22), we can use the below command:

sudo ufw allow 22

We can also deny a given service by inserting a rule in a given position using the numbered format. In this example, we will deny SSH and also implement the command using numbered rules format. This allows us to insert the rule before other rules. This is because order matters and if the rule is inserted after other related rules on the list, the rule may never be reached.

sudo ufw insert 1 deny ssh

To remove or delete a previously applied rule, use the delete keyword as follows:

sudo ufw delete deny 22

To reload the firewall after making changes via ufw, we can use the following command:

sudo ufw reload

Ufw also provides the capability to allow traffic from only a specific IP address or network to a given port. This example shows how we can allow SSH traffic from host 172.16.1.2 to any given IP address on this host.

sudo ufw allow proto tcp from 172.16.1.2 to any port 22

To check what traffic is allowed by default whenever ufw is enable, one can look inside the file named before.rules that is located in the below path.

/etc/ufw/before.rules

Some of the traffic that is allowed by default includes pings or ICMP (e.g.,  echo-request), DHCP (port 67 and 68), and already-established connections. These rules are run before those ufw rules that are defined on the command line or terminal.

If we wanted to check the resulting ufw rule without applying it, we can use the ‘–dry-run’ option as shown in the command below:

sudo ufw –dry-run deny http

There is also a GUI version of ufw that can be opened by running the gufw command on the terminal. However, gufw is not installed by default on Ubuntu. To install the GUI version of ufw use:

sudo apt install gufw

To open the GUI version of ufw, type the following command in the terminal:

gufw

The GUI version of ufw allows us to view the currently configured firewall rules, add new rules, delete rules, and view logs.

Conclusion

In this article, we introduced the concept of network traffic filtering in Ubuntu Linux. We demonstrated how to use the ufw tool to configure the firewall in Ubuntu. We showed how ufw can be a much simpler approach for managing firewalls when compared to using iptables. We called to attention some of the commands associated with ufw that can be used to allow or deny network traffic. In addition, we provided examples of how to verify which firewall rules are currently implemented in an Ubuntu machine.

Inno

Inno

Related Posts

Linux

Getting Started with Kali Linux: A Guide for Beginners

July 31, 2024
Linux

20 Linux Commands for Beginners

March 31, 2024
Linux

What is KVM Virtualization?

March 31, 2024
Linux

The Linux Booting Process in Linux

February 17, 2024

Category

  • Linux
  • Other Tech Tips
  • Programming
  • Windows

Recommended.

Introduction to Functions in Python

Introduction to Functions in Python

July 27, 2023
File/Directory Ownership and Permissions in Linux

File/Directory Ownership and Permissions in Linux

July 27, 2023

Trending.

How To Connect Kali Linux to Wi-Fi on VirtualBox

October 9, 2023

How to Install and Enable Free VPN in Kali Linux

July 27, 2023

How to Connect Kali Linux on VMware Workstation to a Wi-Fi Network

July 27, 2023

How to Capture Network Traffic on a Wi-Fi Network using Kali Linux

July 27, 2023
How to Connect to Kali Linux from Window’s Command Prompt

How to Connect to Kali Linux from Window’s Command Prompt

July 27, 2023

About us

This site is dedicated towards highlighting various important aspects of information technology. The key areas includes programming, Linux, software, and security. The content will include articles as well as videos.

Quick Links

Menu
  • Home
  • Linux
  • Programming
  • Other Tech Tips
    • Windows
    • Security

Privacy Policy

Menu
  • Privacy Policy
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}
No Result
View All Result
  • Cookie Policy (EU)
  • Home 1
  • Home 2
  • Home 3
  • Mytest Page
  • Privacy Policy

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.