一、安裝
1、安裝 socks5
sudo apt-get install dante-server
安裝完后可使用 danted -v
查看版本信息
2、創建日志文件
touch /var/log/socks5.log
3、創建用戶
sudo useradd -s /sbin/nologin test -g proxy
passwd test
二、danted.conf 配置文件常用參數
# 指定日志文件保存的絕對路徑
logoutput:/var/log/socks5
# 綁定網卡跟端口
internal: 0.0.0.0 port=1080 # 進口 IP 或 網卡
external: eth0 port=1080 # 出口 IP 或 網卡
# 設置 socks 身份驗證方式
socksmethod: username # 如為 none 則表示不進行身份驗證(rfc931)
socksmethod: pam # pam 身份驗證
# 設置客戶端規則
clientmethod: none
# 用戶相關
user.privileged: proxy # 當做一些需要特權的事情時,會使用 proxy 用戶的權限(默認有該行)
user.unprivileged: nobody # 正常運行時,使用非特權用戶 ID(默認有該行)
# 如果編譯時支持 libwrap,使用的用戶 ID( libwrap:服務程序安全增強工具,對有狀態連接的特定服務進行安全檢測並實現訪問控制)
user.libwrap: nobody # 默認有該行
# 兼容性相關
compatibility: sameport # 當客戶端連接后,socks 服務器將嘗試使用與客戶端使用的端口相同(需設置為 root 特權)
compatibility: reuseaddr # 允許端口復用(加了此行會報錯,此處解釋僅作參考)
# 啟用綁定擴展
extension: bind
# 超時設置
timeout.negotiate: 30 # 設置連接超時時間
timeout.io: 0 # 設置空閑超時時間(0 為永不超時)
# 接受來自地址(DNS)的連接
srchost: nodnsunknown nodnsmismatch
# 設置訪問規則
client pass {
from: 0.0.0.0/0 port 1-65535 to: 0.0.0.0/0
clientmethod: rfc931 # 匹配密碼文件中的所有 ID 用戶
}
client pass {
from: 0.0.0.0/0 port 1-65535 to: 0.0.0.0/0
log: connect disconnect error # 記錄連接、斷開、報錯信息
}
socks pass {
from: 10.0.0.0/8 to: 0.0.0.0/0
protocol: tcp udp
}
# 設置拒絕規則
client block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: connect disconnect error # 記錄連接、斷開、報錯信息
}
socks block {
from: 0.0.0.0/0 port 1-65535 to: 192.168.1.0/24
log: connect disconnect error # 記錄連接、斷開、報錯信息
}
socks block {
from: 0.0.0.0/0 to: lo0
log: connect disconnect error # 記錄連接、斷開、報錯信息
}
socks block { # 阻止任何其他地址連接到 example.com 域
from: 0.0.0.0/0 to: .example.com port = http
log: connect disconnect error # 記錄連接、斷開、報錯信息
}
# 添加路由(服務器鏈接)
route {
from: 10.0.0.0/8 to: 0.0.0.0/0 port = http via: socks.example.net port = socks
}
三、配置 SOCKS5
在 danted.conf
文件末尾添加如下內容
# 指定日志文件保存的絕對路徑
logoutput: /var/log/socks5.log
# 進口 IP 或 網卡
internal: eth0 port = 8888
# 進口網卡及端口
internal: eth0 port = 9999
# 出口網卡
external: eth0
# 設置代理方式(rfc931)
socksmethod: username none
# 設置客戶端規則
clientmethod: none
# 設置用戶權限
user.privileged: root
# 非特權用戶
user.notprivileged: nobody
# 如果編譯時支持 libwrap,使用的用戶 ID( libwrap:服務程序安全增強工具,對有狀態連接的特定服務進行安全檢測並實現訪問控制)
user.libwrap: nobody
# 設置訪問規則
client pass {
from: 0.0.0.0/0 port 1-65535 to: 0.0.0.0/0
# 記錄連接、斷開、報錯信息
log: connect disconnect error
}
socks pass {
from: 0.0.0.0/0 port 1-65535 to: 0.0.0.0/0
protocol: tcp udp
}
停止服務:systemctl stop danted
啟動服務:systemctl start danted
重啟服務:systemctl restart danted
查看服務狀態:systemctl status danted