iptables -P INPUT DROP網絡
iptables -P OUTPUT ACCEPTtcp
iptables -P FORWARD DROPide
-A INPUT -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -m limit --limit 20/sec --limit-burst 200 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 20 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 21 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m state --state INVALID -j DROP
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT
-A OUTPUT -p tcp -m tcp --sport 31337 -j DROP
-A OUTPUT -p tcp -m tcp --dport 31337 -j DROP
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -m state --state INVALID -j DROP
spa
、查看
iptables -nvL –line-number接口
-L 查看當前表的全部規則,默認查看的是filter表,若是要查看NAT表,能夠加上-t NAT參數
-n 不對ip地址進行反查,加上這個參數顯示速度會快不少
-v 輸出詳細信息,包含經過該規則的數據包數量,總字節數及相應的網絡接口
–line-number 顯示規則的序列號,這個參數在刪除或修改規則時會用到ip
添加get
添加規則有兩個參數:-A和-I。其中-A是添加到規則的末尾;-I能夠插入到指定位置,沒有指定位置的話默認插入到規則的首部。it
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.4 0.0.0.0/0io
添加一條規則到尾部:table
iptables -A INPUT -s 192.168.1.5 -j DROP
iptables -I INPUT 3 -s 192.168.1.3 -j DROP
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
4 DROP all -- 192.168.1.4 0.0.0.0/0
5 DROP all -- 192.168.1.5 0.0.0.0/0
刪除
iptables -D INPUT -s 192.168.1.5 -j DROP
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
iptables -D INPUT 2
修改
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.5 0.0.0.0/0
iptables -R INPUT 3 -j ACCEPT
[root@test ~]# iptables -nL --line-numberChain INPUT (policy ACCEPT)num target prot opt source destination1 DROP all -- 192.168.1.1 0.0.0.0/02 DROP all -- 192.168.1.2 0.0.0.0/03 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0