Servers

Install and Manage Firewalls in AlmaLinux 9

Share this!
Install and Manage Firewalls in AlmaLinux 9

A firewall is a security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules. Firewalls act as a barrier between a trusted internal network and untrusted external networks, such as the internet. They are critical for preventing unauthorized access while allowing legitimate traffic to pass through. In this tutorial, we will walk you through the process of understanding, installing, configuring, and troubleshooting firewalls on AlmaLinux 9.

What is a Firewall?

At its core, a firewall is designed to monitor network traffic and either allow or block it based on a defined set of rules. Firewalls can be either hardware- or software-based and are essential in providing a secure network environment by controlling access between external and internal systems.

Types of Firewalls

  • **Packet Filtering Firewalls**: These examine packets of data and filter them based on source and destination IP addresses, protocols, and ports.
  • **Stateful Inspection Firewalls**: They monitor the state of active connections and determine which network packets to allow through the firewall.
  • **Proxy Firewalls**: Proxy firewalls act as an intermediary between two systems and filter traffic at the application layer.

Installing Firewalld on AlmaLinux 9

In AlmaLinux 9, the default firewall solution is Firewalld. It provides an easy-to-use and powerful tool for managing firewall rules and zones. Follow these steps to install Firewalld:

Step 1: Install Firewalld

Use the following command to install Firewalld:

sudo dnf install firewalld

Step 2: Start and Enable Firewalld

Once installed, you need to start and enable the firewall to ensure it runs at startup:

sudo systemctl start firewalld

sudo systemctl enable firewalld

Step 3: Check Firewall Status

To verify that Firewalld is running, use:

sudo firewall-cmd --state

Configuring Firewalld on AlmaLinux 9

Firewalld uses the concept of zones to define what kind of network traffic is allowed or blocked. AlmaLinux 9 comes with several predefined zones, each catering to specific use cases, such as public, work, and home zones.

Step 1: List Available Zones

To list all available zones in Firewalld, run:

sudo firewall-cmd --get-zones

Step 2: Set Default Zone

You can set the default zone that applies to network interfaces without a defined zone:

sudo firewall-cmd --set-default-zone=public

Opening and Closing Ports in Firewalld

To allow specific services or ports through the firewall, you'll need to add rules to Firewalld.

Common Ports to Enable

Here are some common ports that you might need to open depending on the services you are running:

  • **SSH** (Port 22): Allows remote connections via SSH.
  • **HTTP** (Port 80) and **HTTPS** (Port 443): Allow web traffic for websites hosted on the server.
  • **MySQL** (Port 3306): Required if running a MySQL database server.
  • **FTP** (Port 21): Needed for FTP server connections.

Step 1: Open a Port

To open a specific port, such as SSH (port 22), use the following command:

sudo firewall-cmd --permanent --add-port=22/tcp

Once added, reload the firewall to apply the changes:

sudo firewall-cmd --reload

Step 2: Remove a Port

If you want to close a previously opened port, use:

sudo firewall-cmd --permanent --remove-port=22/tcp

Step 3: List All Open Ports

To check all currently open ports, run:

sudo firewall-cmd --list-all

Troubleshooting Firewalld

Common Issues and Fixes

  • Firewalld is Not Starting: If Firewalld fails to start, check the service status using:

    sudo systemctl status firewalld

  • Unable to Connect to Services: Ensure that the necessary ports are open and reload the firewall settings using:

    sudo firewall-cmd --reload

  • Firewall Rules Not Applying: Verify if the correct zone is being used and that the rules are applied to the intended interfaces by using:

    sudo firewall-cmd --get-active-zones

Conclusion

Firewalls are a critical component of network security in any system. AlmaLinux 9's Firewalld provides a flexible and powerful solution for managing your server's incoming and outgoing traffic. By following this guide, you should be able to install, configure, and troubleshoot your firewall setup effectively. A properly configured firewall ensures that your server is secure from unauthorized access while allowing necessary services to function without disruption.

Read more excellent posts from this exact same topic.

How To Disable Firewalld On AlmaLinux A Step-By-Step Guide

Firewalld is the default firewall management tool on AlmaLinux, providing a dynamic way to manage firewall settings with support for network zones. While it's a crucial component for system security, there are scenarios where you might need to disable it temporarily or permanently. This guide will walk you through the steps to disable Firewalld, along with important considerations to keep your system secure.

1 minute read

Mastering Linux Server Commands Similarities and Differences Across Distributions

Linux is one of the most powerful and versatile operating systems, widely used for both personal computing and server management. Although different Linux distributions (or "distros") may seem distinct, many of their basic operations remain consistent across platforms. However, there are also key differences, especially when it comes to package management and system administration. In this article, we’ll explore both the commonalities and distinctions between Linux distributions, helping users

1 minute read

How To Disable The Firewall On AlmaLinux 9 Step-By-Step Guide

Firewalls play a crucial role in protecting systems by monitoring and controlling incoming and outgoing network traffic. However, there are scenarios where disabling the firewall may be necessary, such as when troubleshooting or during specific system configurations. In this article, we will walk you through the steps to disable a firewall. This is a general guide that can be applied to various systems, offering a clear, professional explanation suitable for a wide audience.

1 minute read