Skip to content

Firewall-cmd

查看防火墙状态

Terminal window
systemctl status firewalld

开启防火墙,设置开机自动启动

Terminal window
systemctl start firewalld
systemctl enable firewalld

关闭防火墙,设置开机不自动启动

Terminal window
systemctl stop firewalld
systemctl disable firewalld

开放端口

开启 8080 端口

Terminal window
firewall-cmd --zone=public --add-port=8080/tcp --permanent

--permanent 设置永久生效,否则重启后将失效。

重新载入防火墙设置,使之生效

Terminal window
firewall-cmd --reload

查询端口是否开放

Terminal window
firewall-cmd --zone=public --query-port=8080/tcp

查看打开的所有端口

Terminal window
firewall-cmd --zone=public --list-ports

查看当前系统防火墙所有设置

Terminal window
firewall-cmd --list-all

批量操作

Terminal window
firewall-cmd --zone=public --add-port=10000-10100/tcp --permanent
firewall-cmd --reload

限制端口

Terminal window
firewall-cmd --zone=public --remove-port=8080/tcp --permanent

--permanent 设置永久生效,否则重启后将失效。

重新载入防火墙设置,使之生效

Terminal window
firewall-cmd --reload

批量操作

Terminal window
firewall-cmd --zone=public --remove-port=10000-10100/tcp --permanent
firewall-cmd --reload