V2Ray环境搭建,支持V2Ray协议和Shadowsocks协议

原文转载自http://www.jianshu.com/p/b59150fd8f47

一、简介

V2Ray这个项目出来有一段时间了,一直有关注,不过官方文档不是很详细,而且项目改动很大。直到这几天,才发现已经发布了1.9版本,加上支持Shadowsocks协议。于是花了一个多小时时间看文档,在自己VPS搭建了一下,记下搭建过程。

二、环境

服务器:Ubuntu 14.04 LTS 256MB Ram
客户端:Mac OS X 10.11.4,Chrome浏览器,iTerm2

三、试用

发布页下载操作系统支持的相应客户端,打开命令行模式(CMD或者iTerm):
./v2ray
在Chrome浏览器SwithyOmega插件中添加代理:
SOCKS5 127.0.0.1:1080
试试看是不是能打开Google了?
或者再开一个命令行窗口,测试一下:
curl -v --socks5-hostname 127.0.0.1:1080 https://www.google.com/

四、使用自己VPS搭建

但用别人服务器有很大限制,我们把服务器地址换成自己的。
  • ssh登陆自己的vps,下载一键安装命令:
wget https://raw.githubusercontent.com/v2ray/v2ray-core/master/release/install-release.sh
  • 安装
sudo chmod +x install-release.sh
sudo ./install-release.sh
没有问题的话,已经安装好了
主程序在/usr/bin/v2ray/v2ray,配置文件在/etc/v2ray/config.json
我的系统是systemd,刚才一键安装已经设定好了,可以通过
sudo service v2ray start | stop | restart | status
来配置
PS 如果安装没有成功,可以通过文后的引用文章参考配置

五、参数配置

在配置的时候绕了很大坑,不过总算搞定了。
下面贴出设置好的,相应部分修改成自己的配置就好了:
注意
  • 配置文件中的//注释全部去掉才能正常工作,json不能加注释?第一个坑
  • 相应的ip, port, uuid建议按照自己的设置一下

v2ray-client.json

客户端配置文件,或者这里下载
{
  "port": 1080,
  "log": {
    "access": ""
  },
  "inbound": {
    "protocol": "socks",
    "settings": {
      "auth": "noauth",
      "udp": false,
      "ip": "127.0.0.1"
    }
  },
  "outbound": {
    "protocol": "vmess",
    "settings": {
      "vnext": [
        {
          "address": "1.2.3.4", //服务器VPS IP地址
          "port": 12345, //通讯端口,客户端和服务端一致,自定
          "users": [
            {
              "id": "293c95b0-a4a2-47d5-b6eb-da8e6894e7b8", //UUID 在这个网站随机生成一个,https://www.uuidgenerator.net, 要保证client和server配置一个UUID
              "alterId": 55 // 这个自定,数字范围0-100,但要保证客户端和服务端一致
            }
          ]
        }
      ]
    }
  },
  "outboundDetour": [
    {
      "protocol": "freedom",
      "settings": {},
      "tag": "direct"
    }
  ],
  "routing": {
    "strategy": "rules",
    "settings": {
      "rules": [
        {
          "type": "field",
          "port": "54-79",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "81-442",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "port": "444-65535",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "domain": [
            "gc.kis.scr.kaspersky-labs.com"
          ],
          "outboundTag": "direct"
        },
        {
          "type": "chinasites",
          "outboundTag": "direct"
        },
        {
          "type": "field",
          "ip": [
            "0.0.0.0/8",
            "10.0.0.0/8",
            "100.64.0.0/10",
            "127.0.0.0/8",
            "169.254.0.0/16",
            "172.16.0.0/12",
            "192.0.0.0/24",
            "192.0.2.0/24",
            "192.168.0.0/16",
            "198.18.0.0/15",
            "198.51.100.0/24",
            "203.0.113.0/24",
            "::1/128",
            "fc00::/7",
            "fe80::/10"
          ],
          "outboundTag": "direct"
        },
        {
          "type": "chinaip",
          "outboundTag": "direct"
        }
      ]
    }
  }
}

v2ray-server.json

服务端配置文件,或者这里下载
{
  "port": 12345, //通讯端口,客户端和服务端一致,自定
  "log" : {
    "access": "/var/log/v2ray/access.log", 
    "error": "/var/log/v2ray/error.log",  
    "loglevel": "warning"                  
  },
  "inbound": {
    "protocol": "vmess",    
    "settings": {
      "clients": [
        {
          "id": "293c95b0-a4a2-47d5-b6eb-da8e6894e7b8",  //UUID 在这个网站随机生成一个,https://www.uuidgenerator.net, 要保证client和server配置一个UUID
          "alterId": 55,  // 这个自定,数字范围0-100,但要保证客户端和服务端一致
          "level": 1  // 官方说明,0 共享VPS, 1 自用VPS
        }
      ]
    }
  },
  "outbound": {
    "protocol": "freedom",  
    "settings": {}
  },
  "inboundDetour": [
    {
      "protocol": "shadowsocks",   // 此段为支持SS协议部分
      "port": 1234, 
      "settings": {
        "method": "chacha20", // 加密协议支持aes-256-cfb, aes-128-cfb, chacha20 (V2Ray 1.9+), chacha20-ietf (V2Ray 1.9+)
        "password": "v2ray",     
        "udp": false             //是否支持UDP中转
      }
    }
  ],
  "outboundDetour": [
    {
      "protocol": "blackhole",  
      "settings": {},
      "tag": "blocked"
    }
  ],
  "routing": {
    "strategy": "rules",
    "settings": {
      "rules": [
        {
          "type": "field",  
          "ip": [
            "0.0.0.0/8",
            "10.0.0.0/8",
            "100.64.0.0/10",
            "127.0.0.0/8",
            "169.254.0.0/16",
            "172.16.0.0/12",
            "192.0.0.0/24",
            "192.0.2.0/24",
            "192.168.0.0/16",
            "198.18.0.0/15",
            "198.51.100.0/24",
            "203.0.113.0/24",
            "::1/128",
            "fc00::/7",
            "fe80::/10"
          ],
          "outboundTag": "blocked"
        }
      ]
    }
  }
}

六、使用

1、使用自带协议:

上面的配置文件相应修改完后,
测试本地配置文件是否正确
./v2ray --test --config v2ray-client.json
没有问题,启动本地客户端
./v2ray --config v2ray-client.json
设置服务端配置:
sudo cp v2ray-server.json /etc/v2ray/config.json
测试配置文件是否正确
sudo /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json
没有问题后,启动服务器
sudo service v2ray start
经测试,上面的配置文件兼容Shadowsocks,所以可以两种方式使用V2Ray:
  • 使用V2Ray自带带协议。需要V2Ray客户端后台启动才能运行。
  • 使用Shadowsocks兼容协议,加密协议支持aes-256-cfb, aes-128-cfb, chacha20 (V2Ray 1.9+), chacha20-ietf (V2Ray 1.9+)加密算法。可以使用Surge/GoagentX/ShadowsocksX 运行。

七、参考引用

  1. V2Ray GitHub发布页
  2. V2Ray设置文档
  3. V2Ray for Windows Client and Debian Server
  4. Ubuntu环境下V2ray配置教程
  5. V2Ray完全使用教程
  6. 简易配置VPS V2Ray 服务端、客户端
  7. 使用v2ray科学上网
  8. V2ray科学上网
  9. Online UUID Generator
  10. V2Ray开发讨论组


作者:crystone
链接:http://www.jianshu.com/p/b59150fd8f47
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

0 评论: