Hosting + Ai Website Builder + Free Domain (3 Month Free Credit)
Shop Today

Beginner’s Guide to Setup FirewallD on Linux Server Step by Step

FirewallD is a dynamic firewall management tool for Linux systems that provides an easy way to configure firewall rules, zones, and services. Learning to setup FirewallD on a Linux server is essential for protecting your server from unauthorized access, managing network traffic, and ensuring secure communication for your applications and services.

FirewallD-firewall

In this article, we will guide you through installing FirewallD, configuring rules and zones, troubleshooting common issues, and implementing best practices to maintain a secure and reliable Linux server environment.

Prerequisites

Before setting up FirewallD, ensure your Linux server meets the following requirements:

  • Supported Linux distributions: CentOS, Fedora, Red Hat Enterprise Linux (RHEL)
  • User permissions: User with sudo privileges
  • System updates: Run yum update or dnf update to ensure packages are up-to-date
  • Network considerations: Familiarity with ports, services, and network zones

Having these prerequisites ensures smooth installation, proper firewall configuration, and prevents connectivity or permission issues during setup.

Setup FirewallD on Linux Server

Setting up FirewallD on a Linux server involves installing the software, starting the service, enabling it at boot, and verifying its status. Proper setup is critical for controlling inbound and outbound traffic, securing server services, and providing granular network access control across different zones.

  • Installing FirewallD

For CentOS/RHEL/Fedora:

sudo yum install firewalld -y   # CentOS/RHEL
sudo dnf install firewalld -y   # Fedora
  • Starting and Enabling FirewallD

Enable FirewallD to start automatically at boot:

sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo systemctl status firewalld

Verifying Installation

Check FirewallD version:

firewall-cmd --version

List default zones and active rules:

firewall-cmd --get-active-zones
firewall-cmd --list-all

Configuring FirewallD

Proper configuration of FirewallD allows you to secure your Linux server while providing controlled access to applications and services. This section will guide you through creating zones, allowing services and ports, and applying permanent rules to ensure your firewall policies persist across reboots.

Managing Zones

Managing zones in Linux helps control network traffic by defining security rules and policies for different trust levels. Proper zone management ensures better access control, enhanced security, and smoother network operations.

  • View available zones:
firewall-cmd --get-zones
  • Set default zone:
firewall-cmd --set-default-zone=public
  • Assign an interface to a zone:
firewall-cmd --zone=public --change-interface=eth0

Allowing Services and Ports

Allow common services like SSH and HTTP:

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

Open custom ports:

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

Reload firewall to apply changes:

firewall-cmd --reload

Removing Services and Ports

Remove unnecessary services or ports:

firewall-cmd --zone=public --remove-service=http --permanent
firewall-cmd --zone=public --remove-port=8080/tcp --permanent
firewall-cmd --reload

Troubleshooting Common Issues

Even after proper setup, FirewallD may encounter issues such as blocked services, misconfigured zones, or rules not applying correctly. Learning to fix FirewallD issues in Linux ensures your server remains accessible and secure, while minimizing service disruptions and potential security risks.

Common Issues and Fixes:

  • Firewall Not Starting:

Check status and enable service:

sudo systemctl status firewalld
sudo systemctl enable firewalld
sudo systemctl start firewalld
  • Service or Port Blocked:

Verify active zones and rules:

firewall-cmd --get-active-zones
firewall-cmd --list-all

Ensure services and ports are added to the correct zone.

  • Configuration Not Persisting:

Always use the --permanent flag and reload:

firewall-cmd --reload
  • Conflicting Firewall Tools:

Disable iptables or other firewall tools to prevent conflicts:

sudo systemctl stop iptables
sudo systemctl disable iptables

Best Practices for Managing FirewallD on Linux

Following best practices for FirewallD ensures your Linux server remains secure, compliant, and protected from unauthorized access. Proper firewall management reduces vulnerabilities, improves monitoring, and allows controlled access to critical services.

Security Practices

  • Limit open ports to only necessary services
  • Use zones to segment network interfaces and control access
  • Regularly review firewall rules and logs for unusual activity

Maintenance and Monitoring

  • Backup firewall configuration files regularly
  • Use firewall-cmd --list-all periodically to verify rules
  • Combine FirewallD with intrusion detection tools for enhanced security

Updates and Compatibility

  • Keep FirewallD and system packages updated
  • Test changes in a controlled environment before applying to production servers

By following these practices, your Linux server’s firewall will remain robust, reliable, and secure.

Conclusion

Learning to setup FirewallD on a Linux server is essential for managing network access and protecting your system from unauthorized connections. By following this guide, you now know how to install FirewallD, configure zones and rules, troubleshoot common issues, and apply best practices for secure firewall management. FirewallD provides a flexible, reliable, and user-friendly way to control Linux server traffic. For more, visit the Official FirewallD Documentation.

Himanshu Joshi

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top