How To Configure Firewall on CentOS 7

Configure Firewall on CentOS 7

In this tutorial we will show you how to configure Firewall on CentOS 7. For those of you who didn’t know, FirewallD is a complete firewall solution that manages the system’s iptables rules and provides a D-Bus interface for operating on them. Starting with CentOS 7, FirewallD replaces iptables as the default firewall management tool.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step, configure Firewall on CentOS 7 server.

Configure Firewall on CentOS 7

Step 1. First, let’s start by ensuring your system is up-to-date.

Step 2. Installing FirewallD on CentOS 7.

Firewalld is installed by default on CentOS 7, but if it is not installed on your system, you can execute the following command for its installation:

After you install firewalld, you can enable the service and reboot your server. Keep in mind that enabling firewalld will cause the service to start up at boot:

We can verify that the service is running and reachable by typing:

Step 3. Setup and configuration of FirewallD on CentOS 7.

FirewallD uses services and zones instead of iptables rules and chains. By default the following zones are available:

  • drop – Drop all incoming network packets with no reply, only outgoing network connections are available.
  • block – Reject all incoming network packets with an icmp-host-prohibited message, only outgoing network connections are available.
  • public – Only selected incoming connections are accepted, for use in public areas
  • external For external networks with masquerading is enabled, only selected incoming connections are accepted.
  • dmz – DMZ demilitarized zone, publicly-accessible with limited access to the internal network, only selected incoming connections are accepted.
  • work – For computers in your home area, only selected incoming connections are accepted.
  • home – For computers in your home area, only selected incoming connections are accepted.
  • internal -For computers in your internal network, only selected incoming connections are accepted.
  • trusted – All network connections are accepted.

To list all available zones run:

To list the default zone:

To change the default zone:

Example, here is how you can configure your VPS firewall with FirewallD if you were running a web server, SSH on port 8888 and mail server.

First we will set the default zone to dmz.

To add permanent service rules for HTTP and HTTPS to the dmz zone, run:

Since the SSH port is changed to 7022, we will remove the ssh service (port 22) and open port 8888

To implement the changes we need to reload the firewall with:

Finally, you can list the rules with:

Congratulation’s! You have successfully configure Firewall. Thanks for using this tutorial for installing firewalld on CentOS 7 system. For additional help or useful information, we recommend you to check the official firewalld website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get a best deal!