10.22 firewalld关于service的操作

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端口
[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 openvpn 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
[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
[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下面
[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目录下面生成配置文件
[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个模板
[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     openvpn.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

实现

[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 //重新加载

转载于:https://my.oschina.net/u/3707314/blog/1583475

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值