歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 使用iptables統計流量

使用iptables統計流量

日期:2017/2/28 13:54:14   编辑:Linux教程

#添加流入/出的iptables規則

1. $ iptables -I INPUT -d 192.168.1.100

2. $ iptables -I OUTPUT -s 192.168.1.100

#查看流量

1. $ iptables -nvx -L

#清除規則

1. $ iptables -F

1. $ iptables -I FORWARD -s 192.168.1.100 -j ACCEPT

2. $ iptables -I FORWARD -d 192.168.1.100 -j ACCEPT

1. $ sudo iptables -t filter -A INPUT -p all -s 174.121.79.132 -j ACCEPT

2. $ sudo iptables -t filter -A OUTPUT -p all -d 174.121.79.132 -j ACCEPT

刪除規則的方法

方法一的語法是:

iptables -D chain rulenum [options]

其中, chain是鏈的意思,就是INPUT FORWARD 之類的;rulenum 是規則的編號,從1 開始,可以使用--line-numbers 列出規則的編號。比如列出INPUT 鏈所有的規則:

1. $ iptables -L INPUT --line-numbers

2.

3. num target prot opt source destination

4. 1 REJECT tcp -- anywhere anywhere tcp dpt:microsoft-ds reject-with icmp-port-unreachable

5. 2 REJECT tcp -- anywhere anywhere tcp dpt:135 reject-with icmp-port-unreachable

6. 3 REJECT tcp -- anywhere anywhere tcp dpt:netbios-ssn reject-with icmp-port-unreachable

7. 4 REJECT udp -- anywhere anywhere udp dpt:microsoft-ds reject-with icmp-port-unreachable

8. 5 REJECT udp -- anywhere anywhere udp dpt:135 reject-with icmp-port-unreachabl

刪除指定行規則:

1. $ iptables -D INPUT 4

如果要連續刪除多條規則,記得NUM編號要從大向小去刪除,因為每刪除一條都會導致被刪條目之後的行號變化。刪一條就iptables -L 再確認一下行號,是比較穩妥的方法。

方法二是 -A 命令的映射,用-D替換-A。當你的鏈中規則很復雜,而你不想計算它們的編號的時候這就十分有用了。也就是說,你如何用iptables -A.... 語句定義了一個規則,則刪除此規則時就用 -D 來代替- A,其余的都不變即可。

Copyright © Linux教程網 All Rights Reserved