SOCKS5 是傳輸層代理協定,支援 TCP/UDP、認證機制、IPv6,幾乎能代理所有基於 TCP/IP 的應用層協定。ss5 是輕量級的 SOCKS5 伺服器實作,適合在 Linux 伺服器快速建立代理服務。
# CentOS/RHEL
yum install -y pam-devel openldap-devel openssl-devel gcc make
# Ubuntu/Debian
apt-get install -y libpam0g-dev libldap2-dev libssl-dev build-essential
wget https://downloads.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz
tar xzf ss5-3.8.9-8.tar.gz
cd ss5-3.8.9
./configure
make && make install
編輯 /etc/opt/ss5/ss5.conf:
# 認證方式:u = 使用者名稱/密碼驗證
auth 0.0.0.0/0 - u
# 允許規則:u = 需驗證使用者,允許所有來源存取所有目的地
permit u 0.0.0.0/0 - 0.0.0.0/0 - - - -
# 格式:使用者 密碼
echo "myuser mypassword" > /etc/opt/ss5/ss5.passwd
chmod 600 /etc/opt/ss5/ss5.passwd
# 給啟動腳本權限
chmod +x /etc/rc.d/init.d/ss5
# 加入服務管理
chkconfig --add ss5
chkconfig ss5 on
# 啟動
service ss5 start
# 驗證監聽埠(預設 1080)
netstat -lntp | grep ss5
# tcp 0 0 0.0.0.0:1080 0.0.0.0:* LISTEN 12345/ss5
SOCKS5 伺服器IP:1080,輸入帳密。curl -x socks5://user:pass@server:1080 https://ipinfo.io| 錯誤現象 | 原因與解決 |
|---|---|
configure 报错 Some of the headers weren't found | 缺少 PAM 開發套件,yum install pam-devel / apt-get install libpam0g-dev |
| 連線被拒絕 | 防火牆未開放 1080:firewall-cmd --add-port=1080/tcp --permanent && firewall-cmd --reload |
| 認證失敗 | 檢查 ss5.passwd 格式、權限 600、ss5.conf auth/permit 規則 |
| UDP 不通 | ss5 預設支援 UDP,確認防火牆 UDP 1080 亦開放 |
# /etc/systemd/system/ss5.service
[Unit]
Description=SOCKS5 Proxy Server
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/init.d/ss5 start
ExecStop=/etc/rc.d/init.d/ss5 stop
PIDFile=/var/run/ss5/ss5.pid
[Install]
WantedBy=multi-user.target
啟用:systemctl daemon-reload && systemctl enable --now ss5。
