点击注册订购clash/ssr/v2ray小火箭等机场节点。69折优惠码:XN2023

Linux下使用v2ray

v2ray是一个强大的代理工具,但苦于Linux下一直没有一个好用的客户端,便萌生了直接使用裸v2ray的念头.v2ray本身是不区分服务端和客户端的,只要配置好相关文件,即可正常使用.

安装v2ray

下载v2ray core

1https://github.com/v2ray/v2ray-core/releases/

解压:

1unzip v2ray-linux-64.zip -d v2ray-linux-64

解压后使用mv将相应的文件放置到对应的路径

1 2 3 4 5 6 7 8 910v2ray -> /usr/local/bin/v2rayv2ctl -> /usr/local/bin/v2ctlgeoip.dat -> /usr/local/share/v2ray/geoip.datgeosite.dat -> /usr/local/share/v2ray/geosite.datconfig.json -> /usr/local/etc/v2ray/config.jsonaccess.log -> /var/log/v2ray/access.logerror.log -> /var/log/v2ray/error.logv2ray.service -> /etc/systemd/system/v2ray.servicev2ray@.service -> /etc/systemd/system/v2ray@.service

日志文件要保证所有人都有读写权限

要在配置文件中指定日志路径

配置文件

注意原生的V2ray并不支持订阅。

以下配置文件仅为参考,你可以将其它客户端中的配置文件完全导出,然后直接替换/usr/local/etc/v2ray/config.json

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99100101102103104105106107108109{ “dns”: { “hosts”: { “domain:googleapis.cn”: “googleapis.com” }, “servers”: [ “1.1.1.1” ] }, “inbounds”: [ { “listen”: “127.0.0.1”, “port”: 10808, “protocol”: “socks”, “settings”: { “auth”: “noauth”, “udp”: true, “userLevel”: 8 }, “sniffing”: { “destOverride”: [ “http”, “tls” ], “enabled”: true }, “tag”: “socks” }, { “listen”: “127.0.0.1”, “port”: 10809, “protocol”: “http”, “settings”: { “userLevel”: 8 }, “tag”: “http” } ], “log”: { “loglevel”: “warning”, “access”:”/var/log/v2ray/access.log”, “error”:”/var/log/v2ray/error.log” }, “outbounds”: [ { //此处根据具体设置 “mux”: { “concurrency”: -1, “enabled”: false }, “protocol”: “vmess”, “settings”: { “vnext”: [ { //此处根据具体设置 “address”: “example.com”, “port”: 10000, “users”: [ { “alterId”: 0, “id”: “xxxxxxxxxxxx”, “level”: 8, “security”: “auto” } ] } ] }, “streamSettings”: { “network”: “tcp”, “security”: “” }, “tag”: “proxy” }, { “protocol”: “freedom”, “settings”: {}, “tag”: “direct” }, { “protocol”: “blackhole”, “settings”: { “response”: { “type”: “http” } }, “tag”: “block” } ], “policy”: { “levels”: { “8”: { “connIdle”: 300, “downlinkOnly”: 1, “handshake”: 4, “uplinkOnly”: 1 } }, “system”: { “statsOutboundUplink”: true, “statsOutboundDownlink”: true } }, “routing”: { “domainStrategy”: “IPIfNonMatch”, “rules”: [] }, “stats”: {}}使用V2ray12345678# 启动V2raysudo systemctl start v2ray# 检查V2ray状态sudo systemctl status v2ray# 设置V2ray开机自启动sudo systemctl enable v2ray检验代理是否成功生效

终端下使用curl,查看它在代理模式下是否能返回数据:

1curl -x socks5://127.0.0.1:10808 https://www.google.com -v

如果能返回google.com的源代码,即表示配置成功。

如果显示超时或者无法建立连接,即表示配置有错误,具体可以查看日志排查原因。

系统设置

当我们配置好代理后,我们很多情况下并不能开箱即用,而是需要将代理信息写入相关配置文件后,才能使用。具体操作如下:

设置处启用代理,并填入相关端口

打开设置,选择网络->代理->手动 并填入相应端口

此操作后可以使用浏览器测试是否能正常打开网页,如果还是失败的话,考虑修改浏览器自带的代理配置。

将代理设置写入shell profile

虽然我们设置了系统代理,但是终端下并不会走代理,所以还要配置以下设置

将此行写入用户的shell profile如果使用的是bash,写入~/.bashrc,如果是zsh,写入~/.zshrc如果不确定,就直接写入~/.bashrc

123//端口具体情况具体对待,不清楚打开代理工具看一下.export ALL_PROXY=”socks5://127.0.0.1:10808″export http_proxy=”http://127.0.0.1:10809″

然后我们要让配置文件生效.

1source ~/.bashrc

如果还是无法走代理可以试试重开一个终端.

使用proxychains

对于某些不会走socks5的应用,我们还可以通过proxychains,使它强制走代理

123/etc/proxychains.conf//编辑配置文件,取消sock4配置,加入这一行socks5 127.0.0.1 10808

此后,直接在原始命令前加一个proxychains,便可走代理.比如:

1proxychains wget https://example.com/index.htmlssh走socks5代理1ssh -o “ProxyCommand=nc -X 5 -x 127.0.0.1:10808 %h %p” user@hostname

其中端口按实际情况修改,如果想永久保持使用,可以使用alias做一个别名。

注意这里需要先安装nc

1alias pssh=’ssh -o “ProxyCommand=nc -X 5 -x 127.0.0.1:10808 %h %p”‘

这里为了区分原始的ssh,我们创建了一个pssh,下次对于需要使用代理的,把ssh换成pssh即可.将此行写入用户的shell profile如果使用的是bash,写入~/.bashrc,如果是zsh,写入~/.zshrc如果不确定,就直接写入~/.bashrc


比丘资源网 » Linux下使用v2ray

提供最优质的资源集合

立即查看 了解详情