Welcome 微信登录

首页 / 操作系统 / Linux / 使用iptables统计流量

#添加流入/出的iptables规则1. $ iptables -I INPUT -d 192.168.1.1002. $ iptables -I OUTPUT -s 192.168.1.100#查看流量1. $ iptables -nvx -L#清除规则1. $ iptables -F1. $ iptables -I FORWARD -s 192.168.1.100 -j ACCEPT2. $ iptables -I FORWARD -d 192.168.1.100 -j ACCEPT1. $ sudo iptables -t filter -A INPUT -p all -s 174.121.79.132 -j ACCEPT2. $ 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-numbers2.3. num target prot opt source destination4. 1 REJECT tcp -- anywhere anywhere tcp dpt:microsoft-ds reject-with icmp-port-unreachable5. 2 REJECT tcp -- anywhere anywhere tcp dpt:135 reject-with icmp-port-unreachable6. 3 REJECT tcp -- anywhere anywhere tcp dpt:netbios-ssn reject-with icmp-port-unreachable7. 4 REJECT udp -- anywhere anywhere udp dpt:microsoft-ds reject-with icmp-port-unreachable8. 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相关教程见以下内容:CentOS 7.0关闭默认防火墙启用iptables防火墙  http://www.linuxidc.com/Linux/2015-05/117473.htmiptables使用范例详解 http://www.linuxidc.com/Linux/2014-03/99159.htmLinux防火墙iptables详细教程 http://www.linuxidc.com/Linux/2013-07/87045.htmiptables的备份、恢复及防火墙脚本的基本使用 http://www.linuxidc.com/Linux/2013-08/88535.htmLinux下防火墙iptables用法规则详解 http://www.linuxidc.com/Linux/2012-08/67952.htmLinux下iptables防火墙设置 http://www.linuxidc.com/Linux/2015-10/123843.htm本文永久更新链接地址