智者不为愚者谋,勇者不为怯者死。这篇文章主要讲述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、查看防火墙区域信息
【CentOS7 防火墙相关操作与端口配置 (收集+持续更新)】[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

文章图片
未完 —— 待续 !
推荐阅读
- 记一次Notepad++安装NppFTP连接Linux 系统(例如(Centos))
- 记一次Centos7 手动安装Mysql 5.7 数据库 (使用 Mysql的 rpm文件)
- Linux之ssh-copy-id命令
- 记一次Centos7安装使用PostWoman
- 记一次Centos7安装 lepus 天兔数据库监控系统 v3.8_beta
- 晋级TypeScript高手,成为抢手的前端开发人才
- 搭建并实现智能DNS
- 记一次 虚拟机 deepin 15.11 深度操作系统安装
- 记一次解决 Xshell 连接 Linux 系统,使用数字小键盘乱码问题