Skip to content

Instantly share code, notes, and snippets.

@doorbash
Created December 18, 2022 09:50
Show Gist options
  • Save doorbash/582b6ab6262f40280705ae4a18a43bc9 to your computer and use it in GitHub Desktop.
Save doorbash/582b6ab6262f40280705ae4a18a43bc9 to your computer and use it in GitHub Desktop.
Set maximum upload/download speed limit to your linux server/pc's selected network interface.
#!/bin/bash
#usage: sudo IF=eth0 UPLOAD_SPEED_LIMIT=300kbps DOWNLOAD_SPEED_LIMIT=300kbps ./script.sh
modprobe ifb numifbs=1
ip link set dev ifb0 up
tc qdisc delete dev $IF handle ffff: ingress
tc qdisc add dev $IF handle ffff: ingress
tc filter add dev $IF parent ffff: protocol ip u32 match u32 0 0 action mirred egress redirect dev ifb0
tc qdisc delete dev $IF root
tc qdisc add dev $IF root handle 1: htb default 1
tc class add dev $IF parent 1: classid 1:1 htb rate $UPLOAD_SPEED_LIMIT
tc qdisc delete dev ifb0 root
tc qdisc add dev ifb0 root handle 1: htb default 1
tc class add dev ifb0 parent 1: classid 1:1 htb rate $DOWNLOAD_SPEED_LIMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment