CentOS 防火墙入门

CentOS7 以下的版本默认使用 iptables 做为防火墙,CentOS 7开始默认使用的是firewall作为防火墙

本文使用的系统是 CentOS7,所以下面讲解的是firewall的操作。

 

 1. 查看防火墙是否开启

firewall-cmd --state

默认是没开启的状态,如下图

 

 

 

2. 查看firewalld状态/开启/关闭/重启/开机自启动

systemctl start firewalld.service //开启
systemctl status firewalld // 查看状态
systemctl enable firewalld // 开机自启动
systemctl stop firewalld // 关闭

 

3. 查看防火墙规则

如果要查看iptables目前运行的规则,使用iptables -L可以列出

- 查看对外网电脑防火墙列外的端口号
firewall-cmd --zone=public --list-ports 

 

4. 设置规则

– 开放指定端口
firewall-cmd --zone=public --add-port=1936/tcp --permanent

– 关闭指定端口
firewall-cmd --zone=public --remove-port=1936/tcp --permanent
– 重启防火墙 firewall
-cmd --reloadl

 

相关链接:

https://www.linuxprobe.com/chapter-08.html

posted @ 2022-01-02 18:14  Ryan_zheng  阅读(96)  评论(0编辑  收藏  举报