阿里云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
目录
相关文章
|
Linux Shell
在Linux、CentOS7中设置shell脚本开机自启动服务
以上就是在CentOS 7中设置shell脚本开机自启动服务的全部步骤。希望这个指南能帮助你更好地管理你的Linux系统。
2366 25
|
Web App开发 运维 Linux
破防了!原来CentOS联网设置竟藏在这个路径?网友:5年运维都白干了!
默认情况下,新装的 CentOS 无法直接上网。可通过点击桌面右上角的网络图标,启动 `eth0` 连接网络。为实现自动连接,右键该图标选择“编辑连接”,在 `System eth0` 设置中勾选“自动连接”。这样配置后,系统重启也能自动联网。
597 19
破防了!原来CentOS联网设置竟藏在这个路径?网友:5年运维都白干了!
|
Kubernetes Ubuntu Linux
阿里云服务器使用centos还是ubuntu?
在选择阿里云服务器操作系统时,CentOS和Ubuntu各有优势。CentOS以企业级稳定性著称,适合数据库、ERP等长期稳定需求;而Ubuntu开发者友好,支持最新硬件与功能,更适合开发/测试环境及云计算场景。两者在阿里云上均有官方镜像支持,性能差异可忽略。无特殊需求时推荐Ubuntu 22.04 LTS,若需RHEL生态则选AlmaLinux。根据实际需求、团队技术栈及场景灵活决策,阿里云还支持更换系统盘降低试错成本。
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
1637 2
|
安全 Linux 网络安全
centos7中firewall防火墙的常用命令总结
以上命令集覆盖了 `firewalld`的基本操作,是维护CentOS 7系统安全不可或缺的工具。对于更高级的配置需求或遇到特定问题
842 3
|
Linux
CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
1747 1
|
XML 应用服务中间件 Linux
在一个centos服务器上同时部署tomcat,django,flask
在一个centos服务器上同时部署tomcat,django,flask
405 0
|
数据采集 弹性计算 网络协议
[CentOS Python系列] 一.阿里云服务器安装部署及第一个Python爬虫代码实现
本文将详细讲解阿里云服务器如何安装及部署本地Python环境,并搭建代码。
2175 1
[CentOS Python系列] 一.阿里云服务器安装部署及第一个Python爬虫代码实现
|
Java 应用服务中间件 Linux
Centos7云服务器部署Tomcat
Centos7云服务器部署Tomcat
Centos7云服务器部署Tomcat
|
弹性计算 Java Linux
CentOS7系统云服务器Java Web环境镜像部署操作演示
本篇文档介绍如何在ECS实例上使用镜像部署Java Web环境。
3014 0