Last active
March 26, 2018 04:30
-
-
Save VMuliadi/7456fc47a5bdf05143a6d471655f58d8 to your computer and use it in GitHub Desktop.
This gist is modified version of rbrook's shape_bandwidth.sh (https://gist.github.com/rbrooks/2719817)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TC=/sbin/tc | |
IF=wlp2s0 | |
U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32" | |
start() { | |
$TC qdisc add dev $IF root handle 1: htb default 3 | |
$TC class add dev $IF parent 1: classid 1:1 htb rate 300kbps ceil 300kbps | |
$TC class add dev $IF parent 1: classid 1:2 htb rate 200kbps ceil 200kbps | |
$TC class add dev $IF parent 1: classid 1:3 htb rate 150kbps ceil 150kbps | |
$U32 match ip dst 10.42.0.143/32 flowid 1:1 | |
$U32 match ip src 10.42.0.143/32 flowid 1:1 | |
$U32 match ip dst 10.42.0.25/32 flowid 1:2 | |
$U32 match ip src 10.42.0.25/32 flowid 1:2 | |
} | |
stop() { | |
$TC qdisc del dev $IF root | |
} | |
restart() { | |
stop | |
sleep 1 | |
start | |
} | |
show() { | |
$TC -s qdisc ls dev $IF | |
} | |
case "$1" in | |
start) | |
echo -n "Starting bandwidth shaping: " | |
start | |
echo "done" | |
;; | |
stop) | |
echo -n "Stopping bandwidth shaping: " | |
stop | |
echo "done" | |
;; | |
restart) | |
echo -n "Restarting bandwidth shaping: " | |
restart | |
echo "done" | |
;; | |
show) | |
echo "Bandwidth shaping status for $IF:" | |
show | |
echo "" | |
;; | |
*) | |
pwd=$(pwd) | |
echo "Usage: tc.bash {start|stop|restart|show}" | |
;; | |
esac | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment