前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >10.22 firewalld关于service的操作

10.22 firewalld关于service的操作

作者头像
运维小白
发布2018-02-06 15:04:37
8150
发布2018-02-06 15:04:37
举报
文章被收录于专栏:运维小白运维小白

Linux防火墙-firewalled

  • firewall-cmd --get-services 查看所有的servies
  • firewall-cmd --list-services //查看当前zone下有哪些service
  • firewall-cmd --zone=public --add-service=http //把http增加到public zone下面
  • firewall-cmd --zone=public --remove-service=http
  • ls /usr/lib/firewalld/zones/ //zone的配置文件模板
  • firewall-cmd --zone=public --add-service=http --permanent //更改配置文件,之后会在/etc/firewalld/zones目录下面生成配置文件
  • 需求:ftp服务自定义端口1121,需要在work zone下面放行ftp
  • cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
  • vi /etc/firewalld/services/ftp.xml //把21改为1121
  • cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
  • vi /etc/firewalld/zones/work.xml //增加一行
  • <service name="ftp"/>
  • firewall-cmd --reload //重新加载
  • firewall-cmd --zone=work --list-services

firewall-cmd查看所有的servies

  • firewall-cmd --get-services 查看所有的servies(这里的 s 可省略)
    • servies,就是zone下面的一个子单元,可理解为它是一个指定的端口
      • 防火墙就是针对一些端口做出一些限制,比如:http操作的是80端口,https操作的是43端口,ssh操作的是22端口

代码语言:javascript
复制
[root@hf-01 ~]# firewall-cmd --get-services    //列出系统中所有的services
amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mysql nfs ntp openV** pmcd pmproxy pmwebapi pmwebapis pop3s postgresql proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https
[root@hf-01 ~]# 

firewall-cmd查看当前zone下有哪些service(service可加 s,也可不加 s)

  • firewall-cmd --list-services //查看当前zone下有哪些service
代码语言:javascript
复制
[root@hf-01 ~]# firewall-cmd --get-default-zone    //查看当前的zone
work
[root@hf-01 ~]# firewall-cmd --list-services    //查看当前zone下有哪些service
dhcpv6-client ipp-client ssh
[root@hf-01 ~]# 

  • 指定对应的zone,有哪些services
代码语言:javascript
复制
[root@hf-01 ~]# firewall-cmd --zone=public --list-services
dhcpv6-client ssh
[root@hf-01 ~]# 

firewall-cmd将http服务增加到public zone下面

  • firewall-cmd --zone=public --add-service=http //把http增加到public zone下面
代码语言:javascript
复制
[root@hanfeng ~]# firewall-cmd --zone=public --add-service=http
success
[root@hanfeng ~]# firewall-cmd --zone=public --list-service
dhcpv6-client http ssh
[root@hanfeng ~]# firewall-cmd --zone=public --add-service=ftp
success
[root@hanfeng ~]# firewall-cmd --zone=public --list-service
dhcpv6-client ftp http ssh
[root@hanfeng ~]# 

  • 现在仅仅是内存里面zone增加了一些service,若想将这些配置保存到配置文件中去,只需在后面在增加--permanent,来更改配置文件
    • firewall-cmd --zone=public --add-service=http --permanent //更改配置文件,之后会在/etc/firewalld/zones目录下面生成配置文件

代码语言:javascript
复制
[root@hanfeng ~]# firewall-cmd --zone=public --add-service=http --permanent
success
[root@hanfeng ~]# ls /etc/firewalld/zones/    //每次改完配置文件,就会生成一个旧的作为备份,后缀名为.old
public.xml   public.xml.old
[root@hanfeng ~]# 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>
[root@hanfeng ~]# 

zone的配置文件模板

  • ls /usr/lib/firewalld/zones/ //zone的配置文件模板
    • 能查看到有9个模板

代码语言:javascript
复制
[root@hanfeng ~]# ls /usr/lib/firewalld/zones/
block.xml  drop.xml      home.xml      public.xml   work.xml
dmz.xml    external.xml  internal.xml  trusted.xml
[root@hanfeng ~]# ls /usr/lib/firewalld/services/
amanda-client.xml      ipp-client.xml   mysql.xml       rpc-bind.xml
bacula-client.xml      ipp.xml          nfs.xml         samba-client.xml
bacula.xml             ipsec.xml        ntp.xml         samba.xml
dhcpv6-client.xml      kerberos.xml     openV**.xml     smtp.xml
dhcpv6.xml             kpasswd.xml      pmcd.xml        ssh.xml
dhcp.xml               ldaps.xml        pmproxy.xml     telnet.xml
dns.xml                ldap.xml         pmwebapis.xml   tftp-client.xml
ftp.xml                libvirt-tls.xml  pmwebapi.xml    tftp.xml
high-availability.xml  libvirt.xml      pop3s.xml       transmission-client.xml
https.xml              mdns.xml         postgresql.xml  vnc-server.xml
http.xml               mountd.xml       proxy-dhcp.xml  wbem-https.xml
imaps.xml              ms-wbt.xml       radius.xml
[root@hanfeng ~]# 

firewall-cmd将public zone下面的http服务删除

  • firewall-cmd --zone=public --remove-service=http

firewalled案例

需求

  • 将ftp服务自定义端口1121,需要在work zone下面放行ftp

实现

代码语言:javascript
复制
[root@hanfeng ~]# cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services
[root@hanfeng ~]# vi /etc/firewalld/services/ftp.xml

将内容中的21端口改为1121端口

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

增加一行,内容为 <service name="ftp"/>

[root@hanfeng ~]# firewall-cmd --reload        //重新加载
success
[root@hanfeng ~]# firewall-cmd --zone=work --list-services
dhcpv6-client ftp ipp-client ssh
[root@hanfeng ~]# 

  • firewall-cmd --reload //重新加载
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Linux防火墙-firewalled
    • firewall-cmd查看所有的servies
      • firewall-cmd查看当前zone下有哪些service(service可加 s,也可不加 s)
        • firewall-cmd将http服务增加到public zone下面
          • zone的配置文件模板
            • firewall-cmd将public zone下面的http服务删除
            • firewalled案例
              • 需求
                • 实现
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档