Nic*_*ick 2 linux traffic debian iptables quota
我一直在尝试为共享服务器上的用户设置流量配额,我相信 [以我有限的知识] iptables --quota 和为每个用户选择的端口 [--dport] 是这样做的方法...
iptables -A 输出 --dport 1,2,3,4... --quota 123412341234 -j 接受
iptables -A 输出 --dport 1,2,3,4... -j DROP
我认为这样的事情可以限制流量[并每月重置],但仅适用于外出的流量。
操作系统是 debian 挤压
谢谢。
如果你想申请配额都传入和传出,你会做这样的:
-A OUTPUT -p tcp --sport $PORTNUM_1 -g filter_quota_1
-A OUTPUT -p tcp --sport $PORTNUM_2 -g filter_quota_2
<other OUTPUT rules for other users>
-A INPUT -p tcp --dport $PORTNUM_1 -g filter_quota_1
-A INPUT -p tcp --dport $PORTNUM_2 -g filter_quota_2
<other INPUT rules>
-A filter_quota_1 -m quota --quota $QUOTA_1 -g chain_where_quota_not_reached
-A filter_quota_1 -g chain_where_quota_is_reached
-A filter_quota_2 -m quota --quota $QUOTA_2 -g chain_where_quota_not_reached
-A filter_quota_2 -g chain_where_quota_is_reached
<other filter_quota_N chains>
Run Code Online (Sandbox Code Playgroud)
当您想重置配额 #N 时,您可以这样做iptables -F filter_quota_N,然后重新填充filter_quota_N.
由于规则大多相似,您真的应该考虑使用 bash(或您选择的其他脚本语言)实现自动化