Step-by-Step Guide: Configuring Firewalld for Apache Web Server on Red Hat Linux
Alexand

Alexand @axisinfo_0a61830e06c3c950

About: I'm an IT enthusiast passionate about networking, systems integration, cybersecurity, and data analytics. I aim to build secure, data-driven solutions that protect businesses and drive innovation.

Location:
Germany
Joined:
Jul 13, 2024

Step-by-Step Guide: Configuring Firewalld for Apache Web Server on Red Hat Linux

Publish Date: Apr 16
2 0

Securing your Apache web server with Firewalld is essential for managing incoming and outgoing traffic. If http and https services are absent, don’t worry; I will show you how to add them. Here’s the complete guide:


Step 1: Install Apache Web Server

Ensure that Apache is installed and running:

  1. Update your system:
   sudo yum update
Enter fullscreen mode Exit fullscreen mode
  1. Install Apache:
   sudo yum install httpd
Enter fullscreen mode Exit fullscreen mode
  1. Start and enable Apache:
   sudo systemctl start httpd
   sudo systemctl enable httpd
Enter fullscreen mode Exit fullscreen mode

Step 2: Verify Firewalld Installation

Check if Firewalld is installed and running:

sudo systemctl status firewalld
Enter fullscreen mode Exit fullscreen mode

If it’s not running, start and enable it:

sudo systemctl start firewalld
sudo systemctl enable firewalld
Enter fullscreen mode Exit fullscreen mode

Step 3: Check and Add HTTP/HTTPS Services

To ensure that your Apache server can communicate properly, HTTP and HTTPS services need to be enabled. Here’s how:

  1. List Available Services Check if http and https services are available:
   sudo firewall-cmd --get-services
Enter fullscreen mode Exit fullscreen mode

If they are listed, proceed to add them in the next step.

  1. Manually Add Missing Services

    If http or https is missing, create a custom service file:

    • Navigate to the services directory:
     cd /etc/firewalld/services/
    
  • Create a new XML file (e.g., http.xml) for HTTP:

     sudo nano http.xml
    

    Add the following content:

     <?xml version="1.0" encoding="utf-8"?>
     <service>
       <short>HTTP</short>
       <description>Web server HTTP service</description>
       <port protocol="tcp" port="80"/>
     </service>
    

    Repeat the steps for https.xml, using port 443.

  • Reload Firewalld to register the services:

     sudo firewall-cmd --reload
    
  1. Enable HTTP/HTTPS Add the services permanently to Firewalld:
   sudo firewall-cmd --permanent --add-service=http
   sudo firewall-cmd --permanent --add-service=https
Enter fullscreen mode Exit fullscreen mode

Reload to apply changes:

   sudo firewall-cmd --reload
Enter fullscreen mode Exit fullscreen mode

Step 4: Verify Firewall Rules

After adding the services, verify they are active:

sudo firewall-cmd --list-all
Enter fullscreen mode Exit fullscreen mode

You should see http and https listed under the services.


Step 5: Test Apache Access

Confirm your setup by accessing your Apache server:

  1. Open a web browser and visit:
    • HTTP: http://your_server_ip
    • HTTPS: https://your_server_ip
  2. You should see the Apache default page.

By following these steps, you’ve ensured that your Apache server is configured securely with Firewalld, even if http and https were missing initially. This setup protects your web server and allows seamless communication.

https://www.linkedin.com/in/alexandjickneba/

Comments 0 total

    Add comment