限制VPS每日或者每月使用流量的iptable规则

教程大全iptable,VPS每月流量

限制VPS每日或者每月使用流量的iptable规则

此文章转自V2大佬,实际效果博主未测试。

 

iptables规则如下:

iptables -F quota70g 【删除指定链或所有链的规则】
iptables -F OUTPUT
iptables -P OUTPUT ACCEPT 【为指定链设置默认规则策略,对自定义链不起作用】

iptables -N quota70g 【创建用户自定义链】
iptables -A quota70g -m quota –quota 75161927680 -j RETURN 【-A 在指定链尾部添加规则,RETURN – 防火墙停止执行当前链中的后续Rules,并返回到调用链(the calling chain)中。】
iptables -A quota70g -j DROP

iptables -A OUTPUT -o eth0+ -j quota70g

添加每日定时执行任务:

08 00 * * * /sbin/iptables -Z quota70g 【将指定链或所有链的计数器清零】 每天0点过8分执行,清空 quota40g 的计数,重新计数。

说明下,流量限定是以字节为单位,1MB=1048576 字节。

红色字体 75161927680 转换后为70G

https://calc.itzmx.com/ 在线转换工具

提示:如果限制每月流量的话,就在每月清零一次。

Posted by 柴郡猫