V2Ray

This guide is a simplified version of 新 V2Ray 白话文指南 and implements v2ray + ws + tls + web + cdn. It is totally my own record and therefore assumes some hacker's spirits and ability.

Install Using Docker

Install Docker using this guide

// TODO: continue writing

Install Using Script

To use correct environment for installing, we do:

sudo su
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)

Above commands are from github repo. You might need to go there to see if there is updates

After installation, you will get these files:

installed: /usr/local/bin/v2ray
installed: /usr/local/bin/v2ctl
installed: /usr/local/share/v2ray/geoip.dat
installed: /usr/local/share/v2ray/geosite.dat
installed: /usr/local/etc/v2ray/config.json
installed: /var/log/v2ray/
installed: /var/log/v2ray/access.log
installed: /var/log/v2ray/error.log
installed: /etc/systemd/system/v2ray.service
installed: /etc/systemd/system/[email protected]

And these files matters:

/etc/systemd/system/v2ray.service

[Unit]
Description=V2Ray Service
Documentation=https://www.v2fly.org/
After=network.target nss-lookup.target

[Service]
User=nobody
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json
Restart=on-failure
RestartPreventExitStatus=23

[Install]
WantedBy=multi-user.target

The above is a .service file. If you don't know what it is, take a look at Systemd

/etc/systemd/system/v2ray.service.d/10-donot_touch_single_conf.conf

# In case you have a good reason to do so, duplicate this file in the same directory and make your customizes there.
# Or all changes you made will be lost!
# Refer: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
[Service]
ExecStart=
ExecStart=/usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json

And then you need to enable and start the v2ray service:

systemctl enable v2ray
systemctl start v2ray

Now, we should see v2ray --version outputs:

V2Ray 4.45.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.18.1 linux/amd64)

Note the version vX.Y.Z means this update is the X-th year Y-th week version. If Z==0 then it is stable release and Z==1 is alpha release. The program updates every week to counteract sensorship.

Configuration of Server and Client

The config file is /usr/local/etc/v2ray/config.json for both server side and client side. They both use the same program.

server

{
  "inbounds": [
    {
      "port": listening port,
      "listen":"127.0.0.1",
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "[Your Own UUID]",
            "alterId": 0
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
        "path": "/endpoint"
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

client

{
  "inbounds": [
    {
      "port": 1080,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": ["http", "tls"]
      },
      "settings": {
        "auth": "noauth",
        "udp": false
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "your-website.com",
            "port": 443,
            "users": [
              {
                "id": "[Your Own UUID]",
                "alterId": 0
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "wsSettings": {
          "path": "/endpoint"
        }
      }
    }
  ]
}

Clash Install

To install:

go get -u github.com/Dreamacro/clash

To run:

/home/$USER/go/bin/clash

You could have put it into systemd by writing a .service file, but I am too lazy.

Subscription

To read subscription url to configuration file, we need subconverter.

Logic Behind Subconverter from https://hsingko.github.io/post/2021/07/05/how-to-use-clash-subscribe/

Logic Behind Subconverter from https://hsingko.github.io/post/2021/07/05/how-to-use-clash-subscribe/

./subconverter

If you subscribe with this url https://your-website.com/link/whatever?clash=1, then, after launch subconverter you visit http://127.0.0.1:25500/sub?target=clash&url=https://your-website.com/link/whatever?clash=1.

Table of Content