Firewall Management
Getting to Know Firewalld
Managing a firewall can be a hassle, but it’s worse to manage a breach because you didn’t have one.
Special Thanks: This article was made possible by support from Linux Professional Institute
A firewall is an important part of a security strategy, but it is only one component and is not a security panacea for reasons that will become clear later in the discussion. A host-based firewall protects the local system just as a network firewall protects an entire network or part of a network, such as a DMZ.
Firewalld is the default firewall installed on CentOS 7 and newer, Red Hat Enterprise Linux 7 and newer (RHEL), and Fedora 18 and newer. If you use a Red Hat-based distribution, then you probably have it already. If you use other distributions, it’s available via git and as a tarball from firewalld.org. Firewalld uses zones to define trust levels of network connections or interfaces. Zones are an advanced topic not covered in this article. There will be a future article that covers firewalld zones.
Firewalld Features
- IPv4 and IPv6 support
- Ethernet bridging
- IP sets
- Separate runtime and permanent configuration options
- No service or system restart required for configuration changes
- Complete D-Bus API
- Predefined Zone list
- Simple configuration options
- Flexible enough for complex zone rules
- Direct interface
- Simple log of denied packets
- Application whitelisting
- Automatic kernel module loading
- Puppet integration
- CLI and graphical configuration
NOTE: A firewall is a set of allow and deny rules that control packet flow to and from networks. A firewalld service is a combination of ports, protocols, modules, and destination addresses.
Troubleshooting firewalls
System administrators of all skill levels have wasted countless hours on troubleshooting a problem that ended up pointing to a firewall that has prevented remote access to a service. The term ‘remote’ is important. Firewalls don’t prevent access to local services. In other words, firewalls prevent access from remote systems across the network but not access from the local system itself. The point of a firewall is to deny everything from the outside except what you specifically allow in. Unfortunately, frustration with firewall rules often ends in the firewall being disabled by an otherwise well-meaning system administrator.
Troubleshooting firewall access is easy. In this example, you’ve just installed the Apache web server, NGINX, or some other web server of your choice onto a server system. You test from your workstation and you get a “This site can’t be reached” message in your browser. Here is the process of how to resolve the problem:
- Check the system’s process list to be sure the service is running.
- Test the service from the local system. Open a web browser (Firefox or Chrome, if you have a GUI or lynx, if not (lynx is a text-based web browser).
- Check to see if a firewall is running.
- Add a firewall rule to allow HTTP (TCP port 80) and HTTPS (TCP port 443) or whatever ports your web service uses. Reload the configuration to enable the rule.
- Test from a remote system again.
This same procedure works for any service accessed over the network. To illustrate the troubleshooting procedure above, the next section is a demonstration of setting up a web server and then remotely accessing it.
Setting up http and https access
Install a web server onto your system. For my Red Hat-based system, the process is simple to install the Apache web server.
$ sudo yum -y install httpd
Enable the web server to run at startup.
$ sudo systemctl enable httpd.service $ sudo systemctl list-unit-files | grep httpd httpd.service enabled
Start the httpd.service.
$ systemctl start httpd.service
Check that the httpd service is running.
$ ps -ef | grep httpd
root 1194 1 0 20:05 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1199 1194 0 20:05 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1200 1194 0 20:05 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1201 1194 0 20:05 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1202 1194 0 20:05 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1203 1194 0 20:05 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
Test the web server locally using lynx or a graphical browser.
$ lynx http://localhost
Check that you can access the web server from a remote computer. It fails the test because the firewall is currently blocking all ports.
Check to see if a firewall is running.
$ sudo firewall-cmd -state running
To allow access from remote systems, you have to enable the ports configured for your web server. In this example, it is port 80. The --permanent switch adds the allowed port to the firewall’s permanent configuration.
$ sudo firewall-cmd --permanent --add-port=80/tcp success
Reload the firewall configuration.
$ sudo firewall-cmd -reload success
Check access again from your remote computer. You should see a web page appear in the browser.
Use this same procedure to configure other ports for your services. You can also add multiple ports before reloading the firewall’s configuration.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.