Linux中最简单的总带宽限制

分类: 系统管理   出处:iocblog整理  更新时间:2008-06-19   添加到收藏  

  最简单的总带宽限制(tc脚本,每个主流linux都有tc和iptable,cp到一个文件赋予x权限,执行就ok)....根据pureftp的faq中带宽限制得来的...
  
  #! /bin/sh
  # simple bandwidth limiter -
  
  # change this to your link bandwidth
  # (for cable modem, dsl links, etc. put the maximal bandwidth you can
  # get, not the speed of a local ethernet link)
  real_bw='10mbit'
  
  # change this to the bandwidth you want to allocate to ftp.
  # we're talking about megabits, not megabytes, so 80kbit is
  # 10 kilobytes/s
  ftp_bw='7200kbit' //总带宽
  
  # change this to your physical network device (or 'ppp0')
  nic='eth0'
  
  # change this to the ports you assigned for passive ftp
  ftp_port_low="10000" //passive端口低限
  ftp_port_high="11000" //passive端口上限
  tc qdisc del dev "$nic" root 2> /dev/null //清除tc队列中关于网卡的设置
  //(hunreal修改)
  
  tc qdisc add dev "$nic" root handle 1: cbq bandwidth "$real_bw" avpkt 1000
  
  tc class add dev "$nic" parent 1: classid 1:1 cbq bandwidth "$real_bw" rate "$real_bw" maxburst 5 avpkt 1000
  
  tc class add dev "$nic" parent 1:1 classid 1:10 cbq bandwidth "$real_bw" rate "$ftp_bw" maxburst 5 avpkt 1000 bounded
  
  tc qdisc add dev "$nic" parent 1:10 sfq quantum 1514b
  
  tc filter add dev "$nic" parent 1: protocol ip handle 1 fw flowid 1:10(来源www.iocblog.net)
  
  iptables -t mangle -a output -p tcp --sport 20:1221 -j mark --set-mark 1
  //上面的1221是ftp的端口号
  
  iptables -t mangle -a output -p tcp --sport "$ftp_port_low":"$ftp_port_high" -j mark --set-mark 1
  
Tag: iptables



文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。