Dante既可以监听网卡,可可以监听内网ip,请根据业务环境选择。
注:监听网卡和监听ip,两个配置上唯一区别是监听的对象不同,按网卡监听就配置网卡名,按ip监听就配置ip,其它都在一样。
环境:
操作系统:ubuntu 24.04
Dante-serve:v1.4.3
模式:多网卡,多配置模式,实现独立服务管理
认证模式:使用系统用户
公网绑定:多个网卡,没个网卡绑定1个公网ip
流程:
1.创建系统用户
2.安装Dante-serve
3.创建Dante-serve代理配置
4.创建Dante-serve系统服务
5.测试
第一步,创建系统用户
创建系统用户用于socsk5代理认证,使用系统用户来登录代理
| #创建用户
useradd -r -s /usr/sbin/nologin -M <用户名>
#配置密码
passwd <用户名>
|
第二步,安装Dante-serve
| #
apt install dante-server -y
|
第三步,创建Dante-serve代理配置
使用多网卡配置,多服务管理。这里以2个网卡为例:eth0、eth1
eth0代理端口1080
eth1代理端口1081
关键配置:监听网卡、出口网卡
3.1)创建配置目录
| #创建配置目录
mkdir -p /etc/danted.d
|
3.2)写入/etc/danted.d/danted-eth0.conf,eth0代理端口1080
注:监听地址需要是网卡的内网地址!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | # === Dante SOCKS5 配置 - 实例1 ===
logoutput: syslog
# 监听ip就写ip地址,监听网卡就写网卡名
# 监听在网卡 eth0,端口1080
internal: eth0 port = 1080
# 出口也绑定到同一个网卡
external: eth0
# 权限设置
user.privileged: root
user.notprivileged: nobody
# 认证方式:需要用户名密码
clientmethod: none
socksmethod: username
# 允许所有客户端连接(认证在socks层进行)
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error connect disconnect
}
# 仅允许user_socks1用户,且只允许绑定/连接/UDP关联
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
command: bind connect udpassociate
log: error connect disconnect
socksmethod: username
#登录的系统用户名
user: user_socks1
}
# 拒绝其他所有socks请求(若想任意用户可以当前代理,可注释socks block部分)
socks block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error
}
|
3.3)写入/etc/danted.d/danted-eth1.conf,eth1代理端口1081
注:监听地址和出口网卡,需要是你自己的!!!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | # === Dante SOCKS5 配置 - 实例2 ===
logoutput: syslog
# 监听ip就写ip地址,监听网卡就写网卡名
# 监听在网卡 eth1,端口1081
internal: eth1 port = 1081
# 出口也绑定到同一个网卡
external: eth1
# 权限设置
user.privileged: root
user.notprivileged: nobody
# 认证方式:需要用户名密码
clientmethod: none
socksmethod: username
# 允许所有客户端连接(认证在socks层进行)
client pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error connect disconnect
}
# 仅允许user_socks5用户,且只允许绑定/连接/UDP关联
socks pass {
from: 0.0.0.0/0 to: 0.0.0.0/0
command: bind connect udpassociate
log: error connect disconnect
socksmethod: username
#登录的系统用户名
user: user_socks5
}
# 拒绝其他所有socks请求(若想任意用户可以当前代理,可注释socks block部分)
socks block {
from: 0.0.0.0/0 to: 0.0.0.0/0
log: error
}
|
第四步,创建Dante-serve系统服务
为每个实例写一个 service,实现systemd服务分开管理
4.1)eth0代理服务:/etc/systemd/system/danted-eth0.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | [Unit]
Description=Dante SOCKS5 Proxy Server (eth0)
After=network.target
[Service]
Type=forking
RuntimeDirectory=danted
PIDFile=/var/run/danted/danted-eth0.pid
ExecStart=/usr/sbin/danted -f /etc/danted.d/danted-eth0.conf -p /var/run/danted/danted-eth0.pid -D
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
|
4.2)eth1代理服务:/etc/systemd/system/danted-eth1.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | [Unit]
Description=Dante SOCKS5 Proxy Server (eth1)
After=network.target
[Service]
Type=forking
RuntimeDirectory=danted
PIDFile=/var/run/danted/danted-eth1.pid
ExecStart=/usr/sbin/danted -f /etc/danted.d/danted-eth1.conf -p /var/run/danted/danted-eth1.pid -D
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
|
4.3)启动两个服务
1
2
3
4
5
6
7
8
9
10
11
12 | #重载 systemd 配置
systemctl daemon-reload
#启动eth0
systemctl restart danted-eth0
systemctl status danted-eth0
systemctl enable danted-eth0
#启动eth1
systemctl restart danted-eth1
systemctl status danted-eth1
systemctl enable danted-eth1
|
第五步,测试
注:测试前,请放行代理端口,云服务器放行安全组!!!
命令测试
| curl --socks5 《暴漏服务器地址:端口号》 --proxy-user 《用户名:密码》 http://ifconfig.me
|
若是代理工具,如Proxifier
网页测试地址:https://nstool.netease.com/