章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • linux

    • rsync

      • rsync用法及参数详解
      • rsync服务实现推送,拉取
    • dns

    • sed、awk、grep、find四剑客

    • LVM管理
    • sudo权限规划
    • linux修改网卡为eth0的两种方法
    • Logrotate入门了解及生产实践
    • linux中用dd命令来测试硬盘读写速度
    • linux 阿里云盘挂载错误
    • CentOS7安装Android SDK
    • centos7安装更新git
    • linux启动顺序
    • centos7升级openssl
    • expect工具的安装和使用方法
    • linux下使用v2ray
      • 安装v2ray
      • 配置文件
      • 使用V2ray
      • 检验代理是否成功生效
      • 系统设置
        • 设置处启用代理,并填入相关端口
        • 将代理设置写入shell profile
        • 使用proxychains
        • ssh走socks5代理
    • centos7安装java环境的两种方式
    • linux-centos7系统设置时区及同步时间
    • rsyslog日志系统:rsyslog配置文件
    • rsyslog的安装、使用、详解
    • safe-rm防止删除重要的文件
    • linux如何获取打开文件和文件描述符数量
    • LVS集群-DR模式
    • linux服务器安装ffmpeg
    • linux服务器安装samba
    • 使用openssl创建自签发证书
    • linux服务器部署next.js服务
    • linux服务器ionice命令使用方式
    • linux服务器curl命令常用操作
  • windows

  • 中间件

  • 网络

  • 安全

  • 存储

  • 防火墙

  • 数据库

  • 系统

  • docker

  • other

  • 监控

  • 运维
  • linux
章工运维
2023-05-31
目录

linux下使用v2ray

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

# 安装v2ray

下载v2ray core

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

解压:

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

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

v2ray -> /usr/local/bin/v2ray
v2ctl -> /usr/local/bin/v2ctl
geoip.dat -> /usr/local/share/v2ray/geoip.dat
geosite.dat -> /usr/local/share/v2ray/geosite.dat
config.json -> /usr/local/etc/v2ray/config.json
access.log -> /var/log/v2ray/access.log
error.log -> /var/log/v2ray/error.log
v2ray.service -> /etc/systemd/system/v2ray.service
v2ray@.service -> /etc/systemd/system/v2ray@.service
1
2
3
4
5
6
7
8
9
  • 日志文件要保证所有人都有读写权限

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

# 配置文件

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

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

{
  "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": {}
}
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
99
100
101
102
103
104
105
106
107
108
109

# 使用V2ray

# 启动V2ray
sudo systemctl start v2ray

# 检查V2ray状态
sudo systemctl status v2ray

# 设置V2ray开机自启动
sudo systemctl enable v2ray
1
2
3
4
5
6
7
8

# 检验代理是否成功生效

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

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

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

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

# 系统设置

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

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

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

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

# 将代理设置写入shell profile

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

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

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

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

source ~/.bashrc
1

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

# 使用proxychains

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

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

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

proxychains wget https://example.com/index.html
1

# ssh走socks5代理

ssh -o "ProxyCommand=nc -X 5 -x 127.0.0.1:10808 %h %p" user@hostname
1

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

注意这里需要先安装nc

alias pssh='ssh -o "ProxyCommand=nc -X 5 -x 127.0.0.1:10808 %h %p"'
1

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


原文链接 (opens new window)

微信 支付宝
上次更新: 2024/11/08, 12:33:03

← expect工具的安装和使用方法 centos7安装java环境的两种方式→

最近更新
01
shell脚本模块集合
05-13
02
生活小技巧(认知版)
04-29
03
生活小技巧(防骗版)
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式