Centos7的防火墻服務(wù):firewalld
systemctl start firewalld
firewall-config
Centos6的防火墻服務(wù):iptables
iptables 由四個表和五個鏈組成
四個表:
filter表:過濾規(guī)則表蔚袍,根據(jù)規(guī)則過濾符合要求的數(shù)據(jù)包。
nat表:network address translation 地址轉(zhuǎn)換規(guī)則表
mangle:修改數(shù)據(jù)標記位規(guī)則表
Raw:關(guān)閉NAt表上啟用的連接跟蹤機制,加快封包穿越防火墻速度
這四個表的優(yōu)先級由高到低:Raw-->mangle-->nat----->filter
五個內(nèi)置鏈chain
INPUT
OUTPUT
FORWARD
PREROUTING
POSTROUTING
鏈和和表組成規(guī)則:
iptables 規(guī)則:
規(guī)則rule :
根據(jù)規(guī)則的匹配條件嘗試匹配報文七嫌,對匹配成功的報文根據(jù)規(guī)則定義的處理動作作出處理
匹配條件:默認為與條件觉渴,同時滿足
基本匹配:IP, 端口,TCP 的Flags (SYN,ACK 等)
擴展匹配:通過復(fù)雜高級功能匹配
處理動作:稱為target 汞贸,跳轉(zhuǎn)目標
內(nèi)建處理動作:ACCEPT,DROP,REJECT,SNAT,DNAT MASQUERADE,MARK,LOG...
自定義處理動作:自定義chain 肝箱,利用分類管理復(fù)雜情形規(guī)則要添加在鏈上坤检,才生效叹谁;添加在自定義上不會自動生效
鏈chain:
內(nèi)置鏈:每個內(nèi)置鏈對應(yīng)于一個鉤子函數(shù)
自定義鏈:用于對內(nèi)置鏈進行擴展或補充饲梭,可實現(xiàn)更靈活的規(guī)則組織管理機制;只有Hook 鉤子調(diào)用自定義鏈時焰檩,才生效憔涉。
iptables 命令
man 8 iptables
iptables [-t table] {-A|-C|-D} chain rule-specification
iptables [-t table] -I chain [rulenum] rule-specification
iptables [-t table] -R chain rulenum rule-specification
iptables [-t table] -D chain rulenum
iptables [-t table] -S [chain [rulenum]]
iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
iptables [-t table] -N chain
iptables [-t table] -X [chain]
iptables [-t table] -P chain target
iptables [-t table] -E old-chain-name new-chain-name
rule-specification = [matches...] [target]
match = -m matchname [per-match-options]
target = -j targetname [per-target-options]
iptables命令的例子
iptables -A INPUT -s 192.168.8.106 -j DROP ; 丟掉這個ip來的包
iptables -I INPUT -s 192.168.8.106 -j accept :拒絕這個IP來的包
iptables -F ; 清空防火墻規(guī)則
iptables -vnL --line-number
iptables -A INPUT 析苫! -s 192.168.8.12 -j REJECT ; 除了這個IP地址兜叨,其他的都拒絕