萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Linux 部署 SOCKS5 代理伺服器:ss5 安裝與設定全紀錄

SOCKS5 是傳輸層代理協定,支援 TCP/UDP、認證機制、IPv6,幾乎能代理所有基於 TCP/IP 的應用層協定。ss5 是輕量級的 SOCKS5 伺服器實作,適合在 Linux 伺服器快速建立代理服務。

安裝步驟

1. 安裝相依套件

# 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

2. 下載編譯安裝

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
  • Proxifier / ProxyChains 全系統代理。

常見問題排查

錯誤現象原因與解決
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 亦開放

進階:systemd 服務單元

# /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。

copyright © 萬盛學電腦網 all rights reserved