iptables規則備份恢復,firewalld的9個zone

​10月29日任務linux

10.19 iptables規則備份和恢復bash

10.20 firewalld的9個zonetcp

10.21 firewalld關於zone的操做rest

10.22 firewalld關於service的操做xml

 

linux防火牆-netfilterblog

  • 保存和備份iptables規則
  • service iptables save //會把規則保存到/etc/sysconfig/iptables
  • 把iptables規則備份到my.ipt文件中
  • iptables-save > my.ipt
  • 恢復剛纔備份的規則
  • iptables-restore < my.ipt

 

linux防火牆-firewalledip

  • 打開firewalld
  • systemctl disable iptables
  • systemctl stop iptables
  • systemctl enable firewalld
  • systemctl start firewalld
  • firewalld默認有9個zone
  • 默認zone爲public
  • firewall-cmd --get-zones //查看全部zone
  • firewall-cmd --get-default-zone //查看默認zone

#關閉netfilter防火牆,開啓firewalld防火牆。rem

[root@zgxlinux-01 ~]# systemctl disable iptables
[root@zgxlinux-01 ~]# systemctl stop iptables
[root@zgxlinux-01 ~]# system enable fierwalld
-bash: system: 未找到命令
[root@zgxlinux-01 ~]# systemctl enable fierwalld
Failed to execute operation: No such file or directory
[root@zgxlinux-01 ~]# systemctl enable firewalld
[root@zgxlinux-01 ~]# systemctl start firewalld
[root@zgxlinux-01 ~]# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1041 77178 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
   83  7467 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   83  7467 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   83  7467 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
   81  7323 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
 4482  376K FORWARD_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 4482  376K FORWARD_IN_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 4482  376K FORWARD_IN_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   81  5892 FORWARD_OUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   81  5892 FORWARD_OUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
   81  5892 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 321 packets, 37610 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  766 81456 OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD_IN_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDI_public  all  --  ens33  *       0.0.0.0/0            0.0.0.0/0           [goto] 
 4482  376K FWDI_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_IN_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD_OUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDO_public  all  --  *      ens33   0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 FWDO_public  all  --  *      +       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_OUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FWDI_public (2 references)
 pkts bytes target     prot opt in     out     source               destination         
 4482  376K FWDI_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 4482  376K FWDI_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 4482  376K FWDI_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 4401  370K ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FWDI_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FWDI_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FWDI_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FWDO_public (2 references)
 pkts bytes target     prot opt in     out     source               destination         
   81  5892 FWDO_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   81  5892 FWDO_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   81  5892 FWDO_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FWDO_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FWDO_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain FWDO_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination         
   76  6001 IN_public  all  --  ens33  *       0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 IN_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain INPUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain IN_public (2 references)
 pkts bytes target     prot opt in     out     source               destination         
   83  7467 IN_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   83  7467 IN_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   83  7467 IN_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain IN_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    2   144 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 ctstate NEW

Chain IN_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain IN_public_log (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT_direct (1 references)
 pkts bytes target     prot opt in     out     source               destination 

 

#查看firewalld的所有zone ,和查看默認的zone。get

[root@zgxlinux-01 ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
[root@zgxlinux-01 ~]# firewall-cmd --get-default-zone
public

 

10.21 firewalld關於zone的操做cmd

  • firewall-cmd --set-default-zone=work //設定默認zone

  • firewall-cmd --get-zone-of-interface=ens33 //查指定網卡

  • firewall-cmd --zone=public --add-interface=lo //給指定網卡設置zone

  • firewall-cmd --zone=dmz --change-interface=lo //針對網卡更改zone

  • firewall-cmd --zone=dmz --remove-interface=lo //針對網卡刪除zone

  • firewall-cmd --get-active-zones //查看系統全部網卡所在的zone

 

10.22 firewalld關於service的操做

  • firewall-cmd --get-services   查看全部的services

  • 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/firewall/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

相關文章
相關標籤/搜索