• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to Configure and Manage Firewall with FirewallD in Linux

683

To Configure and Manage Firewall with FirewallD in Linux

Firewalld helps you to configure dynamic firewall rules in Linux, which can be applied without the requirement of firewall restart and it also supports D-BUS and zone concepts that makes configuration simple and easy. The following article helps you to Configure and Manage Firewall with Useful FirewallD Rules in Linux.

First run the following command to verify whether firewalld service is enabled or not.

[root@linuxhelp ~]# systemctl status firewalld

firewalld service

Now we know that it is running, next check all the active zones and services.

[root@linuxhelp ~]# firewall-cmd --get-active-zones
[root@linuxhelp ~]# firewall-cmd --get-services

active zones

To manage firewalld you need to install GUI package in your system.

[root@linuxhelp ~]# yum install firewalld firewall-config

To list all active services, ports and rich rules for public zone use the following command.

[root@linuxhelp ~]# firewall-cmd --zone=public --list-all

active services list

Add and Remove Ports in Firewalld

To open any port for public zone use the below command.

[root@linuxhelp ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp

In order to remove the added port, use the --remove option along with firewalld command.

[root@linuxhelp ~]# firewall-cmd --zone=public --remove-port=80/tcp

Now confirm whether the port is added or removed by using the option, --list-ports.

[root@linuxhelp ~]# firewall-cmd --zone=public --list-ports

active zone

remove

Add and Remove Services in Firewalld

The following command will add the service.

[root@linuxhelp ~]# firewall-cmd --zone=public --add-service=ftp

To remove the services, run the following command.

[root@linuxhelp ~]# firewall-cmd --zone=public --remove-service=ftp

Execute the below command to list the services.

[root@linuxhelp ~]# firewall-cmd --zone=public --list-services

services list

Block Incoming and Outgoing Packets

You can block any incoming or outgoing connections by using panic-on mode.

[root@linuxhelp ~]# firewall-cmd --panic-on

Now verify whether the panic mode is ON using query-panic option

[root@linuxhelp ~]# ping google.com -c 1
[root@linuxhelp ~]# firewall-cmd --query-panic

query panic option

Disable the panic mode, then once again ping and check.

[root@linuxhelp ~]# firewall-cmd --query-panic
[root@linuxhelp ~]# firewall-cmd --panic-off
[root@linuxhelp ~]# ping google.com -c 1

panic mode

To Masquerade IP Address

Masquerade allows a computer to connect with internet by using the base machine. Verify whether Masquerade is enabled for external zone.

[root@linuxhelp ~]# firewall-cmd --zone=external --query-masquerade

You can enable with the following command.

[root@linuxhelp ~]# firewall-cmd --zone=external --add-masquerade

Now forward all ssh port 22 connections to port 2222 for IP address 192.168.0.132.

[root@linuxhelp ~]# firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=2222:toaddr=192.168.0.132
[root@linuxhelp ~]# firewall-cmd --zone=external --list-all

ssh port

To Block and Enable ICMP

Check the type of ICMP with the below command.

[root@linuxhelp ~]# firewall-cmd --get-icmptypes

Use the following command to add icmp block on any zone.

[root@linuxhelp ~]# firewall-cmd --zone=public --query-icmp-block=echo-reply

If you get ‘ no‘ then enable it using the following command.

[root@linuxhelp ~]# firewall-cmd --zone=public --add-icmp-block=echo-reply

icmp blocks

Add/Remove Chain using Direct Interface

To add a Custom direct interface rule, use the option, --direct. Before that make sure to list all the current rules in public zone use --get-rules.

[root@linuxhelp ~]# irewall-cmd --direct --get-rules ipv4 filter IN_public_allow

To add the rules use --add-rules

[root@linuxhelp ~]# firewall-cmd --direct --add-rule ipv4 filter IN_public_allow 0 -m tcp -p tcp --dport 25 -j ACCEPT

To remove the rules use --remove-rule

[root@linuxhelp ~]# firewall-cmd --direct --remove-rule ipv4 filter IN_public_allow 0 -m tcp -p tcp --dport 25 -j ACCE

firewall

Firewalld Lockdown Rules

To protect the firewalld from any unwanted changes by any applications, put a lock-down in firewalld.conf file.

[root@linuxhelp ~]# vim /etc/firewalld/firewalld.conf

Now change Lockdown= yes

firewalld

To make permanent changes reload the changes made using --reload.

[root@linuxhelp ~]# firewall-cmd --reload

Make sure to verify whether firewalld was lockdown using query.

[root@linuxhelp ~]# firewall-cmd --query-lockdown

To On/Off lockdown mode, use the following lines.

[root@linuxhelp ~]# firewall-cmd --lockdown-on
[root@linuxhelp ~]# firewall-cmd --lockdown-off

editor

Enable Fail2ban-firewalld Support

To enable support of fail2ban in firewalld, install the package named fail2ban-firewalld by enabling epel repository under RHEL/CentOS systems.

Install the fail2ban-firewalld package using the following command.

[root@linuxhelp ~]# yum install fail2ban-firewalld -y

fail2ban firewalld
Next start the fail2ban service and also enable it to make it persistent.

[root@linuxhelp ~]# systemctl start fail2ban
[root@linuxhelp ~]# systemctl enable fail2ban

fail2ban

Adding & Blocking IP Addresses

To add specific IP address such as 192.168.0.254 to public zone, use the following command

[root@linuxhelp ~]# firewall-cmd --zone=public --add-rich-rule=' rule family=" ipv4"  source address=" 192.168.0.254"  accept' 

Use the following command to list all the trusted public zone rules.

[root@linuxhelp ~]# firewall-cmd --zone=public --list-all

To remove any added rule, use --remove-rich-rule as show below.

[root@linuxhelp ~]# firewall-cmd --zone=public --remove-rich-rule=' rule family=" ipv4"  source address=" 192.168.0.254"  accept' 

added rule

To reject an IP address use reject option as shown below

[root@linuxhelp ~]# firewall-cmd --zone=public --add-rich-rule=' rule family=" ipv4"  source address=" 192.168.0.250"  reject' 
[root@linuxhelp ~]# firewall-cmd --zone=public --list-all

IP address

Tags:
mason
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

How to install "firewalld" package manually on CentOS?

A

Use the following command to install "firewalld" on CentOS, "yum install firewalld".

Q

How can I display the all available zone in "firewalld"?

A

You can use the following command to get display the all available zones in "Firewalld"

Q

How can I access the firewall setup on GUI in centos?

A

Yes, you can access the firewall setup in GUI on CentOS as got to the "Application-> sundry -> firewall"

Q

How to add the "ssh" service in permanently "firewalld"?

A

You can use the following syntax to add the "ssh" service in permanently "firewalld". For syntax: "firewall-cmd --permanent --zone=public --remove-service=ssh".

Q

How can I review the current Rules defined in "iptables"?

A

You can runt the following command to review the current Rules defined in "iptables". For syntax: "iptables -L".

Related Tutorials in How to Configure and Manage Firewall with FirewallD in Linux

Related Tutorials in How to Configure and Manage Firewall with FirewallD in Linux

How to Install IPFire in Linux
How to Install IPFire in Linux
May 31, 2016
How to install ipcop
How to install ipcop
Jul 25, 2016
How to Configure Static NAT on Fortigate firewall
How to Configure Static NAT on Fortigate firewall
Feb 4, 2021
How To Install FireStarter in Debian
How To Install FireStarter in Debian
May 21, 2016
How to install OPNSense
How to install OPNSense
Jul 21, 2016
How to install NAXSI Web Application Firewall on Centos7
How to install NAXSI Web Application Firewall on Centos7
Jan 7, 2019
How to manage Ubuntu firewall using UFW commands
How to manage Ubuntu firewall using UFW commands
Aug 3, 2017
How to configure Interface, Address, and Firewall Policy on Fortigate in CLI Mode
How to configure Interface, Address, and Firewall Policy on Fortigate in CLI Mode
Feb 10, 2021

Related Forums in How to Configure and Manage Firewall with FirewallD in Linux

Related Forums in How to Configure and Manage Firewall with FirewallD in Linux

Firewall
kishore class=
How to check log for CSF firewall
Jan 2, 2018
Zentyal
ganeshkonka class=
Zentya 6.1 http proxy configuration
Jan 31, 2020
Firewall
wilson class=
How to block IP in firewalld command
Sep 23, 2017
Firewall
michael class=
What are the security firewalls for Linux
Feb 24, 2017
Firewall
aiden class=
How to enable and disable the firewall service in ubuntu
Mar 31, 2017
Firewall
landon class=
How to use firewall commands in ubuntu
Sep 8, 2017
Windows
grayson class=
How To turn off the Virus and threat Protection or Windws defender in Windows 7
Dec 19, 2019
Firewall
noah class=
Remove access to a port using firewall On CentOS8
Feb 19, 2021
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luk Van De Looverbosch ?
How to create a root ?

Hello,
How to create root@linuxhelp in Linux Mint 20.1 64-bit ?
Thanks in advance for your reply.
Best regards.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.