Centos 下配置 V2ray 客户端

2025年8月28日 0 条评论 53 次阅读 0 人点赞

一、前言

每逢国家大事,网络总是会出点问题。近日就在 Linux 服务器上拉不下 Github 代码让我颇为头疼。

直接上解决方案,自建的 trojan-go 不太行,但是从tomatossr 买的可以。

二、安装 V2ray Linux 客户端

https://github.com/v2ray/v2ray-core/releases/tag/v4.28.2

下载完毕上传至服务器进行解压

解压完毕会有一个 config.json 的文件,这个文件就是 v2ray 的 Linux 客户端配置文件。

三、黏贴配置

导出现有配置,黏贴进 服务器 config.json 下

四、校验配置并启动

执行命令校验配置

./v2ray -test config.json

不出意外会返回以下内容表示校验 OK

V2Ray 4.28.2 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.15.2 linux/amd64)
A unified platform for anti-censorship.
2025/08/28 22:28:55 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message> 
v2ctl> Read config:  ./config.json
2025/08/28 22:28:55 [Warning] v2ray.com/core: V2Ray 4.28.2 started
[root@iZf8z1sryc3u6tm5k9z7f2Z local]# ./v2ray -test config.json]# 
V2Ray 4.28.2 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.15.2 linux/amd64)
A unified platform for anti-censorship.
2025/08/28 22:28:59 Using default config:  /usr/local/config.json
2025/08/28 22:29:00 [Info] v2ray.com/core/common/platform/ctlcmd: <v2ctl message> 
v2ctl> Read config:  /usr/local/config.json
Configuration OK.

启动命令

./v2ray -config config.json

测试联通性命令: curl -x socks5://127.0.0.1:10808 https://github.com

五、配置curl、wget等命令使用代理

编辑 /etc/profile 环境变量

# 设置http代理
export http_proxy=socks5://127.0.0.1:10808
​
# 设置https代理
export https_proxy=socks5://127.0.0.1:10808
​
# 设置ftp代理
export ftp_proxy=socks5://127.0.0.1:10808
​
# 17.16.x.x为我们自己的云服务器的内网IP 配置为no_proxy代表内网传输不走代理
export no_proxy="172.16.x.x"

刷新环境变量 source /etc/profile

这样我 curl 的时候就不需要携带 -x sockes 了

因此直接尝试 curl -v 'https://www.google.com' 畅通无阻

六、让代理失效

不要以为 注释了 export 并且source /etc/profile 就能让代理失效

至少你得重新开个窗口,才会失效。如果想让代理失效请执行以下命令

unset http_proxy
unset https_proxy
unset ftp_proxy
unset no_proxy

七、配置 Git SSH 走代理

SSH 的代理依赖 NC 命令

没装的先装 yum install -y nmap-ncat

在配置之前先测试

nc -v --proxy-type socks5 --proxy 127.0.0.1:10808 github.com 22

看看能否输出如下

Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to proxy 127.0.0.1:10808
Ncat: No authentication needed.
Ncat: connection succeeded.
SSH-2.0-5dfa2843

能输出就说明 SSH 走 socket5 代理配置没问题。

编辑: vim ~/.ssh/config

填写内容如下所示

Host github.com
  # 通过 V2Ray 的 SOCKS5 代理(端口 10808 对应配置中的 socks 入站)
  ProxyCommand nc -v --proxy-type socks5 --proxy  127.0.0.1:10808 %h %p
  # 可选:指定连接超时时间
  ConnectTimeout 10

此时 ssh 拉 github.com 的主机就会走 socket5 代理

兰陵美酒郁金香

大道至简 Simplicity is the ultimate form of sophistication.

文章评论(0)

你必须 登录 才能发表评论