Firewall CentOS

Introduction

firewalld is a firewall management tool for Linux operating systems.

It provides firewall features by acting as an interface for the netfilter framework of the Linux kernel through the nftables userspace utility (before version v0.6.0 the iptables backend), acting as an alternative to the nft command-line program.

The name firewalld follows the Unix convention of naming system daemons by adding the letter "d". firewalld is written in Python .

It was supposed to be ported to C++ , but the port project was abandoned in January 2015.

Check the Current Status

To check the status of firewalld execute

sudo systemctl status -l firewalld

● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2026-11-27 00:00:01 EEST; 2h 55min ago 1795818105 Docs: man:firewalld(1) Main PID: 783 (firewalld) Tasks: 2 CGroup: /system.slice/firewalld.service └─783 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid Nov 27 14:23:45 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon... Nov 27 14:23:45 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. Nov 27 14:23:45 localhost.localdomain firewalld[783]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.

Firewall

List of open ports

firewall-cmd --list-ports

8443/tcp 3389/tcp 2222/tcp

List of active zones

firewall-cmd --get-active-zones

public interfaces: enp0s3 enp0s8

Full list

sudo firewall-cmd --list-all

public (active) target: default icmp-block-inversion: no interfaces: enp0s3 enp0s8 sources: services: dhcpv6-client http https ssh ports: 8443/tcp 3389/tcp 2222/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

Open a Port

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

sucess

Then you need to restart the firewall

sudo firewall-cmd --reload

sucess

Check

sudo firewall-cmd --list-ports

8443/tcp 3389/tcp 2222/tcp 19999/tcp

If you are suddenly curious what port 19999 is - it is used by Locust

Block a Port

sudo firewall-cmd --remove-port=22/tcp --permanent
sudo firewall-cmd --remove-port=53/udp --permanent
sudo firewall-cmd --reload

Allow a Service

sudo firewall-cmd --add-service=https
sudo firewall-cmd --reload

Block a Service

sudo firewall-cmd --remove-service=https
sudo firewall-cmd --reload

Add an IP to the "white" list

To add a single IP address

sudo firewall-cmd --permanent --add-source=192.168.56.101

To add the whole subnet 255.255.255.0 run

sudo firewall-cmd --permanent --add-source=192.168.2.0/24
sudo firewall-cmd --reload

Remove an IP from the "white" list

To remove a single IP address

sudo firewall-cmd --permanent --remove-source=192.168.2.50
sudo firewall-cmd --reload

To remove the whole subnet 255.255.255.0 run

sudo firewall-cmd --permanent --remove-source=192.168.2.50/24
sudo firewall-cmd --reload

Block an IP

To block incoming connections from a specific IP address use rich-rule

sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='192.168.2.50' reject"
sudo firewall-cmd --reload

View All rich-rules

To view all existing rich-rules execute

sudo firewall-cmd --list-rich-rules

rule family="ipv4" source address="192.168.56.109" reject

Delete a Rule

To delete an existing rich-rule execute

sudo firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.56.109" reject'
sudo firewall-cmd --reload

sudo firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="3306" accept'

Article author: Andrei Olegovich