v2ray多用户配置

部分网友自行搭建好v2ray科学上网环境后,不好意思拒绝朋友的分享请求,所以想设置一个不同的端口或者id再分享。类似的需求v2ray都是支持的,配置起来也不算麻烦。本文就v2ray普通版、伪装版分别介绍v2ray多用户配置。

注意:自行更改配置文件需要用到 vi/vim/nano 等编辑器,或者把配置文件下载到本地修改,修改完再上传到服务端。下载和上传教程请参考:Bitvise连接Linux服务器教程(Windows用户)、Mac电脑连接Linux教程(Mac用户)。

普通版多用户配置

v2ray一键脚本 运行完后,会输出配置文件路径,默认是 /etc/v2ray/config.json,其内容类似这样:

{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 12345,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "6be0aa25-09c1-4d8b-a96f-75cd3485021f",
          "level": 1,
          "alterId": 53
        }
      ]
    }
  }],
  "outbounds": [{
    "protocol": "freedom",
    "settings": {}
  },{
    "protocol": "blackhole",
    "settings": {},
    "tag": "blocked"
  }],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      }
    ]
  }
}

下文教程的修改都是参考这个文件,如果出现问题,请注意与原来文件的差异。

v2ray多用户分成两种:同端口不同id,不同端口不同id。v2ray两种类型都支持,接下来分别做介绍。

同端口不同id

这是最简单的配置多用户方式。方法是编辑 /etc/v2ray/config.json 文件,在”clients“一节中增加新增用户配置。例如在上面配置基础上增加一个用户:

{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 12345,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "6be0aa25-09c1-4d8b-a96f-75cd3485021f",
          "level": 1,
          "alterId": 53
        }, # 逗号不能少
        # 下面是新增的内容
        {
          "id": "2a1292fd-07be-37e7-af20-57668b4a546a",  # id可以用 /usr/bin/v2ray/v2ctl uuid生成
          "level": 1, # 这个不用改
          "alterId": 63 # 建议50-150之间的一个整数
        }
        # 新增内容结束
      ]
    }
  }],
  # 下面的内容保持不变

注意:“#”和后面的东西都不能出现在配置文件中,上面只是为了解释说明。

编辑好文件后,重启 v2ray:systemctl restart v2ray。如果命令失败,或者 netstat -nltp | grep v2ray 输出为空,说明配置文件有错误,请仔细检查,改好后再重启。

接下来就可以用新的id和alterId配置客户端,其余信息保持不变。

不同端口不同id

如果希望端口也不一样,请按照如下步骤做:

1. 首先编辑 /etc/v2ray/config.json 文件,按照”inbounds“格式新增入口和用户。例如新增一个端口和用户后,配置文件变成:

