5

OpenVPN 限制流量带宽

 2 years ago
source link: https://zhangrr.github.io/posts/20211018-openvpn_limit_bandwidth/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

OpenVPN 限制流量带宽

2021-10-18 1 分钟阅读

公司安装了 openvpn ,带来方便,但是也有很多不便的地方,机房的总带宽就那么多。

很多人共用 vpn 的时候,就会抢占带宽。

那么,我们需要限制一下,限制 openvpn 所能使用的带宽,避免抢占 WEB 的带宽

做法如下:

由于我们不是要单独限制某一个 openvpn 用户,而是限制整体,所以简单用 TC 就可以了

#!/bin/sh
tc qdisc del dev tun0 root  
tc qdisc add dev tun0 root handle 1: htb default 1
tc class add dev tun0 parent 1: classid 1:1 htb rate 30Mbit ceil 30Mbit
shell

解释一下:

  • 我们 openvpn 启的是 tun0 ,所以限制的对象就是 dev tun0
  • 首先第一行清除 tun0 的根队列
  • 然后第二行建立 tun0 的 root 根队列为 1:0 htb ,缺省是1:1的子队列
  • 最后一行,第三行建立 1:1 的子队列,带宽限制是 30Mbit ,注意这里是大B,就是网络术语中的带宽,换算成小b的话,需要除以8

效果很明显,直接被限制住(41兆而不是30M是因为这台机器是虚机,实体机上还有别的流量):

Float Left


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK