天天看點

火牆管理工具(iptables,firewalld)

一.火牆介紹:

1.netfilter:

        netfilter是由Rusty Russell提出的Linux 2.4核心防火牆架構,該架構既簡潔又靈活,可實作安全政策應用中的許多功能,如資料包過濾、資料包處理、位址僞裝、動态網絡位址轉換,以及基于使用者及媒體通路控制位址的過濾和基于狀态的過濾、包速率限制等。

2.iptables

        iptables(網絡 過濾器)是一個工作于使用者空間的防火牆應用軟體,是與3.5版本Linux核心內建的IP資訊包過濾系統。如果Linux系統連接配接到網際網路或LAN、伺服器或連接配接LAN和網際網路的代理伺服器,則該系統有利于在Linux系統上更好地控制IP資訊包過濾和防火牆配置。

3.iptables|firewalld

二.火牆管理工具切換:

firewalld----->   iptables

火牆管理工具(iptables,firewalld)

iptables------->  firewalld

火牆管理工具(iptables,firewalld)

三.iptables使用

/etc/sysconfig/iptables               #iptables政策記錄檔案

永久儲存政策:

iptables-save > /etc/sysconfig/iptables

service iptables save

火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)

四.iptables指令

iptables

          -t             #指定表名稱

          -n            #不做解析

          -L            #檢視

          -A            #添加政策

         -p            #協定

         --dport     #目的地端口

         -s            #來源

         -j             #動作

                  ACCEPT        #允許

                 DROP             #丢棄

                 REJECT         #拒絕

                 SNAT              #源位址轉換

                 DNAT             #目的地位址轉換

         -N               #建立鍊

        -E               #更改鍊名稱

        -X                #删除鍊

        -D               #删除規則

        -I                 #插入規則

       -R               #更改規則

        -P               #更改預設規則

火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)

四.資料包狀态

RELATED            #建立過連接配接的

ESTABLISHED    #正在連接配接的

NEW                    #新的

實驗:

主機1:west_firewalld 伺服器(雙網卡):172.25.254.10           192.168.42.133

主機2:west_file         用戶端(單網卡):172.25.254.20

建立過連接配接的和正在建立連接配接的可以直接使用服務,新使用者需讀取iptables中的資料

火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)
火牆管理工具(iptables,firewalld)

五.nat表中的snat

snat:

iptables -t nat -A POSTROUTING -o ens160 -j SNAT --to-source 192.168.42.133

sysctl -a | grep ip_forward

net.ipv4.ip_forward=1

net.ipv4.ip_forward_use_pmtu=0

六.firewalld的開啟,基本資訊

systemctl stop iptables

systemctl disable iptables

systemctl mask iptables

systemctl unmask iptables

systemctl enable --now firewalld

火牆管理工具(iptables,firewalld)

/etc/firewalld              #火牆配置目錄

/lib/firewalld               #火牆子產品目錄

七.關于firewalld的域

trusted                # 接受所有的網絡連接配接

home                  #用于家庭網絡,允許接受ssh,mdns,ipp-client,samba-client,dhcp-client

work                   #工作網絡ssh,ipp-client,dhcp-client

public                 #公共網絡ssh,dhcp-client

dmz                   #軍級網絡ssh

block                 #拒絕所有

drop                  #丢棄,所有資料全部丢棄無任何恢複

internal              #内部網絡ssh,mdns,ipp-client,samba-client,dhcp-client

八.firewalld管理指令

firewall-cmd    --state                               #檢視火牆狀态

firewall-cmd   --get-active-zones              #檢視目前火牆中生效的域

firewall-cmd   --get-default-zone              #檢視預設域

firewall-cmd   --list-all                              #檢視預設域中的火牆政策

firewall-cmd   --list-all  --zone=work        #檢視指定域中的火牆政策

firewall-cmd   set-default-zone=trusted    #設定預設域

firewall-cmd   --get-service                     #檢視所有可以設定的服務

firewall-cmd   --permanent  --remove-service=cockpit             #移除服務

firewall-cmd   --permanent  --add-source=172.25.254.0/24  --zone=block          #指定資料來源通路指定域

firewall-cmd   --permanent  --remove-source=172.25.254.0/24  --zone=block     #删除指定域中的資料來源

firewall-cmd   --permanent  --remove-interface=ens192  zone=public                  #删除指定域中的網絡接口

firewall-cmd   --permanent  --add-interface=ens192  zone=block                         #添加指定域的網絡接口

firewall-cmd   --permanent  --change-interface=ens192  zone=public                   #更改網絡接口到指定域

繼續閱讀