一个高效的协议转换工具,支持将 SOCKS5/HTTP 代理转换为 Trojan 协议。
安装好socks2trojan后,直接复制下面命令,设置trojan节点,设置好立即生效无需重启(下面节点已经失效)
socks2trojan set --trojan 'trojan://2fbc7e66-a9ad-476b-86a2-8c8a6bedf764@107.172.80.82:4433?sni=www.bing.com&allowInsecure=1'
可以通过邀请好友访问网址获得免费流量,足够用来下载各种镜像。
Socks2Trojan 主要用于优化服务器访问各类资源的速度,特别适用于:
- Docker 镜像拉取
- NPM 包下载
- PIP 包安装
- 其他需要加速的网络请求
核心原理是将 SOCKS5 和 HTTP 代理请求转换为 Trojan 协议,通过 Trojan 节点进行安全且高效的数据传输。
如果您的服务器数据安全性要求较高,并且您对socks2trojan的安全性存在疑虑,我们建议您考虑购买阿里云或腾讯云的服务器,安装socks2trojan,并配置代理地址以实现外网访问。通过在您的服务器上修改HTTP或SOCKS代理地址为运行socks2trojan的地址,可以显著提高安全性。
# x86_64 系统:
wget https://proxy.v2gh.com/https://github.com/developer-over/socks2trojan/releases/latest/download/socks2trojan_amd64.deb
sudo apt install ./socks2trojan_amd64.deb
# arm64 系统:
wget https://proxy.v2gh.com/https://github.com/developer-over/socks2trojan/releases/latest/download/socks2trojan_arm64.deb
sudo apt install ./socks2trojan_arm64.deb# x86_64 系统:
wget https://proxy.v2gh.com/https://github.com/developer-over/socks2trojan/releases/latest/download/socks2trojan.x86_64.rpm
sudo yum install ./socks2trojan.x86_64.rpm
# arm64 系统:
wget https://proxy.v2gh.com/https://github.com/developer-over/socks2trojan/releases/latest/download/socks2trojan.aarch64.rpm
sudo yum install ./socks2trojan.aarch64.rpmgit clone https://github.com/developer-over/socks2trojan.git
cd socks2trojan
tar -zxvf socks2trojan-linux-x86_64-musl.tar.gz
chmod +x socks2trojan
rm -rf socks2trojan-linux-x86_64-musl.tar.gz# Intel 芯片
wget https://proxy.v2gh.com/https://github.com/developer-over/socks2trojan/blob/main/socks2trojan-macos-x86_64.tar.gz
tar -zxvf socks2trojan-macos-x86_64.tar.gz
chmod +x socks2trojan
# Apple Silicon 芯片
wget https://proxy.v2gh.com/https://github.com/developer-over/socks2trojan/blob/main/socks2trojan-macos-aarch64.tar.gz
tar -zxvf socks2trojan-macos-aarch64.tar.gz
chmod +x socks2trojan📝 注意:如果遇到克隆困难,可以:
- 使用 Gitee 镜像仓库
- 直接下载仓库后通过
scp或rsync传输到服务器
# 查看帮助
socks2trojan --help
# 设置配置
socks2trojan set --trojan "trojan://password@address:port?sni=server_name&allowInsecure=1"
# 或分别设置
socks2trojan set --address "1.2.3.4" \
--port 443 \
--password "your-password" \
--server-name "your-sni" \
--alpn "h2" \
--insecure true \
--socks "127.0.0.1:1080" \
--http "127.0.0.1:8080"
# 查看当前配置
socks2trojan show
# 启动服务
socks2trojan start
# 停止服务
socks2trojan stop
# 设置系统代理
socks2trojan proxy
# 取消系统代理
socks2trojan proxy --disable- SOCKS5h: DNS 解析由代理服务器执行
- 更安全
- 防止 DNS 泄露
- 避免 DNS 污染
- SOCKS5: DNS 解析在本地执行
- 响应更快
- 存在 DNS 泄露风险
推荐使用 SOCKS5h 以获得更好的安全性
HTTP 代理默认将 DNS 解析委托给代理服务器,天然具有防止 DNS 污染的特性。
下图展示了使用 Socks2Trojan 加速 Docker 镜像拉取的效果。左侧窗口显示 Socks2Trojan 运行状态,右侧窗口展示 Docker 拉取过程:
注意:运行日志中可能出现的断开连接提示是正常现象,不会影响实际使用。
Socks2Trojan 提供了一个简单而强大的解决方案,通过协议转换实现了资源访问加速。它的灵活配置和易用性使其成为服务器优化的理想工具。配置完成后,您将获得:
- 更快的 Docker 镜像拉取速度
- 更稳定的 NPM 包管理体验
- 更高效的 PIP 包安装过程
- 其他网络请求的显著提升
命令如下
root@test:~# pwd
/root
root@test:~# ls
socks2trojan_amd64.deb
root@test:~# apt install ./socks2trojan_amd64.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'socks2trojan' instead of './socks2trojan_amd64.deb'
The following NEW packages will be installed:
socks2trojan
0 upgraded, 1 newly installed, 0 to remove and 83 not upgraded.
After this operation, 15.0 MB of additional disk space will be used.
Get:1 /root/socks2trojan_amd64.deb socks2trojan amd64 1.15 [3588 kB]
Selecting previously unselected package socks2trojan.
(Reading database ... 117244 files and directories currently installed.)
Preparing to unpack /root/socks2trojan_amd64.deb ...
Unpacking socks2trojan (1.15) ...
Setting up socks2trojan (1.15) ...
Failed to enable unit: Unit file /etc/systemd/system/socks2trojan.service is masked.
Failed to start socks2trojan.service: Unit socks2trojan.service is masked.
socks2trojan.service is a disabled or a static unit not running, not starting it.
W: Repository is broken: socks2trojan:amd64 (= 1.15) has no Size information
N: Download is performed unsandboxed as root as file '/root/socks2trojan_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)
root@test:~#
root@test:~# curl ifconfig.cc
85.9.54.71root@test:~#
root@test:~#
root@test:~# socks2trojan start
╭────────────────────────────────────────────────╮
│ SOCKS2Trojan │
│ │
├────────────────────────────────────────────────┤
│ SOCKS5 to Trojan Protocol Converter │
├────────────────────────────────────────────────┤
│ 下面地址有免费节点: │
│ https://github.com/developer-over/socks2trojan │
│ │
╰────────────────────────────────────────────────╯
Service started in background.
root@test:~# socks2trojan set --trojan 'trojan://ec0c3165-b2d7-428b-a5cf-5a683412cb59@138.128.223.175:443?sni=m.ctrip.com&allowInsecure=1'
Configuration updated successfully!
root@test:~#
root@test:~# socks2trojan proxy
╭────────────────────────────────────────────────────────────────────────────╮
│ Run these commands to set system proxy: │
├────────────────────────────────────────────────────────────────────────────┤
│ export http_proxy=http://127.0.0.1:8080 │
│ export HTTP_PROXY=http://127.0.0.1:8080 │
│ export all_proxy=socks5h://127.0.0.1:1080 │
│ export ALL_PROXY=socks5h://127.0.0.1:1080 │
╰────────────────────────────────────────────────────────────────────────────╯
root@test:~# export ALL_PROXY=socks5h://127.0.0.1:1080
root@test:~# curl ifconfig.cc
138.128.223.175root@test:~#
root@test:~#
root@test:~# socks2trojan proxy --disable
╭────────────────────────────────────────────────────────────────────────────╮
│ Run these commands to unset system proxy: │
├────────────────────────────────────────────────────────────────────────────┤
│ unset http_proxy HTTP_PROXY all_proxy ALL_PROXY │
╰────────────────────────────────────────────────────────────────────────────╯
root@test:~# unset http_proxy HTTP_PROXY all_proxy ALL_PROXY
root@test:~# socks2trojan stop
Service stopped successfully.
root@test:~#
root@test:~# apt remove socks2trojan
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
socks2trojan
0 upgraded, 0 newly installed, 1 to remove and 83 not upgraded.
After this operation, 15.0 MB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 117250 files and directories currently installed.)
Removing socks2trojan (1.15) ...
root@test:~# # 修改代理服务器监听地址,无需手动重启,立即生效
socks2trojan set --socks "0.0.0.0:1080"
socks2trojan set --http "0.0.0.0:8080"
# 查看当前配置
socks2trojan show
apt remove socks2trojan

