阿里云ECS服务器CentOS7防火墙firewalld设置

阿里云ECS服务器CentOS7防火墙firewalld设置
----------------------------------------------
 
使用root登录
 
1.确保服务器系统处于最新状态
[root@localhost ~]# yum -y update
如果显示以下内容说明已经更新完成
Complete!
 
2.重启服务器
[root@localhost ~]# reboot
 
3.安装防火墙
[root@localhost ~]# yum install firewalld
 
4.设置在开机时启用防火墙服务
[root@localhost ~]# systemctl enable firewalld.service
 
4.查看防火墙状态
[root@localhost ~]# systemctl status firewalld
 
5.启动防火墙
[root@localhost ~]# systemctl start firewalld
 
6.增加80端口到防火墙规则
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
 
7.增加3306端口到防火墙规则
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
 
8.增加21端口到防火墙规则
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=21/tcp
 
9.增加33000端口到防火墙规则
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=33000-33003/tcp
 
10.设置HTTP协议服务被允许
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http
 
11.使最新的防火墙设置规则生效
[root@localhost ~]# firewall-cmd --reload
 
12.重启防火墙服务
[root@localhost ~]# systemctl restart firewalld.service
 
 
--------------------------------------------------------
 
firewalld的基本使用
 
# 使最新的防火墙设置规则生效
[root@localhost ~]# firewall-cmd --reload 
 
# 查询ssh协议服务是否被允许
[root@localhost ~]# firewall-cmd --zone=public --query-service=ssh
 
# 查询HTTP协议服务是否被允许
[root@localhost ~]# firewall-cmd --zone=public --query-service=http
 
# 启动
[root@localhost ~]# systemctl start firewalld
 
# 查看状态
[root@localhost ~]# systemctl status firewalld 
 
# 停止
[root@localhost ~]# systemctl disable firewalld
 
# 禁用
[root@localhost ~]# systemctl stop firewalld 
 
#启动服务
[root@localhost ~]# systemctl start firewalld.service
 
# 关闭服务
[root@localhost ~]# systemctl stop firewalld.service
 
# 重启服务
[root@localhost ~]# systemctl restart firewalld.service
 
# 显示一个服务的状态
[root@localhost ~]# systemctl status firewalld.service
 
# 在开机时启用一个服务
[root@localhost ~]# systemctl enable firewalld.service
 
# 在开机时禁用一个服务
[root@localhost ~]# systemctl disable firewalld.service
 
# 查看服务是否开机启动
[root@localhost ~]# systemctl is-enabled firewalld.service
 
# 查看已启动的服务列表
[root@localhost ~]# systemctl list-unit-files|grep enabled
 
# 查看启动失败的服务列表
[root@localhost ~]# systemctl --failed
 
# 查看版本
[root@localhost ~]# firewall-cmd --version
 
# 查看帮助
[root@localhost ~]# firewall-cmd --help
 
# 显示状态
[root@localhost ~]# firewall-cmd --state
 
# 查看所有打开的端口
[root@localhost ~]# firewall-cmd --zone=public --list-ports
 
# 更新防火墙规则
[root@localhost ~]# firewall-cmd --reload
 
# 查看区域信息
[root@localhost ~]# firewall-cmd --get-active-zones
 
# 查看指定接口所属区域
[root@localhost ~]# firewall-cmd --get-zone-of-interface=eth0
 
# 拒绝所有包
[root@localhost ~]# firewall-cmd --panic-on
 
# 取消拒绝状态
[root@localhost ~]# firewall-cmd --panic-off
 
# 查看是否拒绝
[root@localhost ~]# firewall-cmd --query-panic
 
# 端口添加(--permanent永久生效,没有此参数重启后失效)
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp
 
# 使最新的防火墙设置规则生效
[root@localhost ~]# firewall-cmd --reload 
 
# 查看80端口
[root@localhost ~]# firewall-cmd --zone=public --query-port=80/tcp
 
# 删除80端口
[root@localhost ~]# firewall-cmd --permanent --zone=public --remove-port=80/tcp
 
# 删除21端口
[root@localhost ~]# firewall-cmd --permanent --zone=public --remove-port=21/tcp
 
# 删除HTTP协议服务
[root@localhost ~]# firewall-cmd --permanent --zone=public --remove-service=http
 
# 增加3306端口到防火墙规则tcp
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
 
# 增加3306端口到防火墙规则udp
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=3306/udp
 
# 查看当前的区域
[root@localhost ~]# firewall-cmd --get-default-zone
 
# 查看当前的服务
[root@localhost ~]# firewall-cmd --zone=public --list-services
 
# 安装图形化用户接口工具 firewall-config,则以 root 用户身份运行下列命令
[root@localhost ~]# yum install firewall-config
 
# 检查防火墙版本
[root@localhost ~]# firewall-cmd --version
 
# 查看帮助
[root@localhost ~]# firewall-cmd --help

猜你喜欢

转载自www.cnblogs.com/zjhssj/p/11847347.html