使用iptables统计流量

#添加流入/出的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

扫描二维码关注公众号,回复: 2002568 查看本文章

删除规则的方法

方法一的语法是:

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,其余的都不变即可。

更多iptables相关教程见以下内容

猜你喜欢

转载自www.linuxidc.com/Linux/2016-03/128861.htm