RHCSA Practical Lab Series – Firewall Configuration & Security

Expertise in Cloud, Networking & DevOps
Photo by Alexandre Debiève / Unsplash

πŸ” Lab 3: Configuring Firewalld to Allow HTTP on Port 8080

πŸ“Œ Objective

By default, firewalld blocks access to non-standard ports. In this lab, you will:

βœ” Open port 8080 for Apache (httpd)
βœ” Configure SELinux to allow HTTP traffic on port 8080
βœ” Ensure firewall rules persist after reboot


πŸ“Œ Step 1: Check Current Firewalld Rules

Before making changes, verify which ports are currently open:

[root@node1 ~]# firewall-cmd --list-all

πŸ”Ή Expected Output (partial):

public (active)
  target: default
  services: ssh dhcpv6-client http https
  ports: 

πŸ“Œ Tip: If port 8080 is not listed under ports:, it must be added.


πŸ“Œ Step 2: Open Port 8080 in the Firewall

Allow HTTP traffic on port 8080 permanently:

[root@node1 ~]# firewall-cmd --permanent --add-port=8080/tcp

πŸ“Œ Tip: The --permanent flag ensures the rule persists after a reboot.


πŸ“Œ Step 3: Reload the Firewall Rules

Apply the changes:

[root@node1 ~]# firewall-cmd --reload

πŸ”Ή Verify the rule has been applied:

[root@node1 ~]# firewall-cmd --list-ports

πŸ”Ή Expected Output:

8080/tcp

βœ… If port 8080 appears, the firewall is correctly configured.


πŸ“Œ Step 4: Configure SELinux to Allow HTTP on Port 8080

πŸ”Ή Check current allowed HTTP ports:

[root@node1 ~]# semanage port -l | grep http

πŸ”Ή Expected Output (partial):

http_port_t                    tcp      80, 443, 488, 8008, 8009, 8443

πŸ“Œ Port 8080 is not listed, so we need to add it.


πŸ“Œ Step 5: Allow Apache to Use Port 8080 in SELinux

[root@node1 ~]# semanage port -a -t http_port_t -p tcp 8080

πŸ”Ή Verify that port 8080 has been added:

[root@node1 ~]# semanage port -l | grep 8080

πŸ”Ή Expected Output:

http_port_t                    tcp      80, 443, 488, 8008, 8009, 8080, 8443

βœ… If port 8080 appears, SELinux has been updated correctly.

πŸ“Œ Troubleshooting:

If the command fails, ensure SELinux is in enforcing mode:

getenforce

If semanage is not found, install the package:

yum -y install policycoreutils-python-utils

πŸ“Œ Step 6: Restart Apache and Verify

πŸ”Ή Restart the Apache service to apply changes:

[root@node1 ~]# systemctl restart httpd

πŸ”Ή Enable Apache to start on boot:

[root@node1 ~]# systemctl enable httpd

πŸ“Œ Step 7: Verify Web Server Accessibility

πŸ”Ή Check if Apache is listening on port 8080:

[root@node1 ~]# ss -tnlp | grep httpd

πŸ”Ή Expected Output:

LISTEN  0  128  *:8080  *:*  users:(("httpd",pid=1234,fd=5))

βœ… If Apache is listening on port 8080, the configuration is correct.


πŸ“Œ Step 8: Test Access to the Web Server

From node1, test HTTP access:

[root@node1 ~]# curl http://node1.cloudnetops.tech:8080/

πŸ”Ή Expected Output:

<html>
<head><title>Test Page</title></head>
<body><h1>Success! Apache is running on port 8080.</h1></body>
</html>

βœ… If you receive the HTML response, the firewall and SELinux are correctly configured.

πŸ“Œ Troubleshooting:

If the firewall rule was not applied, try restarting firewalld:

systemctl restart firewalld

If curl fails, check if httpd is running:

systemctl status httpd

βœ… Final Summary

In this lab, you successfully:
βœ” Opened port 8080 in firewalld
βœ” Allowed Apache to serve content on port 8080
βœ” Updated SELinux policy to allow HTTP on port 8080
βœ” Restarted and enabled Apache
βœ” Ensured the changes persist after reboot


πŸ“Œ Next Lab: Creating User Accounts and Group Permissions

πŸ“© Subscribe for more RHCSA exam labs and hands-on tutorials! πŸš€

Read more