V2ray配置实例[最新v2fly]

Linux下推使用V2rayA,安装使用可参考V2rayA客户端使用实例

说明: 从V2Ray 4.27.0开始,请使用新版安装脚本,旧版安装配置实例仅供参考。

新版安装配置实例

服务端安装

下载安装脚本

➜  ~ curl -O https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh  

执行安装脚本

➜  ~ bash ./install-release.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   98k  100   98k    0     0   495k      0 --:--:-- --:--:-- --:--:--  495k
info: Installing V2Ray v4.27.5 for x86_64
Downloading V2Ray archive: https://github.com/v2fly/v2ray-core/releases/download/v4.27.5/v2ray-linux-64.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   644  100   644    0     0   5457      0 --:--:-- --:--:-- --:--:--  5457
100 12.6M  100 12.6M    0     0  8316k      0  0:00:01  0:00:01 --:--:-- 10.2M
Downloading verification file for V2Ray archive: https://github.com/v2fly/v2ray-core/releases/download/v4.27.5/v2ray-linux-64.zip.dgst
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   649  100   649    0     0   2368      0 --:--:-- --:--:-- --:--:--  2368
100   590  100   590    0     0   1053      0 --:--:-- --:--:-- --:--:--  1053
info: Extract the V2Ray package to /tmp/tmp.gWzZRTMMij and prepare it for installation.
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]
removed: /tmp/tmp.gWzZRTMMij
info: V2Ray v4.27.5 is installed.         //安装完成
You may need to execute a command to remove dependent software: dnf remove curl unzip
Please execute the command: systemctl enable v2ray; systemctl start v2ray

配置systemd服务

➜  ~ systemctl enable v2ray //添加systemd服务模块
Created symlink /etc/systemd/system/multi-user.target.wants/v2ray.service → /etc/systemd/system/v2ray.service.
➜  ~ systemctl start v2ray  //开启v2ray服务
➜  ~ service v2ray status  //检查v2ray服务状态
Redirecting to /bin/systemctl status v2ray.service
● v2ray.service - V2Ray Service
   Loaded: loaded (/etc/systemd/system/v2ray.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-09-07 11:16:13 CST; 8s ago
 Main PID: 25897 (v2ray)
    Tasks: 6 (limit: 4566)
   Memory: 4.7M
   CGroup: /system.slice/v2ray.service
           └─25897 /usr/local/bin/v2ray -config /usr/local/etc/v2ray/config.json

Sep 07 11:16:13 bwgcn2 systemd[1]: Started V2Ray Service.
Sep 07 11:16:13 bwgcn2 v2ray[25897]: V2Ray 4.27.5 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.14.7 linux/amd64)
Sep 07 11:16:13 bwgcn2 v2ray[25897]: A unified platform for anti-censorship.
Sep 07 11:16:13 bwgcn2 v2ray[25897]: 2020/09/07 11:16:13 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message>
Sep 07 11:16:13 bwgcn2 v2ray[25897]: v2ctl> Read config:  /usr/local/etc/v2ray/config.json
Sep 07 11:16:13 bwgcn2 v2ray[25897]: 2020/09/07 11:16:13 [Warning] v2ray.com/core: V2Ray 4.27.5 started

服务端配置

默认安装完成后,启用配置文件为/usr/local/etc/v2ray/config.json,但这个默认配置为空,因此需要自定义服务端配置。

