Linux upload speed limit script

Source: Internet
Author: User

Linux upload speed limit script

The following script can be used to limit the upload speed of the server. when the service is in peak hours, the upload speed is limited to ensure normal service.

The principle is to use the TC (Traffic Control Module) in linux to implement the speed limit function.

The script is used as follows:

Start: sh limit. sh start 200 (the maximum upload speed is kb/s)

Stop: sh limit. sh stop

 

#! /Bin/bash # a simple example for "tc" # set the paramDELAY = 20 SPEED = $2 FLOW = 0 # exit Nic NETWORK_CARD = $ (ip ro get 115.29.128.27 | grep eth | awk '{print $5 }') # server IPIP_ADDRESS = 115.29.128.28start () {/sbin/tc qdisc add dev $ {NETWORK_CARD} root handle 1: htb default 25/sbin/tc class add dev $ {NETWORK_CARD} parent 1: classid 1:1 htb rate $ {SPEED} kbps/sbin/tc qdisc add dev $ {NETWORK_CARD} parent 1:1 netem delay $ {DELAY} MS $ {FLOW} MS/sbin/tc filter add dev $ {NETWORK_CARD} parent 1: protocol ip prio 1 u32 match ip dst ${IP_ADDRESS}/32 flowid 1:1} stop () {/sbin/tc qdisc dele dev $ {NETWORK_CARD} root} case "$1" in start) start; stop) stop; *) echo "Usage: 'basename $ 0' {start | stop} speed (kb/s) "esac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.