七周五次课 10.19 iptables规则备份和恢复 10.20 firewalld的9个zone 10.21 firewalld关于zone的操作 10.22 firewalld关于service...

10.19 iptables规则备份和恢复

•service iptables save //会把规则保存到/etc/sysconfig/iptables

• 把iptables规则备份

iptables-save > 目标文件名

• 恢复备份的规则

iptables-restore < 目标文件名

10.20 firewalld的9个zone

• 查看所有zone

firewall-cmd --get-zones

• 查看默认zone(默认zone为public)

firewall-cmd --get-default-zone

• 9个zone的简介

142510_K2ui_3804357.png

10.21 firewalld关于zone的操作

• 设定默认zone

firewall-cmd --set-default-zone=zone的名称

• 查看指定网卡所使用的zone

firewall-cmd --get-zone-of-interface=网卡名称

• 给指定网卡设置zone

firewall-cmd --zone=zone名称 --add-interface=网卡名称

• 针对网卡更改zone

firewall-cmd --zone=zone名称 --change-interface=网卡名称

• 针对网卡删除zone

firewall-cmd --zone=zone名称  --remove-interface=网卡名称

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

firewall-cmd --get-active-zones

10.22 firewalld关于service的操作

service:service是zone下面的子单元,可以理解为是指定的一个端口,防火墙的功能无外乎是针对一些端口进行限制,比如http操作的是80端口,https操作的是443端口,ssh操作的是22端口。

• 查看所有的services

firewall-cmd --get-services  //结尾的s可加可不加

• 查看当前zone下有哪些service

firewall-cmd --list-services 

• 把http增加到public zone下面

firewall-cmd --zone=public --add-service=http 

• 把http从public zone下面删除

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

• 更改配置文件

firewall-cmd --zone=public --add-service=http --permanent 

单纯修改规则只是在内存中修改,重启后会丢失,更改配置文件后,会在/etc/firewalld/zones目录下面生成配置文件,可以永久生效。

• zone的配置文件模板/usr/lib/firewalld/zones/

[root@linux-5 ~]# ls /usr/lib/firewalld/zones/
block.xml  dmz.xml  drop.xml  external.xml  home.xml  internal.xml  public.xml  trusted.xml  work.xml

• servies的配置文件模板/usr/lib/firewalld/services/

[root@linux-5 ~]# ls /usr/lib/firewalld/services/
amanda-client.xml        freeipa-replication.xml  libvirt-tls.xml           postgresql.xml       spideroak-lansync.xml
amanda-k5-client.xml     freeipa-trust.xml        libvirt.xml               privoxy.xml          squid.xml
bacula-client.xml        ftp.xml                  managesieve.xml           proxy-dhcp.xml       ssh.xml
bacula.xml               ganglia-client.xml       mdns.xml                  ptp.xml              synergy.xml
bitcoin-rpc.xml          ganglia-master.xml       mosh.xml                  pulseaudio.xml       syslog-tls.xml
bitcoin-testnet-rpc.xml  high-availability.xml    mountd.xml                puppetmaster.xml     syslog.xml
bitcoin-testnet.xml      https.xml                mssql.xml                 quassel.xml          telnet.xml
bitcoin.xml              http.xml                 ms-wbt.xml                radius.xml           tftp-client.xml
ceph-mon.xml             imaps.xml                mysql.xml                 RH-Satellite-6.xml   tftp.xml
ceph.xml                 imap.xml                 nfs.xml                   rpc-bind.xml         tinc.xml
cfengine.xml             ipp-client.xml           nrpe.xml                  rsh.xml              tor-socks.xml
condor-collector.xml     ipp.xml                  ntp.xml                   rsyncd.xml           transmission-client.xml
ctdb.xml                 ipsec.xml                openvpn.xml               samba-client.xml     vdsm.xml
dhcpv6-client.xml        iscsi-target.xml         ovirt-imageio.xml         samba.xml            vnc-server.xml
dhcpv6.xml               kadmin.xml               ovirt-storageconsole.xml  sane.xml             wbem-https.xml
dhcp.xml                 kerberos.xml             ovirt-vmconsole.xml       sips.xml             xmpp-bosh.xml
dns.xml                  kibana.xml               pmcd.xml                  sip.xml              xmpp-client.xml
docker-registry.xml      klogin.xml               pmproxy.xml               smtp-submission.xml  xmpp-local.xml
dropbox-lansync.xml      kpasswd.xml              pmwebapis.xml             smtps.xml            xmpp-server.xml
elasticsearch.xml        kshell.xml               pmwebapi.xml              smtp.xml
freeipa-ldaps.xml        ldaps.xml                pop3s.xml                 snmptrap.xml
freeipa-ldap.xml         ldap.xml                 pop3.xml                  snmp.xml

• 系统中firewalld服务zone的配置文件/etc/firewalld/zones/

[root@linux-5 ~]# ls /etc/firewalld/zones/
public.xml  public.xml.old

注:在保存系统的firewalld服务配置文件时,系统会把旧的配置自动生成一个后缀名为.old的文件

• 系统中firewalld服务services的配置文件/etc/firewalld/services/

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

1.从servies的配置文件模板中将ftp服务的模板(ftp.xml)拷贝至系统中firewalld服务services的配置文件

cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services

2.修改配置文件

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="21"/>  //把21改为1121
  <module name="nf_conntrack_ftp"/>
</service>

3.从zone的配置文件模板中将work服务的模板(work.xml)拷贝至系统中firewalld服务zone的配置文件

cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/

4.修改配置文件

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>

5.重新加载

[root@linux-5 ~]# firewall-cmd --reload
success

6.查看结果

[root@linux-5 ~]# firewall-cmd --zone=work --list-services
ssh dhcpv6-client ftp    //成功添加ftp服务

 

转载于:https://my.oschina.net/u/3804357/blog/1810180

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值