The script can be used to upload the server speed limit, when the business use at peak time, to not affect the normal use of the business, limit the upload speed, to ensure that the normal delivery of services.
The principle is to use the TC (Flow control module) in Linux to achieve the speed limit function.
The script is used as follows:
Start: SH limit.sh start 200 (limit upload speed to 200kb/s)
STOP: SH limit.sh stop
#!/bin/bash#a Simple example for "TC" #set the paramdelay=20speed=$2flow=0# exit Nic network_card=$ (IP ro get 115.29.128.27 | gr EP ETH | awk ' {print $} ') #服务器IPIP_ADDRESS =115.29.128.28start () { /sbin/tc qdisc add dev ${network_card} root handle 1:htb de Fault /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:protoco L IP prio 1 u32 match IP DST ${ip_address}/32 flowid 1:1}stop () { /sbin/tc qdisc dele Dev ${network_card} root}case " "In start" start ; Stop) stop ;; *) echo "Usage: ' basename $ ' {start|stop} speed (kb/s)" Esac
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux Upload speed limit script