linux安装使用v2ray客户端,配置全局模式和PAC模式

V2Ray 是一个与 Shadowsocks 类似的代理软件,不过V2Ray 更全能。V2Ray是一个网络转发程序,支持 TCP、mKCP、WebSocket 这3种底层传输协议,支持HTTP、Socks、Shadowsocks、VMess这4种内容传输协议(HTTP只支持传入),并且有完整的TLS实现,是一个非常强大的平台。

系统要求:debian 9及以上(对应的ubuntu16.04版本及以上,deepin15.9)

为了方便,这里使用deepin15.9示例,(ubuntu与deepin的步骤和使用命令是一致的)

这里假设你有一台已经配置好V2Ray 的服务器端,下面展示如何在linux下配置V2Ray 客户端,实现科学上网。

一、安装V2Ray

1、下载官方的V2Ray客户端脚本:

wget https://install.direct/go.sh

下载的go.sh文件会存放在终端当前面目录下:

2、执行go.sh脚本

使用命令

sudo bash go.sh

或者添加go.sh文件执行权限,然后执行

chmod u+x go.sh
./go.sh

安装成功后路径/etc/v2ray下会生成一个配置文件config.json (config.backup是之后本人对配置文件的备份)

 

 

二、修改配置文件config.json
打开路径/etc/v2ray下会生成的配置文件config.json:

原始配置文件:

修改后的配置文件:

关键注意配置中inbounds和outbounds的属性,需要注意修改的地方以下带有中文注释

// Config file of V2Ray. This file follows standard JSON format, with comments support.
// Uncomment entries below to satisfy your needs. Also read our manual for more detail at
// https://www.v2ray.com/
{
  "log": {
    // By default, V2Ray writes access log to stdout.
    // "access": "/path/to/access/log/file",

    // By default, V2Ray write error log to stdout.
    // "error": "/path/to/error/log/file",

    // Log level, one of "debug", "info", "warning", "error", "none"
    "loglevel": "warning"
  },
  // List of inbound proxy configurations.
  "inbounds": [{
    // Port to listen on. You may need root access if the value is less than 1024.
    "port": 1080,  //客户端本地监听端口,必须与本地代理端口一致

    // IP address to listen on. Change to "0.0.0.0" to listen on all network interfaces.
    "listen": "127.0.0.1",

    // Tag of the inbound proxy. May be used for routing.
    "tag": "socks-inbound",

    // Protocol name of inbound proxy.
    "protocol": "socks", //入口协议

    // Settings of the protocol. Varies based on protocol.
    "settings": {
      "auth": "noauth",
      "udp": false,
      "ip": "127.0.0.1"
    },

    // Enable sniffing on TCP connection.
    "sniffing": {
      "enabled": true,
      // Target domain will be overriden to the one carried by the connection, if the connection is HTTP or HTTPS.
      "destOverride": ["http", "tls"]
    }
  }],
  // List of outbound proxy configurations.
  "outbounds": [
    {
      "sendThrough": "0.0.0.0",
      "mux": {
        "enabled": false,
        "concurrency": 8
      },
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "XXX.XXX.XX.XX", //服务起IP地址,必须修改为自己VPS的地址
            "users": [
              {
                "id": "XXXXXXX-XXXX-44ac-b6fe-XXXXXXXXXX", //UID,必须与服务器一致
                "alterId": 64, //与服务器一致
                "security": "aes-128-gcm", //与服务器一致
                "level": 1 //与服务器一致
              }
            ],
            "port": XXXXX //服务器端口必须与服务器一致
          }
        ]
      },
      "tag": "XXXX", //配置名称,可选
      "streamSettings": {
        "wsSettings": {
          "path": "",
          "headers": {}
        },
        "quicSettings": {
          "key": "key",
          "security": "none",
          "header": {
            "type": "none"
          }
        },
        "tlsSettings": {
          "allowInsecure": false,
          "alpn": [
            "http/1.1"
          ],
          "serverName": "server.cc",
          "allowInsecureCiphers": false
        },
        "httpSettings": {
          "path": ""
        },
        "kcpSettings": {
          "header": {
            "type": "none"
          },
          "mtu": 1350,
          "congestion": false,
          "tti": 50,
          "uplinkCapacity": 5,
          "writeBufferSize": 2,
          "readBufferSize": 2,
          "downlinkCapacity": 20
        },
        "tcpSettings": {
          "header": {
            "type": "none"
          }
        },
        "security": "none",
        "network": "tcp",
        "sockopt": {}
      }
    }
  ],

  // Transport is for global transport settings. If you have multiple transports with same settings
  // (say mKCP), you may put it here, instead of in each individual inbound/outbounds.
  //"transport": {},

  // Routing controls how traffic from inbounds are sent to outbounds.
  "routing": {
    "domainStrategy": "IPOnDemand",
    "rules":[
      {
        // Blocks access to private IPs. Remove this if you want to access your router.
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      },
      {
        // Blocks major ads.
        "type": "field",
        "domain": ["geosite:category-ads"],
        "outboundTag": "blocked"
      }
    ]
  },

  // Dns settings for domain resolution.
  "dns": {
    // Static hosts, similar to hosts file.
    "hosts": {
      // Match v2ray.com to another domain on CloudFlare. This domain will be used when querying IPs for v2ray.com.
      "domain:v2ray.com": "www.vicemc.net",

      // The following settings help to eliminate DNS poisoning in mainland China.
      // It is safe to comment these out if this is not the case for you.
      "domain:github.io": "pages.github.com",
      "domain:wikipedia.org": "www.wikimedia.org",
      "domain:shadowsocks.org": "electronicsrealm.com"
    },
    "servers": [
      "1.1.1.1",
      {
        "address": "114.114.114.114",
        "port": 53,
        // List of domains that use this DNS first.
        "domains": [
          "geosite:cn"
        ]
      },
      "8.8.8.8",
      "localhost"
    ]
  },

  // Policy controls some internal behavior of how V2Ray handles connections.
  // It may be on connection level by user levels in 'levels', or global settings in 'system.'
  "policy": {
    // Connection policys by user levels
    "levels": {
      "0": {
        "uplinkOnly": 0,
        "downlinkOnly": 0
      }
    },
    "system": {
      "statsInboundUplink": false,
      "statsInboundDownlink": false
    }
  },

  // Stats enables internal stats counter.
  // This setting can be used together with Policy and Api. 
  //"stats":{},

  // Api enables gRPC APIs for external programs to communicate with V2Ray instance.
  //"api": {
    //"tag": "api",
    //"services": [
    //  "HandlerService",
    //  "LoggerService",
    //  "StatsService"
    //]
  //},

  // You may add other entries to the configuration, but they will not be recognized by V2Ray.
  "other": {}
}

 

三、配置PAC代理模式

1、安装GenPAC

pip install genpac

2、生产pac文件

genpac --format=pac --pac-proxy="SOCKS5 127.0.0.1:1080" -o /home/jtian/Softwares/V2Ray/autoproxy.pac

3、配置本地系统代理

打开系统代理(ubuntu的类似):

选择自动模式(Auto),并在配置路径(configuaration URL)中填入上述产生的PAC文件(以 file:// 开头):

file:///home/jtian/Softwares/V2Ray/autoproxy.pac

 

然后确定保存, 上述便是PAC代理模式的系统设置。选择PAC模式代理的小伙伴可以直接跳过下属PS(全局代理)

PS:若是想全局代理模型,则在系统代理是选择手动(Manual),并在设置代理端口为1080(与V2Ray的入口端口一致)

四、启动V2Ray

完成上述配置后,启动V2Ray即可科学上网

启动V2Ray:

sudo systemctl start v2ray

停止运行V2Ray:

sudo systemctl stop v2ray

重启V2Ray

sudo systemctl restart v2ray

PS:每次修改配置文件请重启V2Ray

至此,可以愉快的科学上网

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章