[ TechDocsCove ]  TechDocsCove en   ↩︎

# Getting Started with firewalld: A Comprehensive Guide

linux   security   server-configuration   system-administration  

translations: [ de/Deutsch ] · [ es/Español ] · [ fr/Français ]


Table of contents


firewalld is a dynamic firewall management tool for Linux that provides an easy way to manage your firewall rules. It uses zones to define the trust level of network connections and supports both IPv4 and IPv6. This guide will cover the basic usage of firewalld, focusing on rules and zones.

Checking the Status of firewalld

To check if firewalld is running, use the following command:

sudo firewall-cmd --state

If it returns running, then firewalld is active.

Listing Active Zones

To see the active zones and their configurations, run:

sudo firewall-cmd --get-active-zones

This command will show which zones are active and the interfaces associated with them.

Listing Rules in a Zone

To list the rules in a specific zone (e.g., public), use:

sudo firewall-cmd --zone=public --list-all

This command displays all the settings, including services, ports, and rules defined for the specified zone.

Creating a New Rule

To allow a specific service (e.g., http) in the public zone, you can run:

sudo firewall-cmd --zone=public --add-service=http --permanent

The --permanent flag makes the rule persistent across reboots. After adding the rule, reload firewalld to apply the changes:

sudo firewall-cmd --reload

Removing a Rule

If you need to remove a previously added rule, use:

sudo firewall-cmd --zone=public --remove-service=http --permanent

Again, remember to reload firewalld to apply the changes:

sudo firewall-cmd --reload

Adding and Removing Ports

You can also allow specific ports. For example, to allow TCP traffic on port 8080:

sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent

To remove that port, use:

sudo firewall-cmd --zone=public --remove-port=8080/tcp --permanent

Checking All Rules

To check all rules currently active in the firewall, you can use:

sudo firewall-cmd --list-all

This command shows all zones and the associated rules for each zone.

Conclusion

firewalld is a powerful tool for managing firewall rules on Linux systems. With its zone-based configuration and straightforward command-line interface, you can easily secure your server or workstation. Regularly check your firewall rules and adapt them as necessary to maintain your system’s security.



Created on: Nov 6, 2024


Email shareIcon for sharing via email    Reddit shareIcon for sharing via Reddit    X shareIcon for sharing via X    Telegram shareIcon for sharing via Telegram    WhatsApp shareIcon for sharing via WhatsApp    Facebook shareIcon for sharing via Facebook    LinkedIn shareIcon for sharing via LinkedIn



Discover More within this Subject: