Centos7安装firewalld防火墙及常用的基本操作
侧边栏壁纸
  • 累计撰写 2 篇文章
  • 累计收到 0 条评论

Centos7安装firewalld防火墙及常用的基本操作

haha
2025-02-06 / 0 评论 / 13 阅读 / 正在检测是否收录...
  1. 如果centos7有安装iptables防火墙及其他防火墙先关掉或者卸载掉,没有就忽略。
    关闭iptables

    systemctl stop iptables

    安装firewalld

    yum install -y firewalld

    开启防火墙

    systemctl start firewalld

    查看防火墙状态

    systemctl status firewalld

    重启防火墙

    systemctl restart firewalld

    设置防火墙开机自启

    systemctl enable firewalld

    关闭防火墙开机自启

    systemctl disable firewalld
  2. 查看预定义区域

    firewall-cmd --get-zones

    查看每个区域的详细信息

    firewall-cmd --list-all-zones

    区域简介:

    区域默认规则
    block拒绝流入的流量,除非与流出的流量相关
    dmz拒绝流入的流量,除非与流出的流量相关;如果流量与ssh服务相关,则允许流量
    drop拒绝流入的流量,除非与流出的流量相关
    external拒绝流入的流量;除非与流出的流量相关;如果流量与ssh服务相关,则允许流量
    home拒绝流入的流量;除非与流出的流量相关;如果流量与ssh,mdns,ipp-client,amba-client,dhcpv6-client服务相关,则允许流量
    internal等同于home区域
    public拒绝流入的流量;除非与流出的流量相关;如果流量与ssh,dhcpv6-client服务相关,则允许流量
    trusted允许所有的数据包流入与流出
    work拒绝流入的流量;除非与流出的流量相关;如果流量与ssh,ipp-client,dhcpv6-client服务相关,则允许流量
  3. 创建自定义区域

    firewall-cmd --permanent --new-zone=testing

    注意: --permanent选项不能少

  4. 查看默认区域

    firewall-cmd --get-default-zone

    查看网卡关联的区域

    firewall-cmd --get-zone-of-interface=eth0

    注意: 一张网卡只能关联一个区域

  5. 修改默认区域

    # #修改默认区域为`trusted`
    # firewall-cmd --set-default-zone=trusted 
    success
    # firewall-cmd --get-default-zone 
    trusted
    # firewall-cmd --get-zone-of-interface=eth0
    trusted
    # #还原
    # firewall-cmd --set-default-zone=public 
    success
    # firewall-cmd --get-default-zone 
    public
    # firewall-cmd --get-zone-of-interface=eth0
    public

    修改网卡关联的区域
    方法1:先删除现有关联区域,再添加目标关联区域(因为同一时间,一张网卡只能关联一个区域,所以要先添加再删除)

    # firewall-cmd --remove-interface=eth0 --zone=public
    success
    # firewall-cmd --get-zone-of-interface=eth0
    no zone
    ## 设置eth0关联区域为trusted
    # firewall-cmd --add-interface=eth0 --zone=trusted
    success
    # firewall-cmd --get-zone-of-interface=eth0
    trusted

    方法2:

    ## 设置eth0关联区域为public
    # firewall-cmd --change-interface=eth0 --zone=public
    success
    # firewall-cmd --get-zone-of-interface=eth0
    public

    查看当前活动区域及绑定的接口和源

    # firewall-cmd --get-active-zones
    public
      interfaces: eth0
0

评论 (0)

取消