Centos7.7firewalld安装与使用

firewall 防火墙服务简述

1、Centos7 默认的防火墙是 firewall===Centos6 iptables

2、firewall 使用更加方便、功能也更加强大一些

3、firewalld 服务引入了一个信任级别的概念来管理与之相关联的连接与接口。它支持 ipv4ipv6,并支持网桥,采用 firewall-cmd (command)firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则,并实时生效而无需重启服务。

firewall 防火墙安装

1.需要注意的是某些系统已经自带了 firewal l的,如果查看版本没有找到,则可以进行 yum 安装

2.安装指令:

[root@firewalld ~]# yum -y install firewalld

3.查看 firewall 版本

[root@firewalld ~]# firewall-cmd --version
0.6.3

firewalld 服务基本使用

#查看防火墙状态
[root@firewalld ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-05-13 15:22:56 CST; 1min 45s ago
     Docs: man:firewalld(1)
 Main PID: 6129 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─6129 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

May 13 15:22:56 firewalld systemd[1]: Starting firewalld - dynamic firewall.....
May 13 15:22:56 firewalld systemd[1]: Started firewalld - dynamic firewall ...n.
May 13 15:22:56 firewalld firewalld[6129]: WARNING: AllowZoneDrifting is ena....
Hint: Some lines were ellipsized, use -l to show in full.

#关闭防火墙,停止 firewall 服务
[root@firewalld ~]# systemctl stop firewalld

#开启防火墙,启动 firewall 服务
[root@firewalld ~]# systemctl start firewalld

#重启防火墙,重启 firewall 服务
[root@firewalld ~]# systemctl restart firewalld

#查看 firewall 服务是否开机启动
[root@firewalld ~]# systemctl is-enabled firewalld
disabled

#开机时自动启动 firewall 服务
[root@firewalld ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.

#开机时自动禁用 firewall 服务
[root@firewalld ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

firewalld-cmd 防护墙命令使用

上面所说的 firewall 可以看成整个防火墙服务,而 firewall-cmd 可以看成是其中的一个功能,可用来管理端口

1.查看 firewall-cmd 状态

#即查看 `firewall` 防火墙程序是否正在运行: `firewall-cmd --state`
[root@firewalld ~]# firewall-cmd --state
running

2.查看已打开的所有端口

[root@firewalld ~]# firewall-cmd --zone=public --list-ports

3.开启指定端口

#开启防火墙,无法访问apache
[root@firewalld ~]# systemctl start firewalld

在这里插入图片描述

#开启80端口  --permanent 永久生效,没有此参数重启后失效
[root@firewalld ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success

#重新加载 firewall,修改配置后,必须重新加载才能生效
[root@firewalld ~]# firewall-cmd --reload
success

#开到80端口已开启
[root@firewalld ~]# firewall-cmd --zone=public --list-ports
80/tcp

在这里插入图片描述

4.关闭指定端口

#查看已开启的端口
[root@firewalld ~]# firewall-cmd --zone=public --list-ports
80/tcp

#关闭80端口  --permanent 表示永久生效,没有此参数重启后失效
[root@firewalld ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent success
[root@firewalld ~]# firewall-cmd --reload
success

#查看已打开的端口
[root@firewalld ~]# firewall-cmd --zone=public --list-ports

[root@firewalld ~]#

在这里插入图片描述

public.xml 文件修改防火墙端口(直接修改也是可以的)

#已开启端口列表是空的时候 配置文件也没有
[root@firewalld ~]# firewall-cmd --zone=public --list-ports

[root@firewalld zones]# cat public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
</zone>

#添加一个端口时  配置文件也有
[root@firewalld zones]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@firewalld zones]# cat public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <port protocol="tcp" port="80"/>
</zone>

注意事项(阿里云)

1、CentOS 7.7 系统防火墙明明开启了指定的端口,tomcat服务器端口也指定正确,启动没有任何问题,最后从浏览器访问的时候,却只有80端口有效,其余的端口全部访问失败

[root@aly bin]# firewall-cmd --zone=public --list-ports
8080/tcp 80/tcp

在这里插入图片描述
2、最后原因居然是因为系统是阿里云服务器,而它的后台为了安全,封掉了其它端口的访问,所以即使防火墙修改了也没用,解决办法是登录阿里云服务器后台,修改它的安全组策略即可。

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生解决方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值