Firewall management
Getting to Know firewalld

© Lead Image © Gino Santa Maria, Fotolia.com
Managing a firewall can be a hassle, but it's worse to manage a breach because you didn't have one.
Afirewall is an important part of a security strategy. However, it is only one component and not a security panacea for reasons that will become clear later in this article. 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.
On CentOS 7 and newer, Red Hat Enterprise Linux 7 and newer, and Fedora 18 and newer, the default firewall is firewalld (see the "Features" box for more information.) If you use a Red Hat-based distribution, then you probably have it already. If you use other distributions, firewalld is available via git
and as a tarball [1]. Firewalld uses zones to define trust levels of network connections or interfaces. (Zones are an advanced topic not covered in this article; look for a future article covering firewalld zones).
Features
- IPv4 and IPv6 support
- Ethernet bridging
- IP sets
- Separate run time 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
Sys admins of all skill levels have wasted countless hours 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; 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 sys admin.
Troubleshooting firewall access is easy. In the following example, the Apache web server, NGINX, or some other web server of your choice has just been installed onto a server system. During testing, you get a "This site can't be reached" message in the browser. 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 (if you have a GUI, Firefox or Chrome; if not, Lynx, 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.
- Retest from a remote system.
This same procedure works for any service accessed over the network.
HTTP and HTTPS Access
To illustrate this troubleshooting procedure, I will demonstrate setting up a web server and then accessing it remotely. First, install a web server on 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 httpdhttpd.service enabled
Start httpd.service
:
$ systemctl start httpd.service
Check that the httpd
service is running, as shown in Listing 1. Then, test the web server locally using Lynx or a graphical browser (Figure 1):
$ lynx http://localhost
Listing 1
Verifying the httpd Service
Check that you can access the web server from a remote computer; it fails the test, because the firewall is currently blocking all ports (Figure 2).
Check to see if a firewall is running:
$ sudo firewall-cmd -state running
To allow access from remote systems, you must 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 (Figure 3).
Use this same procedure to configure other ports for your services. You can also add multiple ports before reloading the firewall's configuration.
Focusing on Security
To reiterate, firewalls are a single part of an overall security strategy, not a panacea. In configuring a firewall exception to allow remote access to port 80 for the Apache web server, you have created a vulnerability on the host system. For the moment, assume that you only allow ports 22 (SSH) and 80 (HTTP) on that server system. That's two vulnerabilities or what security people call "acceptable risk." You have to accept some risk when you allow network access to a system's services.
The reason allowing access creates vulnerabilities is that you're allowing computers on a network, and possibly the entire Internet, to access this system via port 80. What if the version of Apache you installed has an unpatched security flaw? Your system is exposed and vulnerable to that flaw until it's patched. The firewall won't protect the system, because you have allowed access to that port. The door is open.
Is this a real problem? Yes, and no. It is a problem but the alternative is to have no services running on computers, which means you have no customers or employees connecting to those services. That's not acceptable. There is some degree of risk that you have to accept to run a service. You have to practice due diligence and protect the system in other ways (encryption, application firewall, backups, and monitoring) and routinely patch the system.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Direct Download
Read full article as PDF:
Price $2.95
News
-
GNOME 43 To Bring Some Exciting New Features
GNOME 43 is getting close to the first alpha development release and it promises to add one particular feature that should be exciting to several users.
-
KaOS 2022.06 Now Available With KDE Plasma 5.25
The newest iteration of KaOS Linux not only adds the latest KDE Plasma desktop but sets LibreOffice as the default.
-
Manjaro 21.3.0 Is Now Available
Manjaro “Ruah” has been released and includes the latest Calamares installer, GNOME 42, and much more.
-
SpiralLinux is a New Linux Distribution Focused on Simplicity
A new Linux distribution, from the creator of GeckoLinux, is a Debian-based operating system with a focus on simplicity and ease of use.
-
HP Dev One Linux Laptop is Now Available for Pre-Order
The System76/HP collaboration Dev One laptop, geared toward developers, is now available for pre-order.
-
NixOS 22.5 Is Now Available
The latest release of NixOS with a much-improved package manager and a user-friendly graphical installer.
-
System76 Teams up with HP to Create the Dev One Laptop
HP and System76 have come together to develop a new laptop, powered by Pop!_OS and aimed toward developers.
-
Titan Linux is a New KDE Linux Based on Debian Stable
Titan Linux is a new Debian-based Linux distribution that features the KDE Plasma desktop with a focus on usability and performance.
-
Danielle Foré Has an Update for elementary OS 7
Now that Ubuntu 22.04 has been released, the team behind elementary OS is preparing for the upcoming 7.0 release.
-
Linux New Media Launches Open Source JobHub
New job website focuses on connecting technical and non-technical professionals with organizations in open source.