新聞中心
Linux iptables入門(mén)教程總結(jié)

iptables簡(jiǎn)介
iptables是Linux系統(tǒng)中的一個(gè)防火墻工具,它可以用來(lái)配置網(wǎng)絡(luò)規(guī)則,實(shí)現(xiàn)對(duì)數(shù)據(jù)包的過(guò)濾、轉(zhuǎn)發(fā)等功能,iptables是Linux系統(tǒng)中默認(rèn)的防火墻工具,它的功能非常強(qiáng)大,可以滿足大部分企業(yè)級(jí)防火墻的需求,iptables支持多種操作系統(tǒng),包括Linux、FreeBSD、OpenBSD等。
iptables工作原理
iptables的工作原理是基于Netfilter框架的,Netfilter框架是Linux內(nèi)核中的一個(gè)通用架構(gòu),用于處理各種網(wǎng)絡(luò)協(xié)議的數(shù)據(jù)包,iptables通過(guò)與Netfilter框架進(jìn)行交互,實(shí)現(xiàn)對(duì)數(shù)據(jù)包的過(guò)濾、轉(zhuǎn)發(fā)等功能。
iptables基本語(yǔ)法
1、查看當(dāng)前iptables規(guī)則:
iptables -L -n -v
2、清空當(dāng)前iptables規(guī)則:
iptables -F
3、設(shè)置默認(rèn)策略(INPUT、OUTPUT、FORWARD):
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
4、允許來(lái)自特定IP的數(shù)據(jù)包:
iptables -A INPUT -s IP地址 -j ACCEPT
5、拒絕來(lái)自特定IP的數(shù)據(jù)包:
iptables -A INPUT -s IP地址 -j DROP
6、允許特定端口的數(shù)據(jù)包:
iptables -A INPUT -p 端口號(hào) –dport 端口號(hào) -j ACCEPT
7、拒絕特定端口的數(shù)據(jù)包:
iptables -A INPUT -p 端口號(hào) –dport 端口號(hào) -j DROP
8、保存當(dāng)前iptables規(guī)則:
service iptables save
iptables常用命令
1、查看當(dāng)前iptables規(guī)則:iptables -L -n -v
2、清空當(dāng)前iptables規(guī)則:iptables -F
3、設(shè)置默認(rèn)策略(INPUT、OUTPUT、FORWARD):iptables -P INPUT ACCEPT、iptables -P OUTPUT ACCEPT、iptables -P FORWARD ACCEPT
4、允許來(lái)自特定IP的數(shù)據(jù)包:iptables -A INPUT -s IP地址 -j ACCEPT
5、拒絕來(lái)自特定IP的數(shù)據(jù)包:iptables -A INPUT -s IP地址 -j DROP
6、允許特定端口的數(shù)據(jù)包:iptables -A INPUT -p 端口號(hào) --dport 端口號(hào) -j ACCEPT
7、拒絕特定端口的數(shù)據(jù)包:iptables -A INPUT -p 端口號(hào) --dport 端口號(hào) -j DROP
8、保存當(dāng)前iptables規(guī)則:service iptables save
9、恢復(fù)默認(rèn)的iptables規(guī)則:service iptables restore
10、重啟iptables服務(wù):service iptables restart
11、查看某個(gè)規(guī)則是否存在:iptables -L | grep "規(guī)則內(nèi)容"
12、刪除某個(gè)規(guī)則:iptables -D INPUT <鏈名> <規(guī)則編號(hào)>或iptables -D <鏈名> <規(guī)則編號(hào)>
13、插入某個(gè)規(guī)則:iptables -I INPUT <鏈名> <規(guī)則內(nèi)容>或iptables -I <鏈名> <規(guī)則內(nèi)容>
14、修改某個(gè)規(guī)則的順序:iptables -R <鏈名> <規(guī)則編號(hào)> <新規(guī)則編號(hào)>或iptables -R <鏈名> <新規(guī)則編號(hào)> <舊規(guī)則編號(hào)>
15、將某個(gè)規(guī)則添加到其他鏈中:iptables -A <目標(biāo)鏈名> <源鏈名> <規(guī)則編號(hào)>或iptables -A <目標(biāo)鏈名> <源鏈名> --jump <跳轉(zhuǎn)類型> --destination-port <目標(biāo)端口> --source-port <源端口> --protocol <協(xié)議類型> --dport <目標(biāo)端口> --sports <源端口> --match multiport --match state --state <狀態(tài)類型> --match comment --comment "<選項(xiàng)" --match destination --destination-address <目標(biāo)地址> --source-address <源地址> --match tcp-flags --tcp-flags <標(biāo)志位> --match packet-length --packet-length <長(zhǎng)度值> --match extension --extension <擴(kuò)展名> --match module --module <模塊名> --match owner --owner <所有者用戶ID>:<所有者組ID> --match limit --limit <限制次數(shù)> --match log-prefix --log-prefix "日志前綴" --log-level <日志級(jí)別> --log-uid <記錄用戶ID>:<記錄組ID> --log-prefix "日志前綴" --log-level <日志級(jí)別> --log-uid <記錄用戶ID>:<記錄組ID> --log-prefix "日志前綴" --log-level <日志級(jí)別> --log-uid <記錄用戶ID>:<記錄組ID>
本文標(biāo)題:iptablescentos
新聞來(lái)源:http://fisionsoft.com.cn/article/cdcdpcs.html


咨詢
建站咨詢
