This article will demonstrate how to manage a firewall on a Redhat server. Firewall functions that will be covered include how to check the firewall status, start, stop, enable, and disable it. The examples below were performed on RHEL 8.x.
The default firewall on RHEL 8 is firewalld and is enabled by default. If your Redhat instance is on a local network protected by a perimeter firewall you may prefer to disable the local firewalld firewall. If the server is public you should strongly consider leaving the firewall enabled.
Redhat Firewall Status
The first step in managing the local Redhat firewall is to check its status. If it is a new instance, the status should be enabled by default. If you’re troubleshooting an issue on a server installed by a previous systems administrator, you should most definitely check the status first.
To check the RHEL firewall status, use the systemctl utility.
systemctl status firewalldThe output will show if the firewall is enabled. If it is enabled, it will automatically start after a reboot.
If the firewall is not running, you will see the following message.
* firewalld is not runningRedhat Firewall Rules
To display the rules configured in your firewall run the following command.
firewall-cmd --list-allRedhat Enable Firewall
To enable the firewall, run the following command.
systemctl enable firewalldDisable Firewall
To disable the firewall, run the following command.
systemctl disable firewalldStart Firewall
To start the firewall, run the following command.
systemctl start firewalldStop Firewall
To stop the firewall, run the following command.
systemctl stop firewalldfirewalld allow service
In the event you need to allow a specific service through the firewall without knowing the ports involved you can use the –add-service option. In this example, the samba service is allowed through temporarily.
firewall-cmd --add-service=sambaTo permanently allow the service through which will persist through a reboot, use the –permanent option.
firewall-cmd --add-service=samba --permanentAfter allowing the samba service you can test with the smbclient on the command line.
smbclient //samba.example.com/testshare -U misterpkiYou should no longer see this error message:
do_connect: Connection to samba.example.com failed (Error NT_STATUS_HOST_UNREACHABLE)If you do then double check that you properly allowed the samba service through the firewall.
firewalld list services
To show the services allowed through firewalld run this command.
firewall-cmd --list-servicesfirewalld list ports
To show the ports allowed through firewalld run this command.
firewall-cmd --list-portsConclusion
This article has demonstrated how to run various functions within firewalld in Redhat. We hope you have learned how to start, stop, enable, disable, and check the firewall status. Let us know in the comments if you have any questions or would like to see additional examples of how to manage a firewall in Linux. If you liked this post, check our additional articles we have written.
Leave a Reply