官方链接:https://www.linode.com/docs/security/firewalls/introduction-to-firewalld-on-centos/#installing-and-managing-firewalld
安装和管理FirewallD
sudo systemctl start firewalld
sudo systemctl enable firewalld
sudo systemctl stop firewalld
sudo systemctl disable firewalld
- 检查防火墙状态。输出应该说running或者not running
sudo firewall-cmd --state
sudo systemctl status firewalld
- 显示示例
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
Active:active (running) since Wed 2015-09-02 18:03:22 UTC; 1min 12s ago
Main PID: 11954 (firewalld)
CGroup: /system.slice/firewalld.service
└─11954 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
sudo firewall-cmd --reload
配置集永久链接
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --add-service=http
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --reload
防火墙区
sudo firewall-cmd --get-default-zone
sudo firewall-cmd --set-default-zone=internal
sudo firewall-cmd --get-active-zones
public
interfaces: eth0
sudo firewall-cmd --zone=public --list-all
- 示例输出
- 要获取所有区域的所有配置:
sudo firewall-cmd --list-all-zones
使用服务
sudo firewall-cmd --get-services
sudo firewall-cmd --zone=public --add-service=http --permanent
sudo firewall-cmd --zone=public --remove-service=http --permanent
sudo firewall-cmd --zone=public --add-port=12345/tcp --permanent
sudo firewall-cmd --zone=public --remove-port=12345/tcp --permanent