Configuring a Firewall
Nov 18, 2025
- Wikipedia - Unix Domain Socket
- Wikipedia - Network Socket
- Red Hat - Configuring Firewalls and Packet Filters
Analyzing Service Configuration with ss
ssis the standard tool to show socket informationsswill show all connections (network and Unix sockets)ss -tushows connected TCP and UDP socketsss -tuaadds sockets that are in listening statess -tlnshows TCP sockets that are in listening state only, without resolving host namesss -tulpnshows TCP and UDP sockets in listening state and process name or PID to the output
nmapcan be used to analyze ports that are open on remote hostsnmap -snwill scan a network for available hostsnmap -sVwill scan for services
RHEL Firewalling
nftablesis the framework that applies firewallingfirewaldis a service which RHEL uses as the front end to managenftablesfirewalls
Allowing Service Access
- This is the main task for the RHCSA exam
firewall-cmdis used to write firewall configuration- Without
--permanentthe rule is written to runtime - With
--permanentthe rule is persistent, but not active at runtime
- Without
firewall-cmd --list-allfirewall-cmd --get-servicesfirewall-cmd --add-servicefirewall-cmd --reload
Allowing Port Access
firewall-cmd --add-port PORT/tcpfirewall-cmd --reload
If this is needed, you might as well just write a service for better portability.
- Copy an example from /usr/lib/firewalld/services to /etc/firewalld/services and modify to meet your needs
- Run
firewall-cmd --reload - Run
firewall-cmd --get-servicesand the new service should be listed
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>My Port</short>
<description>My Port Service</description>
<port protocol="tcp" port="83"/>
<port protocol="udp" port="83"/>
</service>
Advanced Firewalld Usage
Note: this is not needed for the RHCSA exam.
man firewalld.richlanguage
Lab Exercise
- Configure firewalld such that remote access to ssh over is allowed only on port 2022
- Configure firewalld such that remote access to http is allowed only on port 82
Ensure changes are applied immediately as well as persistently
Solution
- —
firewall-cmd --add-service ssh --permanent
firewall-cmd --add-service http --permanent
firewall-cmd --service ssh --get-ports --permanent
firewall-cmd --service http --get-ports --permanent
firewall-cmd --service ssh --add-port 2022/tcp --permanent
firewall-cmd --service http --add-port 82/tcp --permanent
firewall-cmd --service ssh --remove-port 22/tcp --permanent
firewall-cmd --service http --remove-port 80/tcp --permanent
firewall-cmd --reload
firewall-cmd --service ssh --get-ports --permanent
firewall-cmd --service http --get-ports --permanent
- Clint Jordan