iptables+tc 限制每个ip的带宽

作者:佚名 上传时间:2019-05-14 版权申诉
#!/bin/bash
# OUTdoor interface
GREEN_DEV=eth1
# INdoor interface
RED_DEV=eth0
# Upload rate 250kb/s
UPRATE=2000
# Download rate 80kb/s
DOWNRATE=640
start(){
#clean existing down and uplink qdiscs,put the errors to /var/log/htb_log
tc qdisc del dev $RED_DEV root 2>/dev/null >/dev/null
tc qdisc del dev $GREEN_DEV root 2>/dev/null >/dev/null
tc qdisc del dev $RED_DEV ingress 2>/dev/null >/dev/null
tc qdisc del dev $GREEN_DEV ingress 2>/dev/null >/dev/null

tc qdisc add dev $GREEN_DEV root handle 2: htb
tc qdisc add dev $RED_DEV root handle 2: htb
tc class add dev $GREEN_DEV parent 2: classid 2:1 htb rate 256kbit
tc class add dev $RED_DEV parent 2: classid 2:1 htb rate 256kbit
i=5;
while [ $i -le 25 ]
do
tc class add dev $GREEN_DEV parent 2:1 classid 2:2$i htb rate ${DOWNRATE}kbit ceil ${DOWNRATE}kbit burst 15k
tc class add dev $RED_DEV parent 2:1 classid 2:2$i htb rate ${UPRATE}kbit ceil ${UPRATE}kbit burst 15k
tc qdisc add dev $GREEN_DEV parent 2:2$i handle 2$i: sfq
tc qdisc add dev $RED_DEV parent 2:2$i handle 2$i: sfq
tc filter add dev $GREEN_DEV parent 2:0 protocol ip prio 1 u32 match ip dst 192.168.1.$i flowid 2:2$i
tc filter add dev $RED_DEV parent 2:0 protocol ip prio 1 u32 match ip dst 192.168.1.$i flowid 2:2$i
i=`expr $i + 1`
done
}
stop(){
#clean existing down and uplink qdiscs,put the errors to /var/log/htb_log
tc qdisc del dev $RED_DEV root 2>/dev/null >/dev/null
tc qdisc del dev $GREEN_DEV root 2>/dev/null >/dev/null
}
status() {
echo "Show qdisc $RED_DEV (Display Upload queue):"
tc -s qdisc show dev $RED_DEV
echo "Show class $RED_DEV (Display Upload class):"
tc class show dev $RED_DEV
echo "*********************************UP/DOWN*********************************"
echo "Show qdisc $GREEN_DEV (Display Download queue):"
tc -s qdisc show dev $GREEN_DEV
echo "Show class $GREEN_DEV (Display Download class):"
tc class show dev $GREEN_DEV
}
usage(){
echo "(usage): `basename $0` [start | stop | restart | status]"
echo ""
echo "Argument: functions:"
echo "start start traffic-control"
echo "stop stop traffic-control"
echo "restart restart traffic-control"
echo "status show detail of traffic"
}
# Argument
kernel=`uname -r|cut -b 1-3`
case "$kernel" in
2.4|2.6)
case "$1" in
start)
( start && echo "TC started!" ) || echo "Error."
exit 0
;;
stop)
( stop && echo "TC stopped!" ) || echo "Error."
exit 0
;;
restart)
( start && echo "TC restarted!" ) || echo "Error."
exit 0
;;
status)
status
;;
*)
usage
exit 1
;;
esac
;;
*)
echo " (!) Error: Unsupported Kernel!"
exit 1
;;
esac

本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/456573



免责申明:文章和图片全部来源于公开网络,如有侵权,请通知删除 server@dude6.com

用户评论
相关推荐
iptables+tc 限制每个ip带宽
#!/bin/bash # OUTdoor interface GREEN_DEV=eth1 # INdoor interface
fortigate限制带宽
NULL博文链接:https://yuhao224.iteye.com/blog/1735374
RAR
0B
2019-09-09 16:14
FreeBSD下使用pfctl限制特定IP地址带宽
该示例展示了如何在FreeBSD操作系统下使用pfctl限制特定IP地址的带宽。通过使用pfctl命令和traffic shaping技术,可以控制网络中的特定IP地址的带宽使用。# 配置规则pa
FreeBSD 12.2
pfctl
2023-03-22 17:43
isa限制带宽doc
在ISA_2006_上利用Bandwidth_Splitter定制带宽和限制流量.doc
DOC
892KB
2021-05-04 03:26
用php来限制每个ip每天浏览页面数量实现思路
实现思路:首先,创建一个表,比如下面的 复制代码 代码如下: CREATE TABLE ip_log ( ip_log_ip VARCHAR(40), ip_log_date DATE
PDF
33KB
2020-12-23 02:51
破除带宽限制工具
(破除带宽限制工具)共享神盾V3.50安装版.
7Z
0B
2019-05-13 12:10
Nginx限制带宽配置示例
示例一: 代码如下: http { limit_rate 25k; #每个连接的速度限制 limit_zone to_vhost
PDF
33KB
2021-01-16 20:03
tc流控脚本 ,动态保证每个ip有1M带宽
tc主脚本: #!/bin/bash # . /root/tc_functions NUM=2 DEV=eth0 in
PHP限制国内IP PHP限制IP PHP限制IP
PHP限制国内IP,PHP限制IP,PHP限制IP段
RAR
0B
2018-12-25 16:04
带宽锁破解版限制电脑总带宽小软件
Bandwidth lock crack version (small software that limits the total bandwidth of the computer)
zip
0B
2019-06-26 07:09