在 Linux 服务器中设置 v2ray 代理

v2ray 的手册

1. 安装 v2ray

1
sudo apt-get install v2ray

2. 设置config.json配置文件

2.1 提取配置文件

在电脑中安装 v2rayN

v2rayN服务器中导入订阅链接

选择一个节点 > 右键 > 导出所选服务器完整配置 然后就得到config.json配置文件

删除配置文件中"dns"一项,仅保留"inbounds""inbounds"两厢

2.2 导入配置文件

配置文件一般在目录/etc/v2ray/config.json中,删除里面的内容,并粘贴提取到的进去

vim 中输入ggshift+vshift+g删除所有内容

2.3 测试配置文件

1
v2ray -test -config config.json

3. 启动 v2ray

1
2
3
4
5
6
7
8
9
10
11
# 启动V2ray
sudo systemctl start v2ray

# 检查V2ray状态
sudo systemctl status v2ray

# 设置V2ray开机自启动
sudo systemctl enable v2ray

# 取消设置V2ray开机自启动
sudo systemctl disable v2ray

设置代理

临时设置:

1
2
export http_proxy=http://127.0.0.1:10809
export https_proxy=http://127.0.0.1:10809

其中10809为v2ray监听端口

持续化设置则修改文件/etc/profile,在文件结束位置增加如下内容:

1
2
export http_proxy=http://127.0.0.1:10809
export https_proxy=http://127.0.0.1:10809

然后重启或执行命令source /etc/profile

检查端口连通性

1
nc -zv 127.0.0.1 10809

检查端口监听状态

1
lsof -i :10809

检查环境变量

1
2
echo $http_proxy
echo $https_proxy

检查代理

1
curl -v --proxy http://127.0.0.1:10809 https://www.google.com

在 Linux 服务器中设置 v2ray 代理
https://blog.giraffish.me/post/35f1330a/
作者
卖柠檬雪糕的鱼
发布于
2024年11月11日
更新于
2025年3月28日
许可协议