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

至此,可以愉快的科學上網

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