CentOS7 防火墙相关操作与端口配置 (收集+持续更新)

一、防火墙 开启、关闭、查看状态

1、开启防火墙

[root@localhost ~]# systemctl start firewalld

2、关闭防火墙

[root@localhost ~]# systemctl stop firewalld

3、重启防火墙

[root@localhost ~]# systemctl start firewalld

4、查看防火墙当下的状态

[root@localhost ~]# systemctl status firewalld

5、开机自动启用防火墙

[root@localhost ~]# systemctl enable firewalld

6、开机默认禁用防火墙

[root@localhost ~]# systemctl disable firewalld

7、查看防火墙开机 启用/禁用 状态

[root@localhost ~]# systemctl is-enabled firewalld

8、查看系统当前启动服务的列表

[root@localhost ~]# systemctl list-unit-files|grep enabled

9、查看启动失败的服务列表

[root@localhost ~]# systemctl --failed

二、防火墙相关命令

1、查看防火墙版本

[root@localhost ~]# firewall-cmd --version

2、查看帮助

[root@localhost ~]# firewall-cmd --help

其余还有很多

3、查看示当前防火墙状态

[root@localhost ~]# firewall-cmd --state

4、查看当前防火墙打开的所有端口

[root@localhost ~]# firewall-cmd --zone=public --list-ports

5、更新防火墙规则

[root@localhost ~]# firewall-cmd --reload

6、查看防火墙区域信息

[root@localhost ~]# firewall-cmd --get-active-zones

7、查看指定接口所属区域

[root@localhost ~]# firewall-cmd --get-zone-of-interface=eth0

8、拒绝所有包  (慎用)

[root@localhost ~]# firewall-cmd --panic-on

9、取消 包拒绝状态

[root@localhost ~]# firewall-cmd --panic-off

10、查看包的拒绝状态

[root@localhost ~]# firewall-cmd --query-panic

三、firewall防火墙及端口设置

1、防火墙添加端口

[root@localhost ~]# firewall-cmd --zone=public(作用域) --add-port=80/tcp(端口和访问类型) --permanent(永久生效)

2、添加80端口

[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

(--permanent永久生效,没有此参数重启后失效)

3、重新载入防火墙配置

[root@localhost ~]# firewall-cmd --reload

4、查看指定端口状态

[root@localhost ~]# firewall-cmd --zone= public --query-port=80/tcp

5、防火墙移除指定端口

[root@localhost ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent

6、检查是否允许伪装IP

[root@localhost ~]# firewall-cmd --query-masquerade

7、允许防火墙伪装IP

[root@localhost ~]# firewall-cmd --add-masquerade

8、禁止防火墙伪装IP

[root@localhost ~]# firewall-cmd --remove-masquerade

9、开放mysql端口

[root@localhost ~]# firewall-cmd --add-service=mysql

10、阻止mysql端口

[root@localhost ~]# firewall-cmd --remove-service=mysql

11、查看开放的服务

[root@localhost ~]# firewall-cmd --list-services

12、开放通过tcp访问3306

[root@localhost ~]# firewall-cmd --add-port=3306/tcp

13、阻止通过tcp访问3306

[root@localhost ~]# firewall-cmd --remove-port=3306/tcp

14、开放通过udp访问233

15、开放通过udp访问233

[root@localhost ~]# firewall-cmd --add-port=233/udp

16、查看开放的端口

[root@localhost ~]# firewall-cmd --list-ports

17、端口转发

(1)80端口转发到8080(tomcat的默认端口为8080),443转发到8443(https配置的端口为8443)

[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080

[root@localhost ~]# firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8443

(2)将80端口的流量转发至192.168.11.11

[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toaddr=192.168.11.11

(3)将80端口的流量转发至192.168.11.11的8080端口

[root@localhost ~]# firewall-cmd --add-forward-port=port=80:proto=tcp:toaddr=192.168.11.11:toport=8080

 

 

未完 —— 待续 !

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值