Skip to content
Home » Get Started with Firewall Rules in Ubuntu

Get Started with Firewall Rules in Ubuntu

Introduction to Firewall Rules in Ubuntu

Ubuntu is one of the most popular Linux distributions that powers a vast majority of servers, workstations, and even personal computers. One of the key security features of Ubuntu is the firewall, which provides a barrier between the system and the outside world, controlling the incoming and outgoing traffic. Firewall rules are used to control the access of applications, services, and protocols. In this blog, we will explore the process of viewing and managing firewall rules in Ubuntu, and the significance of firewall rules in a secured environment.

Prerequisites

Before we begin, ensure that you have administrative access to your Ubuntu system and a basic understanding of the terminal and firewall concepts.

Viewing Firewall Rules in Ubuntu

Ubuntu uses the ufw (Uncomplicated Firewall) as the default firewall. The ufw firewall provides a simplified and user-friendly interface for managing firewall rules in Ubuntu. The following command can be used to view the current firewall rules in Ubuntu:

sudo ufw status

This command displays the status of the firewall, including the active rules, profiles, and firewall logging.

Here is an example of the output:

Status: active

To                         Action      From
--                         ------      ----
80/tcp                     ALLOW       Anywhere                  
22/tcp                     DENY        Anywhere                  
8080/tcp                   ALLOW       Anywhere                  
5432/tcp (PostgreSQL)      ALLOW       Anywhere                  
22 (v6)                    DENY        Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
8080/tcp (v6)              ALLOW       Anywhere (v6)
5432/tcp (PostgreSQL) (v6) ALLOW       Anywhere (v6)

In this example, the firewall is active and has several rules defined for both IPv4 and IPv6 protocols. The rules include allowing incoming traffic on ports 80, 8080, and 5432, and denying incoming traffic on port 22. The output clearly shows the action and the source of incoming traffic for each rule.

Managing Firewall Rules in Ubuntu

In Ubuntu, firewall rules can be managed using the ufw firewall. The following commands can be used to manage the firewall rules:

  • To enable the firewall:
sudo ufw enable
  • To disable the firewall:
sudo ufw disable
  • To allow incoming traffic to a specific port:
sudo ufw allow <port number>

For example, to allow incoming traffic to port 80, the following command can be used:

sudo ufw allow 80
  • To deny incoming traffic to a specific port:
sudo ufw deny <port number>

For example, to deny incoming traffic to port 22, the following command can be used:

sudo ufw deny 22
  • To delete a firewall rule:
sudo ufw delete <rule>

For example, to delete the rule allowing incoming traffic to port 80, the following command can be used:

sudo ufw delete allow 80

5 Tips for Managing Firewall Rules in Ubuntu

  1. Enable firewall logging to keep track of the firewall activity.
  2. Be mindful of the rules you create and delete, as it may impact the functionality of your system.
  3. Use the default policies (deny incoming and allow outgoing) as the starting point. E.g.: sudo ufw default deny incoming
  4. Regularly review the firewall rules to ensure that only necessary incoming traffic is allowed.
  5. Familiarize yourself with the commonly used ports and services to create firewall rules accordingly.

Conclusion

In this blog, we have explored the process of viewing and managing firewall rules in Ubuntu using the ufw firewall. Firewall rules are an essential aspect of system security and must be managed with care. Understanding firewall rules and the ufw firewall provides a better understanding of the firewall and its functionality in Ubuntu. To dive deeper into the topic, we recommend exploring the ufw manual pages by running the following command:

man ufw

Challenge

Try creating a firewall rule to allow incoming traffic to a specific port and verify the rule using the ufw status verbose command.

Leave a Reply

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

sixteen − nine =