ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ECS云服务器防火墙设置

2020-11-28 17:01:02  阅读:181  来源: 互联网

标签:-- cmd 防火墙 firewalld firewall ECS 服务器 root localhost


阿里云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

标签:--,cmd,防火墙,firewalld,firewall,ECS,服务器,root,localhost
来源: https://blog.csdn.net/qq_42469759/article/details/110286597

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有