欢迎光临
IDC人自己的网站

AlmaLinux 9/10 Dante-server S5代理服务器 多出口IP 部署指南


📝 AlmaLinux 9/10 Dante-server 部署指南

1. 系统约定

  • 操作系统:AlmaLinux 9 / 10
  • 主服务器公网 IP:自动获取(curl 获取)
  • 出口 IP 段:9.9.9.2 - 9.9.9.252
  • 代理协议:Socks5
  • 端口范围:10001 - 10252

2. 环境检查

2.1 更新系统

dnf update -y

2.2 安装常用工具

dnf install -y epel-release wget curl vim net-tools iproute iptables

2.3 检查 IP 是否绑定

ip addr show

确认 9.9.9.2-252 已绑定到网卡。


3. 防火墙配置

3.1 开放端口范围

firewall-cmd --permanent --add-port=10001-10252/tcp
firewall-cmd --reload
firewall-cmd --list-ports

4. 安装 Dante-server

dnf install -y dante-server

5. 配置文件生成脚本

Dante 默认配置比较复杂,我们写一个脚本自动生成 /etc/sockd.conf,实现 端口 ↔ 出口 IP 一一对应

5.1 /usr/local/bin/gen_dante_cfg.sh

#!/bin/bash
# 自动生成 Dante 配置文件
# 用法: ./gen_dante_cfg.sh 9.9.9.2-252

if [ -z "$1" ]; then
    echo "用法: $0 <出口IP范围,例如 9.9.9.2-252>"
    exit 1
fi

MAIN_IP=$(curl -s ifconfig.me)
if [ -z "$MAIN_IP" ]; then
    echo "无法获取主机公网 IP"
    exit 1
fi

BASE=$(echo $1 | cut -d. -f1-3)   # 9.9.9
START=$(echo $1 | cut -d. -f4 | cut -d- -f1) # 2
END=$(echo $1 | cut -d- -f2)                # 252

CFG=/etc/sockd.conf
BASE_PORT=10000

cat > $CFG <<EOF
logoutput: /var/log/danted.log
internal: $MAIN_IP port = 10001-10252
method: none
user.privileged: root
user.unprivileged: nobody

client pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
    log: connect disconnect error
}
EOF

for i in $(seq $START $END); do
    ip="$BASE.$i"
    port=$((BASE_PORT + i))
    cat >> $CFG <<EOF
route {
    from: 0.0.0.0/0 to: 0.0.0.0/0 via: $ip port = $port
}
EOF
done

cat >> $CFG <<EOF

socks pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
    log: connect disconnect error
}
EOF

echo "✅ Dante 配置文件已生成: $CFG"

使用方法:

chmod +x /usr/local/bin/gen_dante_cfg.sh
/usr/local/bin/gen_dante_cfg.sh 9.9.9.2-252

6. 启动文件脚本

6.1 Systemd 服务文件 /etc/systemd/system/danted.service

[Unit]
Description=Dante SOCKS Proxy Server
After=network.target

[Service]
ExecStart=/usr/sbin/sockd -f /etc/sockd.conf
Restart=always

[Install]
WantedBy=multi-user.target

启用服务:

systemctl daemon-reexec
systemctl enable --now danted
systemctl status danted

7. 测试代理出口脚本

7.1 Bash 版 /usr/local/bin/test_proxies.sh

#!/bin/bash
# 批量测试 Dante 代理出口 IP
# 用法: ./test_proxies.sh 1.1.1.1 10001 10252

if [ $# -lt 3 ]; then
    echo "用法: $0 <主机IP> <起始端口> <结束端口>"
    exit 1
fi

SERVER_IP=$1
START_PORT=$2
END_PORT=$3

for port in $(seq $START_PORT $END_PORT); do
    result=$(curl -s --max-time 5 --socks5 $SERVER_IP:$port https://api.ipify.org)
    if [ -n "$result" ]; then
        echo "[OK] $SERVER_IP:$port → 出口IP: $result"
    else
        echo "[FAIL] $SERVER_IP:$port"
    fi
done

使用方法:

chmod +x /usr/local/bin/test_proxies.sh
/usr/local/bin/test_proxies.sh 1.1.1.1 10001 10252

✅ 总结

  1. 环境检查 → 确认 IP、更新系统
  2. 防火墙 → 开放端口范围
  3. 安装 Dantednf install dante-server
  4. 配置文件生成脚本 → 自动生成 /etc/sockd.conf,实现端口 ↔ 出口 IP 映射
  5. systemd 启动脚本 → 后台运行
  6. 测试脚本 → 验证出口 IP
赞(0)
未经允许不得转载:IDC头条 » AlmaLinux 9/10 Dante-server S5代理服务器 多出口IP 部署指南

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

全国首家专注IDC行业的垂直自媒体

我要投稿互帮互助