v2ray安装

v2ray安装

服务端安装

## v2ray
bash <(curl -s -L https://git.io/v2ray.sh)  
## ui+v2ray
bash <(curl -Ls https://blog.sprov.xyz/v2-ui.sh)

客户端安装

  1. 下载当前最新版本v2ray-linux-64,解压到/opt目录下

  2. 解压并修改config.json配置,示例如下

    {
     "policy": null,
     "log": {
       "access": "",
       "error": "",
       "loglevel": "warning"
     },
     "inbounds": [
       {
         "tag": "proxy",
         "port": 10808,
         "listen": "0.0.0.0",
         "protocol": "socks",
         "sniffing": {
           "enabled": false,
           "destOverride": [
             "http",
             "tls"
           ]
         },
         "settings": {
           "auth": "noauth",
           "udp": true,
           "ip": null,
           "address": null,
           "clients": null
         },
         "streamSettings": null
       }
     ],
     "outbounds": [
       {
         "tag": "proxy",
         "protocol": "vmess",
         "settings": {
           "vnext": [
             {
               "address": "152.32.185.152",
               "port": 1990,
               "users": [
                 {
                   "id": "92d875e7-b505-4202-cf9c-f190f7d3f9db",
                   "alterId": 64,
                   "email": "t@t.tt",
                   "security": "auto"
                 }
               ]
             }
           ],
           "servers": null,
           "response": null
         },
         "streamSettings": {
           "network": "tcp",
           "security": null,
           "tlsSettings": null,
           "tcpSettings": {
             "connectionReuse": true,
             "header": {
               "type": "http",
               "request": {
                 "version": "1.1",
                 "method": "GET",
                 "path": [
                   "/"
                 ],
                 "headers": {
                   "Host": [
                     ""
                   ],
                   "User-Agent": [
                     "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
                     "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46"
                   ],
                   "Accept-Encoding": [
                     "gzip, deflate"
                   ],
                   "Connection": [
                     "keep-alive"
                   ],
                   "Pragma": "no-cache"
                 }
               },
               "response": null
             }
           },
           "kcpSettings": null,
           "wsSettings": null,
           "httpSettings": null,
           "quicSettings": null
         },
         "mux": {
           "enabled": true
         }
       },
       {
         "tag": "direct",
         "protocol": "freedom",
         "settings": {
           "vnext": null,
           "servers": null,
           "response": null
         },
         "streamSettings": null,
         "mux": null
       },
       {
         "tag": "block",
         "protocol": "blackhole",
         "settings": {
           "vnext": null,
           "servers": null,
           "response": {
             "type": "http"
           }
         },
         "streamSettings": null,
         "mux": null
       }
     ],
     "stats": null,
     "api": null,
     "dns": null,
     "routing": {
       "domainStrategy": "IPIfNonMatch",
       "rules": [
         {
           "type": "field",
           "port": null,
           "inboundTag": "api",
           "outboundTag": "api",
           "ip": null,
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": [
             "152.32.185.152"
           ],
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": [
             "geoip:private"
           ],
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": [
             "geoip:cn"
           ],
           "domain": null
         },
         {
           "type": "field",
           "port": null,
           "inboundTag": null,
           "outboundTag": "direct",
           "ip": null,
           "domain": [
             "geosite:cn"
           ]
         }
       ]
     }
    }
  3. 修改v2ray目录下systemed/v2ray.service,如下

    ExecStart=ExecStart=/opt/v2ray-linux-64/v2ray -config /opt/v2ray-linux-64/config.json
  4. 执行命令

    cp systemd/v2ray.service /lib/systemd/system/
    systemctl start v2ray
    systemctl enable v2ray

PAC代理模式

  • 安装pip后安装genpac
sudo apt install python3-pip
sudo pip3 install genpac
  • 生成pac文件
genpac --pac-compress --pac-proxy 'SOCKS5 127.0.0.1:10808' --format pac  -o /opt/v2ray-linux-64/auto.pac
# 其他语法
genpac [-h|--help] [-v|version]
       [-p PROXY|--proxy=PROXY]
       [--gfwlist-url=URL] [--gfwlist-proxy=PROXY]
       [--gfwlist-local=FILE] [--update-gfwlist-local]
       [--user-rule=RULE] [--user-rule-from=FILE]
       [-c|--config-from=FILE] [-o|--output=FILE]
       [-z|--compress]
       [--base64]

可选参数:
  -h, --help                帮助
  -v, --version             版本信息
  -p PROXY, --proxy=PROXY   PAC文件中使用的代理信息,如:
                              SOCKS 127.0.0.1:8080
                              SOCKS5 127.0.0.1:8080; SOCKS 127.0.0.1:8080
                              PROXY 127.0.0.1:8080
  --gfwlist-proxy=PROXY     获取gfwlist时的代理设置,如果你可以正常访问gfwlist,则无必要使用该选项
                            格式为 "代理类型 [用户名:密码]@地址:端口" 其中用户名和密码可选,如:
                              SOCKS5 127.0.0.1:8080
                              SOCKS5 username:password@127.0.0.1:8080
  --gfwlist-url=URL         gfwlist地址,一般不需要更改,默认:
                              https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
  --gfwlist-local=FILE      本地gfwlist文件地址,当在线地址获取失败时使用
  --update-gfwlist-local    当在线gfwlist成功获取且gfwlist-local存在时,更新gfwlist-local内容
  --user-rule=RULE          自定义规则,该选项允许重复使用,如:
                              --user-rule="@@sina.com"
                              --user-rule="||youtube.com"
  --user-rule-from=FILE     从文件中读取自定义规则,该选项允许重复使用
  -c FILE, --config-from=FILE
                            从文件中读取配置信息
  -o FILE, --output=FILE    输出生成的文件,如果没有此选项,将直接打印结果
  -z, --compress            压缩输出
  --base64                  base64加密输出,注意:部分浏览器并不支持经过base64加密的pac文件
  • 在deepin的 设置–网络–系统代理–自动 填入pac文件位置:

    file:///opt/v2ray-linux-64/auto.pac
  • chrome设置 chrome在linux环境不支持系统代理时,许通过第三方扩展选取pac文件进行代理控制。