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