使 Centos 上的 CLI 使用 Socks5 Proxy

Tsocks

安装

  1. 进入下载页面
  2. 下载完安装包进行编译安装,具体安装方法可以参考 Proxychains

配置

  • 打开配置文件 #vi /etc/tsocks.conf 后修改以下参数
#local 表示本地的网络,用来表示不用 socks 配置的网络
local = 192.168.1.0/255.255.255.0

# SOCKS 服务器的 IP
server = 127.0.0.1

# SOCKS 服务版本
server_type = 5

# SOCKS 服务使用的端口
server_port = 5401

启动

用 tsocks 运行你的软件很简单,在终端中:
tsocks [command] [args]
我现在运行 Curl 都是这样运行的:
tsocks curl blog.cubat.cc

Proxychains

安装

# git clone https://github.com/rofl0r/proxychains-ng.git
# cd proxychains-ng
# ./configure --prefix=/usr --sysconfdir=/etc
# make && make install && make install-config

配置

打开 vim /etc/proxychains.conf 后在文件末尾加入需要的地址,例如:
socks5 127.0.0.1 5401

启动

和 Tsocks 启动差不多,只需在命令之前加入 Proxychains4 即可
proxychains4 [command] [args]

Ncat

Ncat 是一个专门用于 ssh 的产品,它的使用方法在Centos和Ubuntu上略有差异。

Linux 安装

# apt/yum install nc

Windows 安装

下载 Netcat for win32/64 后将压缩包内的文件解压到 C:\Windows\System32

CentOS 下使用

ssh examplehost.com -o "ProxyCommand=nc --proxy-type socks5 --proxy localhost:7000 %h %p"

Ubuntu 下使用

ssh examplehost.com -o "ProxyCommand=nc -X socks5 -x localhost:7000 %h %p"

参考资料

评论