Files
nexus/wiki/concepts/SOCKS5代理.md
2026-04-27 16:26:34 +08:00

2.7 KiB
Raw Blame History

SOCKS5代理

SOCKS5本地科学上网代理协议监听 127.0.0.1:10808在 Mac Mini、Ubuntu1、Ubuntu2 上正常运行NAS 上仅本机监听。

Overview

SOCKS5 代理是一种网络协议,通过 SOCKS 代理服务器转发客户端的网络请求,支持 TCP 和 UDP。本方案中各节点通过 v2rayA 或类似代理客户端在本地启动 SOCKS5 代理服务,供本机应用走科学上网通道。

Node Status

|| 节点 | IP | 端口 | 状态 | FRP 暴露 | |------|-----|-----|------|----------| | Mac Mini M4 | 127.0.0.1 | 10808 | 正常 | — | | Ubuntu Server 1 | 127.0.0.1 | 10808 | 正常 | — | | Ubuntu Server 2 | 127.0.0.1 | 10808 | 正常 | — | | Synology NAS | 127.0.0.1 | 20170 | 仅本机监听 | 否 |

Usage Patterns

终端命令级ProxyChains

ProxyChains 通过 LD_PRELOAD 劫持 socket 调用,强制任意终端命令走 SOCKS5 代理:

# /etc/proxychains4.conf
socks5 127.0.0.1 10808

# 使用
proxychains4 curl https://google.com

Git 全局代理

Git 不读取系统环境变量,必须显式配置:

git config --global http.proxy socks5://127.0.0.1:10808
git config --global https.proxy socks5://127.0.0.1:10808

Docker Daemon 代理

通过 systemd drop-in 文件注入环境变量:

# /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=socks5://127.0.0.1:10808"
Environment="HTTPS_PROXY=socks5://127.0.0.1:10808"

Docker 容器环境变量

# 容器内使用 ALL_PROXY 环境变量
docker run -e ALL_PROXY=socks5://172.24.0.1:10808 ...

Key Distinction: socks5 vs socks5h

  • socks5DNS 解析在本地完成,可能 DNS 污染
  • socks5hDNS 解析由代理服务器完成,防止本地 DNS 污染
    curl -x socks5h://127.0.0.1:10808 https://google.com
    

Docker 网络网关 IP

Docker 容器内访问宿主机的 IP 不是 127.0.0.1(那是容器自身),而是 Docker 网络网关 IP

  • bridge 网络默认:172.17.0.1
  • 自定义网络(如 compose 项目):172.24.0.1