In Linux, it is very easy to use TC to limit the speed between two servers.

Source: Internet
Author: User

Recently Postgres data synchronization, need to simulate the remote room has bandwidth limitations of the synchronization effect, so want to limit the speed between the two machines.

TS command is very powerful, but also very difficult to understand and use, often wasted long time or uncertain.

Here's a simple and easy-to-use script, just set the target IP and the rate at which it needs to be throttled:

#!/bin/bash## TC uses the following units when passed as a parameter.# kbps:kilobytes per second # mbps:megabytes per se cond# kbit:kilobits per second# mbit:megabits per second# bps:bytes per second # amounts of data can be SPECIF IEDinch: # KB or k:kilobytes# MB or m:megabytes# mbit:megabits# kbit:kilobits# to get thebyteFigure from Bits, divide the number by8BIT#TC=/sbin/Tcif=eth0 # Interface DNLD=1mbit # DOWNLOAD LIMITUPLD=1mbit # UPLOAD Limit IP=216.3.128.12# Host IPU32="$TC Filter Add dev $IF protocol IP parent 1:0 prio 1 u32"start () {$TC qdisc add dev $IF root handle1: HTB Default -$TC class Add dev $IF parent1: ClassID1:1HTB Rate $DNLD $TC class add dev $IF parent1: ClassID1:2HTB rate $UPLD $U match IP DST $IP/ +Flowid1:1$U match ip src $IP/ +Flowid1:2}stop () {$TC qdisc del dev $IF root}restart () {StopSleep 1start}show () {$TC-S QdisclsDev $IF} Case " $" inchstart)Echo-N"Starting bandwidth shaping:"StartEcho " Done"    ;; Stop)Echo-N"Stopping bandwidth shaping:"StopEcho " Done"    ;; Restart)Echo-N"Restarting bandwidth shaping:"RestartEcho " Done"    ;; Show)Echo "Bandwidth Shaping status for $IF: \ n"ShowEcho ""    ;; *)    pwd=$(pwd)    Echo "Usage: $ (/usr/bin/dirname $pwd)/tc.bash {start|stop|restart|show}"    ;;EsacExit0

Original address: http://www.iplocation.net/tools/traffic-control.php

Script Address: Http://www.iplocation.net/tc.bash.txt

In Linux, it is very easy to use TC to limit the speed between two servers.

Related Article

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.