{
    "inbounds": [
        {
            "port": 10086, 
            "protocol": "vmess",
            "settings": {
                "clients": [
                    {
                        "id": "b831es1d-6324-4d53-ad4f-8cda2s5e0811"
                    }
                ]
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom"
        }
    ]
}
	

客户端配置

  • Windows客户端配置

下载最新版v2rayN,地址为https://github.com/2dust/v2rayN/releases/

配置参考下图:

“V2rayN配置”

  • Ubuntu客户端配置

安装方法同服务端,编辑/usr/local/etc/v2ray/config.json,如下配置:

{
    "inbounds": [
        {
            "port": 1080, 
            "listen": "127.0.0.1",
            "protocol": "socks",
            "settings": {
                "udp": true
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "vmess",
            "settings": {
                "vnext": [
                    {
                        "address": "127.99.117.94", 
                        "port": 10086, 
                        "users": [
                            {
                                "id": "b831es1d-6324-4d53-ad4f-8cda2s5e0811"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "tag": "direct"
        }
    ],
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "ip": [
                    "geoip:private"
                ],
                "outboundTag": "direct"
            }
        ]
    }
}

旧版安装配置实例

推荐使用WebSocket传输模式,详细配置可参考Nginx V2ray and WebSocket.

首先使用bash <(curl -L -s https://install.direct/go.sh)来快捷安装v2ray,如下:

    root@vm:~# bash <(curl -L -s https://install.direct/go.sh)
    Installing V2Ray v4.18.0 on x86_64
    Downloading V2Ray: https://github.com/v2ray/v2ray-core/releases/download/v4.18.0/v2ray-linux-64.zip
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   608    0   608    0     0    581      0 --:--:--  0:00:01 --:--:--   581
    100 10.5M  100 10.5M    0     0   172k      0  0:01:02  0:01:02 --:--:--  194k
    Extracting V2Ray package to /tmp/v2ray.
    Archive:  /tmp/v2ray/v2ray.zip
      inflating: /tmp/v2ray/config.json  
       creating: /tmp/v2ray/doc/
      inflating: /tmp/v2ray/doc/readme.md  
      inflating: /tmp/v2ray/geoip.dat    
      inflating: /tmp/v2ray/geosite.dat  
       creating: /tmp/v2ray/systemd/
      inflating: /tmp/v2ray/systemd/v2ray.service  
       creating: /tmp/v2ray/systemv/
      inflating: /tmp/v2ray/systemv/v2ray  
      inflating: /tmp/v2ray/v2ctl        
     extracting: /tmp/v2ray/v2ctl.sig    
      inflating: /tmp/v2ray/v2ray        
     extracting: /tmp/v2ray/v2ray.sig    
      inflating: /tmp/v2ray/vpoint_socks_vmess.json  
      inflating: /tmp/v2ray/vpoint_vmess_freedom.json  
    PORT:51332
    UUID:7378f6a4-790a-11e9-8f9e-2a86e4085a59
    Created symlink /etc/systemd/system/multi-user.target.wants/v2ray.service → /etc/systemd/system/v2ray.service.
    V2Ray v4.18.0 is installed.

然后编辑/etc/v2ray/config.json文件,如下设置:

    {
      "inbounds": [{
        "port": 1080,  // SOCKS 代理端口,在浏览器中需配置代理并指向这个端口
        "listen": "127.0.0.1",
        "protocol": "socks",
        "settings": {
          "udp": true
        }
      }],
      "outbounds": [{
        "protocol": "vmess",
        "settings": {
          "vnext": [{
            "address": "server", // 服务器地址,请修改为你自己的服务器 ip 或域名
            "port": 10086,  // 服务器端口
            "users": [{ "id": "b831381d-6324-4d53-ad4f-8cda48b30811" }]
          }]
        }
      },{
        "protocol": "freedom",
        "tag": "direct",
        "settings": {}
      }],
      "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [{
          "type": "field",
          "ip": ["geoip:private"],
          "outboundTag": "direct"
        }]
      }
    }

编辑完成后保存,重新启动v2ray

    root@vm:~# service v2ray stop
    root@vm:~# service v2ray start
    root@vm:~# service v2ray status
    ● v2ray.service - V2Ray Service
       Loaded: loaded (/etc/systemd/system/v2ray.service; enabled; vendor preset: en
       Active: active (running) since Sat 2019-05-18 08:58:43 CST; 5s ago
     Main PID: 8025 (v2ray)
        Tasks: 7 (limit: 2311)
       CGroup: /system.slice/v2ray.service
               └─8025 /usr/bin/v2ray/v2ray -config /etc/v2ray/config.json
    
    5月 18 08:58:43 vm systemd[1]: Started V2Ray Service.
    5月 18 08:58:43 vm v2ray[8025]: V2Ray 4.18.0 (Po) 20190228
    5月 18 08:58:43 vm v2ray[8025]: A unified platform for anti-censorship.
    5月 18 08:58:44 vm v2ray[8025]: 2019/05/18 08:58:44 [Warning] v2ray.com/core: V2

然后Firefox设置代理如下:

设置-常规-网络设置 勾选手动代理配置,在SOCKS主机中填入127.0.0.1本地IP和端口,协议勾选SOCKS_v5 建议勾选使用SOCKSv5时代理DNS查询

20190518090412.webp

发布于