O que eu quero alcançar é:
-Para CADA conexão com a porta UDP 2222, eu quero limitar a banda up / down a 2mbps para cada ip conectado. - Os usuários conectados obtêm o endereço virtual de 10.8.0.4 a 10.8.0.255, portanto, podemos limitar cada um desses blocos e alcançar o que precisamos.
O que eu tentei é, no final de uma pesquisa de 2 dias eu editei um script bash: O problema é que limita os ips mas eles não são exatamente a banda, por exemplo Se eu rodar um speedtest com apenas 1 máquina ( ninguém está usando a largura de banda do que isso) Estou recebendo 15mbps velocidade de download altoguh deve ser 10mbps
#!/bin/bash
# Name of the traffic control command.
TC=/sbin/tc
# The network interface we're planning on limiting bandwidth.
start() {
ADDRESSES="10.8.0.6 10.8.0.7 10.8.0.8 10.8.0.9 10.8.0.11 10.8.0.12 10.8.0.13 10.8.0.14 10.8.0.15 10.8.0.16 10.8.0.17 10.8.0.18 10.8.0.19 10.8.0.20"
$TC qdisc add dev tun0 root handle 1: htb default 10
$TC class add dev tun0 parent 1: classid 1:1 htb rate 10mbps ceil 10mbps
$TC class add dev tun0 parent 1:1 classid 1:10 htb rate 1mbps ceil 2mbps
$TC class add dev tun0 parent 1:1 classid 1:11 htb rate 4mbps ceil 6mbps
for A in $ADDRESSES
do
$TC filter add dev tun0 protocol ip parent 1:0 prio 1 u32 match ip src $A flowid 1:11
done
# Hierarchical Token Bucket (HTB) to shape bandwidth
}
stop() {
# Stop the bandwidth shaping.
$TC qdisc del dev tun0 root
}
restart() {
# Self-explanatory.
stop
sleep 1
start
}
show() {
# Display status of traffic control status.
$TC -s qdisc ls dev tun0
}
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 tun0:"
show
echo ""
;;
*)
pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show}"
;;
esac
exit 0
Eu também tentei isso, mas o problema disso é quando duas máquinas diferentes que obtiveram os ips acima, por exemplo, 10.8.0.6 e 10.8.0.7, o total de 10mbit é compartilhado entre eles. O que eu quero é que cada ip possa ter no máximo 10mbit e eles podem ter isso separadamente.
#!/bin/bash
# Name of the traffic control command.
TC=/sbin/tc
# The network interface we're planning on limiting bandwidth.
start() {
$TC qdisc del dev tun0 root
ADDRESSES="10.8.0.6 10.8.0.7 10.8.0.8 10.8.0.9 10.8.0.10 10.8.0.11 10.8.0.12 10.8.0.13 10.8.0.14 10.8.0.15 10.8.0.16 10.8.0.17 10.8.0.18 10.8.0.19 10.8.0.20"
$TC qdisc add dev tun0 root handle 1: htb default 10
counter=1
while [ $counter -le 15 ]
do
echo $counter
$TC class add dev tun0 parent 1: classid 1:$counter htb rate 10mbit
((counter++))
done
counter=1
for A in $ADDRESSES
do
$TC filter add dev tun0 parent 1: protocol ip prio 16 u32 match ip dst $A
flowid 1:$counter
echo $A
done
# Hierarchical Token Bucket (HTB) to shape bandwidth
}
stop() {
# Stop the bandwidth shaping.
$TC qdisc del dev tun0 root
}
restart() {
# Self-explanatory.
stop
sleep 1
start
}
show() {
# Display status of traffic control status.
$TC -s qdisc ls dev tun0
}
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 tun0:"
show
echo ""
;;
*)
pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show}"
;;
esac
exit 0
Tags linux traffic-shaping