`
wx1569466809
  • 浏览: 72148 次
文章分类
社区版块
存档分类
最新评论

Linux系统firewalld、zone、service

 
阅读更多

10.20 firewalld的9个zone

先执行以下操作切换至firewalld防火墙:

关闭iptables:
[root@adai003 ~]# systemctl disable iptables
Removed symlink /etc/systemd/system/basic.target.wants/iptables.service.
[root@adai003 ~]# systemctl stop iptables

开启firewalld:
[root@adai003 ~]# 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/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@adai003 ~]# systemctl start firewalld

注: 此时防火墙的规则已发生改变,可以使用命令iptables -nvL查看。

9种zone:

  • 查看zone类型:
[root@adai003 ~]# firewall-cmd --get-zones
work drop internal external trusted home dmz public block

关于9种zone的解析:

mark
注: 9个zone中内容分别保存着不同的规则!

  • 查看系统默认的zone:
[root@adai003 ~]# firewall-cmd --get-default-zone 
public

10.21 firewalld关于zone的操作

设置默认的zone

设置默认的zone:
[root@adai003 ~]# firewall-cmd --set-default-zone=work
success

查看:
[root@adai003 ~]# firewall-cmd --get-default-zone 
work

查看指定网卡的zone:

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

[root@adai003 ~]# firewall-cmd --get-zone-of-interface=lo
no zone

给指定网卡增加zone

可以通过以下两种方法为网卡添加zone:

方法1:

编辑网卡配置文件(复制系统网卡配置文件进行更名)的方法为其添加zone(配置完成后重启网络服务,并重新加载firewalld服务:“systemctl restart firewalld”)。

方法2:

[root@adai003 ~]# firewall-cmd --zone=work --add-interface=ens37
success
[root@adai003 ~]# firewall-cmd --get-zone-of-interface=ens37
work

给指定网卡更改zone

[root@adai003 ~]# firewall-cmd --zone=block --change-interface=ens37
success
[root@adai003 ~]# firewall-cmd --get-zone-of-interface=ens37
block

给指定网卡删除zone

[root@adai003 ~]# firewall-cmd --zone=bmz --remove-interface=ens37
The interface is under control of NetworkManager, setting zone to default.
success

[root@adai003 ~]# firewall-cmd --get-zone-of-interface=ens37
work

查看系统中所有网卡所在的zone

[root@adai003 ~]# firewall-cmd --get-active-zones 
work
  interfaces: ens37
public
  interfaces: ens33

10.22 firewalld关于service的操作

查看系统所有service

[root@adai003 ~]# firewall-cmd --get-services 

查看当前zone下的service

[root@adai003 ~]# firewall-cmd --list-services 
dhcpv6-client ssh

查看指定zone下的service

[root@adai003 ~]# firewall-cmd --zone=public --list-services 
dhcpv6-client ssh

添加一个服务到某个zone下

  • 临时添加(配置文件中不存在,重启会恢复原配置)
[root@adai003 ~]# firewall-cmd --zone=public --add-service=http
success
[root@adai003 ~]# firewall-cmd --zone=public --list-services 
dhcpv6-client ssh http
  • 永久添加(即,更改配置文件)
[root@adai003 ~]# firewall-cmd --zone=public --add-service=http --permanent

删除zone下某服务

  • 临时删除
删除前:
[root@adai003 ~]# firewall-cmd --zone=public --list-service
ftp dhcpv6-client ssh

[root@adai003 ~]# firewall-cmd --zone=public --remove-service=ftp
success
删除后:
[root@adai003 ~]# firewall-cmd --zone=public --list-service
dhcpv6-client ssh
  • 永久删除
[root@adai003 ~]# firewall-cmd --zone=public --list-service
ftp dhcpv6-client http ssh
[root@adai003 ~]# firewall-cmd --zone=public --remove-service=ftp --permanent 
success
[root@adai003 ~]# firewall-cmd --reload 
success
[root@adai003 ~]# firewall-cmd --zone=public --list-service
dhcpv6-client http ssh

配置文件

  • zone的系统配置文件位置:/etc/firewalld/zones/
[root@adai003 ~]# ls /etc/firewalld/zones/
public.xml  public.xml.old

[root@adai003 ~]# cat /etc/firewalld/zones/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="dhcpv6-client"/>
  <service name="http"/>
  <service name="ssh"/>
</zone>

说明: public.xml.old相当于一个备份文件,每次编辑public.xml时,系统会自动将原public.xml内容备份到public.xml.old。

  • zone配置文件模板
[root@adai003 ~]# ls /usr/lib/firewalld/zones/
block.xml  drop.xml      home.xml      public.xml   work.xml
dmz.xml    external.xml  internal.xml  trusted.xml
  • firewalld内各项服务的配置文件模板
[root@adai003 ~]# ls /usr/lib/firewalld/
icmptypes  ipsets  services  xmlschema  zones

注: 每次编辑配置文件后需要重新加载(reload)firewall-cmd才生效。

应用

需求:
ftp服务自定义端口1121,需要在work zone下面放行ftp。

方法:

步骤一:复制ftp的配置文件到/etc/firewalld/services/

[root@adai003 ~]# cp /usr/lib/firewalld/services/ftp.xml  /etc/firewalld/services/

步骤二:编辑该文件,将port="21"改为port="1121"

[root@adai003 ~]# vim /etc/firewalld/services/ftp.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>FTP</short>
  <description>FTP is a protocol used for remote file transfer. If you plan to make your FTP server publicly available, enable this option. You need the vsftpd package installed for this option to be useful.</description>
  <port protocol="tcp" port="1121"/>
  <module name="nf_conntrack_ftp"/>
</service>

步骤三:复制workzone的配置文件到/etc/firewalld/zones/

[root@adai003 ~]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/

步骤四:编辑该文件,增加“<service name="ftp"/>”

[root@adai003 ~]# vim /etc/firewalld/zones/work.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Work</short>
  <description>For use in work areas. You mostly 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"/>
  <service name="ftp"/>
</zone>

步骤五:重新加载

[root@adai003 ~]# firewall-cmd --reload 
success

Finished!

转载于:https://my.oschina.net/1995blog/blog/1594013

分享到:
评论

相关推荐

    linux系统安装jdk tomcat mysql

    ### Linux系统下安装JDK、Tomcat与MySQL详解 #### 一、安装JDK **1. 安装前准备** 在Linux系统中安装JDK之前,首先要确保系统已安装了必要的工具,如`vim`等文本编辑器,并且网络连接正常。 **2. 查看当前系统中...

    Linux系统firewall-cmd 命令详解.docx

    Linux 系统 firewall-cmd 命令详解 firewall-cmd 是 firewalld 的字符界面管理工具,firewalld 是 CentOS 7 的一大特性。firewalld 最大的好处有两个:支持动态更新,不用重启服务;第二个就是加入了防火墙的“zone...

    firewalld防火墙实操

    `firewalld` 是一种动态防火墙管理工具,在Linux系统中广泛使用。与传统的`iptables`相比,`firewalld`提供了更为灵活的服务和端口管理方式,并支持运行时配置更改而无需重启服务。 #### 二、基本概念 在使用`...

    Linux操作手册以及命令使用

    例如,`systemctl start firewalld.service`用于开启防火墙,`systemctl stop firewalld.service`用于关闭,`systemctl status firewalld.service`用于查看状态,`systemctl disable firewalld.service`用于禁止...

    Linux系统下Tomcat的安装详解.docx

    - 重启防火墙使设置生效:`systemctl restart firewalld.service` #### 四、总结 本文详细介绍了如何在Linux环境下安装与配置JDK及Tomcat的过程。通过以上步骤,你可以顺利地在Linux系统上搭建起Java Web应用的运行...

    CentOS防火墙学习教程

    防火墙关闭:使用 `systemctl stop firewalld.service` 命令可以停止防火墙,而 `systemctl disable firewalld.service` 命令可以禁止防火墙在系统启动时自动启动。 端口状态查看:使用 `firewall-cmd --zone=...

    linux系统常见命令.docx

    - `systemctl stop firewalld.service`: 停止防火墙服务 - `firewall-cmd --state`: 查看防火墙状态 - **端口监控**: - `netstat -lnpt`: 查看所有监听的端口 - `netstat -lnpt | grep 5672`: 检查特定端口是否...

    Centos8系统ftp安装与设置最终版.docx

    在 Linux 系统中,FTP 服务器可以通过安装 vsftpd 软件包来实现。在本文中,我们将介绍如何在 CentOS 8 系统中安装和设置 FTP 服务器。 一、安装 vsftpd 首先,我们需要安装 vsftpd 软件包。使用以下命令: `yum ...

    1、系统初始化1

    Iptables,例如:`systemctl stop firewalld && systemctl disable firewalld && yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables...

    linux之centos7防火墙基本使用详解

    Linux中的防火墙是系统安全的重要组成部分,特别是在 CentOS 7 中,使用的是 firewalld 作为默认的防火墙管理系统。firewalld 提供了一个动态防火墙,使得管理规则更加灵活和简便。下面我们将深入探讨 CentOS 7 中 ...

    Linux-FTP服务器详细配置

    [root@rdhtoracle11g ~]# systemctl restart firewalld.service ``` #### 五、再次测试客户端连接 重新尝试连接服务器: ```bash [root@localhost ~]# ftp 192.168.233.112 ``` 此时,如果一切配置正确,...

    linux常用命令整合

    - `/etc/rc.d/rc.local`:是 Linux 系统启动时执行的脚本之一。 - `/path/to/jws_script`:脚本的绝对路径,需要确保脚本具有执行权限。 #### 7. 防火墙添加端口 - **命令**: ```bash firewall-cmd --zone=...

    Linux(CentOS7)安装Tomcat与设置Tomcat为开机启动项(tomcat8为例)

    在Linux(CentOS7)操作系统中安装Apache Tomcat并将其设置为开机启动是一项常见的任务,特别是在部署Java web应用时。本篇文章将详细讲解如何在CentOS7上安装Tomcat8并将其配置为自启动服务。 首先,我们来了解...

    linux虚拟机安装nginx服务器教程

    `systemctl start firewalld.service` 配置 Nginx 1. 配置 Nginx,必须配置,否则无法访问到上传到 FTP 的图片。 `cd /etc/nginx` `vi nginx.conf` 进入之后按 “i” 启动编辑,并在配置文件后面加上红框里面的...

    zabbix简装文档

    systemctl stop firewalld.service systemctl disable firewalld.service firewall-cmd --state ``` 接下来,添加阿里云的YUM源,以便获取最新的软件包。运行以下命令: ``` wget -O /etc/yum.repos.d/CentOS-Base...

    CentOS7安装linux超级详细教程james.docx

    systemctl disable firewalld.service ``` 如果你想只开放3306端口,可以执行以下命令: - 查询3306端口是否已开启: ``` firewall-cmd --query-port=3306/tcp ``` - 开启3306端口: ``` firewall-cmd --...

    Linux部署web网页

    firewall-cmd --zone=public --add-port=1433/tcp --permanent; firewall-cmd --reload` - 安装 SQL 工具(如 sqlcmd 和 bcp):`curl ...

    管控Linux 7防火墙.pdf

    Firewalld 是 Linux 7 默 认 的 管 理 工 具,提供了“Direct rules”(直接规则)和“Rich Rules”(富规则)两个选项。 Firewalld 的特点: 1. 富规则:提供了更为复杂和精细的配置,能够对数据包的源地址、目标...

    firewall-cmd(linuix下类似百度网盘)

    `firewall-cmd` 是 Linux 系统中用于管理 `firewalld` 防火墙服务的命令行工具。`firewalld` 提供了一种动态管理防火墙规则的方法,与传统的静态 `iptables` 不同,它允许在运行时添加、删除或修改规则,并且这些...

    linux安装mysql(实测没问题)

    以上步骤详细阐述了如何在 Linux (CentOS 7) 系统上安装 MySQL 5.7 版本的过程,包括从下载安装包到配置环境变量以及最后的测试过程。按照这些步骤操作,即使是初学者也能顺利完成 MySQL 的安装和配置。

Global site tag (gtag.js) - Google Analytics