Grow Your Business Online

Linkysoft Services, Products, Hosting, and Servers

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.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Search the Knowledge Base

Share