Configure V2Ray(Shadowsocks mode) + 加速:普通BBR/魔改BBR on KVM VPS (Tested on Ubuntu 16.04)


First of all, you will need to deploy a VPS with KVM technology as BBR does not support OpenVZ but KVM. I recommend Bandwagonhost and Vultr because of the price. Here is the link to register and deploy:
Bandwagonhost
Vultr
(Or click here to get a big discount, only available for a LIMITED TIME)

Here I suggest you choose Ubuntu 16.04 or later versions as your OS. After everything is ready and you can successfully ping your server from your local environment, connect to your VPS via SSH. Now let's start.

Step 1: V2RAY
V2RAY is a new generation of software for data proxy. It supports almost all protocols. Here let's choose Shadowsocks as our protocol with which most of us are familiar.

Type in the following command in your SSH terminal to install:
bash <(curl -L -s https://install.direct/go.sh)
Then use your favorite text editor to edit the configuration file located at '/etc/v2ray/config.json'. Here I use vim as my editor and you can use whatever you are used to. Please notice that after the installation, there will be already a default 'config.json'. You can backup it and create a new one with exactly the same name 'config.json' and the same path.
vim /etc/v2ray/config.json

Now use the following configuration as the content of your 'config.json'.
{
  "inbounds": [
    {
      "port": 1024, // 监听端口
      "protocol": "shadowsocks",
      "settings": {
        "method": "aes-128-gcm",
        "ota": false, // 是否开启 OTA
        "password": "sspasswd"
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",  
      "settings": {}
    }
  ]
}
You can change the port, method, ota (Once-Token-Auth, I strongly recommend you NOT to enable it as it may increase the risk of being detected by Chinese GFW.) and password to fit your own environment.

Then restart the service by either 'reboot' or 'service v2ray restart' command.

Step 2: Enable BBR
This is very useful because BBR(congestion control algorithm) can boost your Internet speed. Without BBR, the download speed via proxy may be several times lower. Nowadays as the softwares are more and more demanding for Internet bandwidth, the network speed and efficiency of the VPS become very critical. In my opinion, BBR is not just a recommendation but a must do.

To use BBR, kernel version should be higher than 4.9.3. So let's upgrade our kernel to a newer version.
sudo apt update
sudo apt install --install-recommends linux-generic-hwe-16.04

To confirm the upgrade is successful, please use the following command to see the kernel version.
uname -r
魔改BBR doesn’t support the kernel version later than 4.12. If you want to use 魔改BBR, a 4.12 kernel is needed. The commands above is not recommended because that may install a kernel later than 4.12. Please use the following method:
For 64-bit OS:
cd /tmp/

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12/linux-headers-4.12.0-041200_4.12.0-041200.201707022031_all.deb

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12/linux-headers-4.12.0-041200-generic_4.12.0-041200.201707022031_amd64.deb

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12/linux-image-4.12.0-041200-generic_4.12.0-041200.201707022031_amd64.deb

sudo dpkg -i *.deb
for 32-bit OS:
cd /tmp/

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12/linux-headers-4.12.0-041200_4.12.0-041200.201707022031_all.deb

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12/linux-headers-4.12.0-041200-generic_4.12.0-041200.201707022031_i386.deb

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.12/linux-image-4.12.0-041200-generic_4.12.0-041200.201707022031_i386.deb

sudo dpkg -i *.deb
BBR is natively supported by new linux kernel. A few configurations are enough to enable the BBR. Open the '/etc/sysctl.conf' file with your favorite editor, then find net.core.default_qdisc (if not exist, create one at the bottom of 'sysctl.conf') and configure it to 'fq'. Find net.ipv4.tcp_congestion_control (if not exist, create one at the bottom of 'sysctl.conf') and configure it to 'bbr'. Or if you never configured BBR before on your VPS, just use the following command to achieve this step.
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf 
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
Then activate the modifications:
sysctl -p

To see if BBR is successfully enabled, you can refer to the following commands:
sysctl net.ipv4.tcp_available_congestion_control
And
lsmod | grep bbr

This should return something like:
tcp_bbr 20480 14

Step 3: Enable 魔改BBR
The standard BBR has already boosted your network speed to some extent. But that's not enough, especially if you like to watch 1080p videos on Youtube. Thanks to Nanqinlang, a special version of BBR called 魔改BBR is available to boost your network speed to even higher level. 

First, you need to install some packages for cloning and compiling 魔改BBR:
apt install -y gcc git make

Then, download 魔改BBR:
git clone https://github.com/nanqinlang/tcp_nanqinlang-test.git

Enter the newly downloaded source file folder and modify the Makefile with your favorite editor:
cd tcp_nanqinlang* 
vim Makefile

Modify 'gcc-6' in 'modules CC=/usr/bin/gcc-6' to 'gcc' or any other available version on your VPS. You can check the version by simply using the command 'find /usr/bin/gcc*'.

Then, make and install:
make 
make install

Use the following command to check if 魔改BBR is successfully installed:
sysctl net.ipv4.tcp_available_congestion_control

You should see 'nanqinlang' as one of the options.

Now last step, configure nanqinlang as net.ipv4.tcp_congestion_control in '/etc/sysctl.conf' and use 'sysctl -p' to enable it.

评论

此博客中的热门博文

Openwrt路由器上配置shadowsocks透明代理+gfwlist(PAC)

Configure shadowsocks transparent proxy + gfwlist(PAC) on OpenWRT Router

Using Haproxy + shadowsocks (ha + ss) to setup multi ss backend and load balance