How To Set Up a Firewall Using FirewallD on CentOS 7
How To Set Up a Firewall Using FirewallD on CentOS 7
Introduction
Firewalls are an essential part of any secure network infrastructure. They help to prevent unauthorized access to your system and protect it from malicious attacks. In this tutorial, we will show you how to set up and configure a firewall on CentOS 7 using FirewallD.
Prerequisites
- A server running CentOS 7
- Root access or a user with sudo privileges
Step 1: Install FirewallD
The first step is to install FirewallD if it is not already installed on your system. To do this, run the following command:
sudo yum install firewalld
Step 2: Start and Enable FirewallD
Once FirewallD is installed, start and enable it so that it starts automatically at boot time:
sudo systemctl start firewalld
sudo systemctl enable firewalld
Step 3: Check FirewallD Status
To check the status of FirewallD, run the following command:
sudo firewall-cmd --state
If FirewallD is running, you will see the following output:
running
Step 4: Configure FirewallD
Now that FirewallD is running, you can start configuring it to allow or deny traffic based on your requirements. The following are some examples of common FirewallD commands:
- Allow incoming traffic on a specific port:
- Deny incoming traffic on a specific port:
- List all available services:
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --zone=public --remove-port=22/tcp --permanent
sudo firewall-cmd --get-services
Remember to use the --permanent flag if you want to make the changes persistent across reboots.
Step 5: Reload FirewallD
After making any changes to the FirewallD configuration, you must reload the service to apply the changes:
sudo firewall-cmd --reload
Комментарии
Отправить комментарий