zoukankan      html  css  js  c++  java
  • 22.firewalld

    1.firewalld 中常用的区域名称及策略规则

      

    2.firewalld-cmd 命令中使用的参数以及作用

      

      与 Linux 系统中其他的防火墙策略配置工具一样,使用firewalld 配置的防火墙策略默认为运行时(Runtime)模式,又称为当前生效模式,而且随着系统的重启会失效。

      如果想让配置策略一直存在,就需要使用永久(Permanent)模式了,方法就是在用firewall-cmd 命令正常设置防火墙策略时添加--permanent 参数,这样配置的防火墙策略就可以永久生效了。

      但是,永久生效模式有一个“不近人情”的特点,就是使用它设置的策略只有在系统重启之后才能自动生效。如果想让配置的策略立即生效,需要手动执行firewall-cmd --reload 命令。

      查看 firewalld 服务当前所使用的区域:  

    [root@centos ~]# firewall-cmd --get-default-zone
    public

      查询ens33 网卡在firewalld 服务中的区域  

    [root@centos ~]# firewall-cmd --get-zone-of-interface=ens33 
    public  

      把 firewalld 服务中ens33 网卡的默认区域修改为external,并在系统重启后生效。分别查看当前与永久模式下的区域名称:  

    [root@centos ~]# firewall-cmd --permanent --zone=external --change-interface=ens33 
    success
    [root@centos ~]# firewall-cmd --get-zone-of-interface=ens33
    external
    [root@centos ~]# firewall-cmd --permanent --get-zone-of-interface=ens33
    no zone

      把 firewalld 服务的当前默认区域设置为public:  

    root@centos ~]# firewall-cmd --set-default-zone=public
    success
    [root@centos ~]# firewall-cmd --get-default-zone 
    public  

      启动/关闭firewalld 防火墙服务的应急状况模式,阻断一切网络连接(当远程控制服务器时请慎用):  

    [root@centos ~]# firewall-cmd --panic-on
    success
    [root@centos ~]# firewall-cmd --panic-off 
    success

      查询 public 区域是否允许请求SSH 和HTTPS 协议的流量:  

    [root@centos ~]# firewall-cmd --zone=public --query-service=ssh
    yes
    [root@centos ~]# firewall-cmd --zone=public --query-service=https
    no

      把 firewalld 服务中请求HTTPS 协议的流量设置为永久允许,并立即生效:  

    [root@centos ~]# firewall-cmd --zone=public --add-service=https
    success
    [root@centos ~]# firewall-cmd --permanent --zone=public --add-service=https
    success
    [root@centos ~]# firewall-cmd --reload
    success

      把 firewalld 服务中请求HTTP 协议的流量设置为永久拒绝,并立即生效:  

    [root@centos ~]# firewall-cmd --permanent --zone=public --remove-service=http
    Warning: NOT_ENABLED: http
    success
    [root@centos ~]# firewall-cmd --reload 
    success

      把在firewalld 服务中访问8080 和8081 端口的流量策略设置为允许,但仅限当前生效:  

    [root@centos ~]# firewall-cmd --zone=public --add-port=8080-8081/tcp
    success
    [root@centos ~]# firewall-cmd --zone=public --list-ports
    8080-8081/tcp

      把原本访问本机 888 端口的流量转发到22 端口,要且求当前和长期均有效:

      流量转发命令格式为 firewall-cmd --permanent --zone=<区域> --add-forward-port=port=<源端口号>:proto=<协议>:toport=<目标端口号>:toaddr=<目标IP 地址>  

    [root@centos ~]# firewall-cmd --permanent --zone=public --add-forward-port=port=888:proto=tcp:toport=22:toaddr=192.168.10.10
    success
    [root@centos ~]# firewall-cmd --reload 
    success

      firewalld 中的富规则表示更细致、更详细的防火墙策略配置,它可以针对系统服务、端口号、源地址和目标地址等诸多信息进行更有正对性的策略配置。它的优先级在所有的防火墙策略中也是最高的。

      比如,我们可以在firewalld 服务中配置一条富规则,使其拒绝192.168.10.0/24 网段的所有用户访问本机的ssh 服务(22 端口):  

    [root@centos ~]# firewall-cmd --permanent --zone=public --add-rich-rule="
    rule family="ipv4" source address="192.168.10.0/24" service name="ssh" reject"
    success
    [root@centos ~]# firewall-cmd --reload
    success

      在客户端使用 ssh 命令尝试访问192.168.10.10 主机的ssh 服务(22 端口):  

    [root@client A ~]# ssh 192.168.10.10
    Connecting to 192.168.10.10:22...
    Could not connect to '192.168.10.10' (port 22): Connection failed.
  • 相关阅读:
    Basic knowledge of html (keep for myself)
    科学技术法转成BigDemcial
    SimpleDateFormat
    log4j 配置实例
    R 实例1
    yield curve
    if-else的优化举例
    十二、高级事件处理
    十一、Swing
    十、输入/输出
  • 原文地址:https://www.cnblogs.com/xinghen1216/p/13561232.html
Copyright © 2011-2022 走看看