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

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

----------------------------------------------ssh

 

使用root登陆tcp

 

1.确保服务器系统处于最新状态工具

[root@localhost ~]# yum -y update阿里云

若是显示如下内容说明已经更新完成.net

Complete!rest

 

2.重启服务器接口

[root@localhost ~]# rebootrem

 

3.安装防火墙get

[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

相关文章
相关标签/搜索