{
  "log": {
    "loglevel": "info",
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log"
  },
  "inbounds": [{
    "port": 12345,
    "protocol": "vmess",
    "settings": {
      "clients": [
        {
          "id": "6be0aa25-09c1-4d8b-a96f-75cd3485021f",
          "level": 1,
          "alterId": 53
        }
      ]
    }
  }, # 逗号不能省,原来这里是"}],"
  # 以下是新增的配置
  {
    "port": 54321, # 端口是1000-65535之间的一个整数
    "protocol": "vmess", # 也可以改成其他协议,如果你知道怎么配置的话
    "settings": {
      "clients": [
        {
          "id": "24813255-228d-b0e0-c3fa-e5d4c9defda1", # id可以用 /usr/bin/v2ray/v2ctl uuid生成
          "level": 1, # 0或1都可以
          "alterId": 57 # 建议50-150之间的一个整数
        }
      ]
    }
  }],
  # 新增内容结束
  # 下面的内容保持不变

注意:“#”和后面的东西都不能出现在配置文件中,上面只是为了解释说明。

编辑好文件后,重启 v2ray:systemctl restart v2ray。如果命令失败,或者 netstat -nltp | grep v2ray 输出为空,说明配置文件有错误,请仔细检查,改好后再重启。

2. 设置防火墙放行新增的端口。CentOS系统命令是:

firewall-cmd --permanent --add-port=54321/tcp # 注意:54321要改成你的端口号
firewall-cmd --permanent --add-port=54321/udp # 注意:54321要改成你的端口号
firewall-cmd --reload

Ubuntu系统命令是:

ufw allow 54321/tcp # 注意:54321要改成你的端口
ufw allow 54321/udp # 注意:54321要改成你的端口

接下来用新的端口、id和alterId配置客户端,其余信息保持不变。

带伪装多用户配置

同端口不同id的配置和普通版操作方法一样,配置好后重启v2ray就行了,这里不再重复。

接下来说说不同端口不同id的情形。伪装有了Nginx的介入,所以有多种情况,这里只介绍最简单的一种实现方式。

1. 编辑 /etc/v2ray/config.json 文件,按照 普通版同端口不同id 中的方法添加用户;

2. 编辑 /etc/nginx/conf.d/你的域名.conf 文件,找到 “listen 443 ssl http2;” 这一行,在这行下面添加“listen 新的端口号 ssl http2;”一行(新的端口号要改成整数,例如8443,不能是443)。然后保存文件, nginx -t 检查配置有没有错误,没有错误的话重启Nginx:systemctl restart nginx

3. 设置防火墙放行端口,请参考 普通版设置防火墙 中的命令。

接下来用新的端口、id和alterId配置客户端,其余信息保持不变。

如果你想添加多个端口或多个用户,重复上面的过程就可以了。

《v2ray多用户配置》上有22条评论

      1. 我是从V2Ray一键脚本那全部安装完过来,有显示输出配置文件路径( /etc/v2ray/config.json),也安装Bitvise,但是看不懂编辑这个文件,因为不知道从哪里找到它,电脑上搜不到这个文件,sftp程序里没看到。请问哪里找到这个文件来修改

  1. 家里有2个电脑,其中一个可以上网,另外一个不行,不知道是不是要设置多用户。不能上网在跳这些信息

    2021/03/13 11:02:20 tcp:127.0.0.1:53354 accepted tcp:content-autofill.googleapis.com:443 [proxy]
    2021/03/13 11:02:22 tcp:127.0.0.1:53363 accepted tcp:content-autofill.googleapis.com:443 [proxy]
    2021/03/13 11:02:23 [Warning] [2459978721] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: failed to find an available destination > v2ray.com/core/common/retry: [dial tcp 74.120.173.164:12345: connectex: No connection could be made because the target machine actively refused it. dial tcp 74.120.173.164:12345: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.] > v2ray.com/core/common/retry: all retry attempts failed
    2021/03/13 11:02:23 tcp:127.0.0.1:53370 accepted tcp:content-autofill.googleapis.com:443 [proxy]
    2021/03/13 11:02:24 [Warning] [2337294508] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: failed to find an available destination > v2ray.com/core/common/retry: [dial tcp 74.120.173.164:12345: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. dial tcp 74.120.173.164:12345: connectex: No connection could be made because the target machine actively refused it. dial tcp 74.120.173.164:12345: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. dial tcp 74.120.173.164:12345: operation was canceled] > v2ray.com/core/common/retry: all retry attempts failed
    2021/03/13 11:02:25 [Warning] [2745463675] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: failed to find an available destination > v2ray.com/core/common/retry: [dial tcp 74.120.173.164:12345: connectex: No connection could be made because the target machine actively refused it.] > v2ray.com/core/common/retry: all retry attempts failed
    2021/03/13 11:02:25 tcp:127.0.0.1:53380 accepted tcp:www.youtube.com:443 [proxy]
    2021/03/13 11:02:26 [Warning] [424468231] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: failed to find an available destination > v2ray.com/core/common/retry: [dial tcp 74.120.173.164:12345: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. dial tcp 74.120.173.164:12345: connectex: No connection could be made because the target machine actively refused it.] > v2ray.com/core/common/retry: all retry attempts failed
    2021/03/13 11:02:26 tcp:127.0.0.1:53385 accepted tcp:www.youtube.com:443 [proxy]
    2021/03/13 11:02:27 [Warning] [2861394707] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/vmess/outbound: failed to find an available destination > v2ray.com/core/common/retry: [dial tcp 74.120.173.164:12345: connectex: No connection could be made because the target machine actively refused it.] > v2ray.com/core/common/retry: all retry attempts failed
    2021/03/13 11:02:27 tcp:127.0.0.1:53391 accepted tcp:www.youtube.com:443 [proxy]

    1. 把V2RayN重新设置一次,现在全部跳一样内容,就是数值改变
      2021/03/13 11:29:39 tcp:127.0.0.1:51262 accepted tcp:content-autofill.googleapis.com:443 [proxy]

        1. 俩边都不能用了。。因为重新按照一键脚本来一遍,Bitvise也一遍,现在都卡在Bitvise提示其他进程占用80或443端口,请先关闭再运行一键脚本。

  2. 请问UUID怎么保存?
    比如换了服务器,或者重装了系统。
    原来的UUID都失效了,全部账户都要重新建。

  3. 如果把自己电脑配置好的V2ray拷贝到朋友的电脑上,是否能正常运行?

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注