Files
nexus/wiki/concepts/proxychains.md
2026-04-22 08:02:59 +08:00

75 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ProxyChains
## Aliases
- proxychains
- proxychains4
- proxychains-ng
## Definition
ProxyChains 是一个基于 LD_PRELOAD 机制的终端代理劫持工具通过预先加载preload一个共享库来拦截动态链接程序如 curl、wget、git的 socket 系统调用,将网络流量重定向到配置的代理服务器。
## Type
[[概念]]
## Core Mechanism
### LD_PRELOAD 劫持原理
ProxyChains 在运行时通过 `LD_PRELOAD` 环境变量将自己编译的共享库(`libproxychains4.so`)注入到目标程序的进程空间。当目标程序调用 `connect()` 等 socket 函数时,实际调用的是 ProxyChains 提供的包装函数,该函数将连接重定向到配置文件中指定的代理服务器。
### 优势
- **无需源码修改**:任何使用动态链接库的程序均可通过前置 proxychains4 执行而自动走代理
- **透明性**:目标程序无需感知代理的存在
- **灵活性**:支持 socks4 / socks5 / http 多种代理类型
## Configuration
### ProxyChains 配置文件
```bash
sudo nano /etc/proxychains4.conf
```
### ProxyList 配置格式
```ini
[ProxyList]
# 格式: 类型 IP 端口
socks5 127.0.0.1 10808
```
### 使用方式
```bash
# 任何命令前加 proxychains4 前缀即可走代理
proxychains4 curl https://www.google.com
proxychains4 wget https://github.com/example/repo
proxychains4 git clone https://github.com/...
proxychains4 apt-get update
```
## Limitations
- **仅支持动态链接程序**:静态编译的程序(如 alpine 容器中的命令)无法被劫持
- **不支持 UDP**ProxyChains 4.x 主要处理 TCP 连接
- **不支持链式代理**(新版可配置但复杂):建议直接使用单一代理
- **不支持 ICMP**ping 命令无法通过 ProxyChains 走代理
- **DNS 行为**:取决于配置中的 `proxy_dns` 设置socks5h 模式下 DNS 由代理服务器解析
## Related Concepts
- [[SOCKS5 协议]]ProxyChains 最常使用的代理协议
- [[SOCKS5h 代理]]DNS 由代理服务器解析的 SOCKS5 变体,推荐配合 ProxyChains 使用
- [[LD_PRELOAD]]Linux 动态链接库预加载机制ProxyChains 的底层技术基础
- [[环境变量代理]]另一种让程序走代理的方式HTTP_PROXY/HTTPS_PROXY与 ProxyChains 互补
- [[Git 全局代理]]Git 不读取环境变量代理,需要通过 `git config` 显式配置
## Related Entities
- [[v2rayN]]ProxyChains 常见的代理来源(提供 10808 SOCKS5 端口)
- [[代理协议]]ProxyChains 支持 socks4 / socks5 / http 代理协议
## Related Sources
- [[ubuntu-server科学上网]]ProxyChains 的完整配置流程
## Summary
ProxyChains 是 Ubuntu Server 终端场景下"让任意命令走代理"的最灵活方案,通过 LD_PRELOAD 劫持 socket 调用,无需目标程序支持代理。相比 Git 全局代理配置和 Docker Daemon 代理配置ProxyChains 适用范围最广,但仅限于动态链接程序和 TCP 连接。