Firewalld
Jump to navigation
Jump to search
Firewalld is the default firewall for CentOS 7. It replaces the CentOS 6 firewall, iptables.
Using firewalld
Starting and stopping firewalld:
systemctl start firewalld systemctl stop firewalld
Listing current configuration for firewalld:
sudo firewall-cmd --list-all
Permitting a service through firewall (opens port that corresponds with service):
sudo firewall-cmd --zone=public --add-service=<service-name> --permanent
Opening a specific TCP/UDP port:
sudo firewall-cmd --add-port=<port number>/<tcp or udp> --permanent
Example: adding NFS to firewalld
sudo firewall-cmd --zone=public --add-service=nfs --permanent sudo firewall-cmd --zone=public --add-service=rpc-bind --permanent sudo firewall-cmd --zone-public --add-service=mountd --permanent
Example: adding tcp port 8080 to firewalld
sudo firewall-cmd --add-port=8080/tcp --permanent
Reload the firewall after adding services to the firewall configuration:
sudo firewall-cmd --reload
How to Add/Remove Rich Rule
Add
firewall-cmd --permanent --add-rich-rule=
Here's an example to reject all connection from the 34.0.0.0 subnet:
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="34.0.0.0/8" reject'
Remove
firewall-cmd --permanent --remove-rich-rule=
Example:
firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="34.0.0.0/8" reject'