Debian 下配置 Socks5 代理服务端软件 dante

Socks5 代理在网络访问中具有较高的实用性和安全性,本文将详细介绍在 Debian 系统中使用 dante 软件配置 Socks5 代理服务端的方法。

dante

一、安装 dante 服务端

首先更新系统软件包索引并升级已安装的软件:

apt update
apt upgrade

接着安装 dante-server 软件包:

apt install dante-server

二、配置 dante 服务

1. 备份并创建新配置文件

为避免配置错误导致服务不可用,先备份原配置文件:

cp /etc/danted.conf /etc/danted.conf_orig
rm /etc/danted.conf

使用 nano 编辑器创建新的配置文件:

nano /etc/danted.conf

2. 配置文件内容

在打开的文件中输入以下内容,注意将eth0替换为服务器的实际网卡名称:

logoutput: syslog
user.privileged: root
user.unprivileged: nobody

# 监听的网络接口和端口
internal: 0.0.0.0 port=1080

# 代理的网络接口或地址
external: eth0

# 代理认证方式
socksmethod: username

# 客户端连接规则
clientmethod: none

client pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
}

socks pass {
    from: 0.0.0.0/0 to: 0.0.0.0/0
}

3. 添加认证用户

为代理服务创建专用用户并设置密码:

useradd -r -s /bin/false proxy_user
passwd proxy_user

4. 限制特定 IP 访问(可选)

如果需要只允许特定 IP 连接代理,可修改配置文件中的 client pass 规则,将xxx.111.xxx.222替换为允许连接的 IP 地址:

client pass {
    from: xxx.111.xxx.222/0 to: 0.0.0.0/0
}

三、配置防火墙规则

1. 使用 iptables

允许 TCP 协议的 1080 端口进出流量:

iptables -I INPUT -p tcp --dport 1080 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 1080 -j ACCEPT

# 保存规则
service iptables save

2. 使用 ufw

ufw allow 1080

四、重启并验证服务

1. 重启 dante 服务

systemctl restart danted.service

2. 查看服务状态

systemctl status danted.service

正常情况下会显示服务处于活跃运行状态:

● danted.service - SOCKS (v4 and v5) proxy daemon (danted)
     Loaded: loaded (/lib/systemd/system/danted.service; enabled; preset: enabled)
     Active: active (running)

五、客户端连接测试

1. 使用 curl 测试

curl -v -x socks5://proxy_user:password@xxx.123.xxx.123:1080 http://google.com

若连接成功,会显示类似以下内容:

* Trying xxx.123.xxx.123:1080...
* Connected to xxx.123.xxx.123 (xxx.123.xxx.123) port 1080 (#0)
* SOCKS5 connect to IPv4 64.233.165.106:80 (locally resolved)
* SOCKS5 request granted.

2. 浏览器配置

以 Firefox 为例,进入 “选项”->”网络设置”,选择 “手动配置代理”,在 “SOCKS 主机” 中填入服务器 IP,端口填 1080,选择 “SOCKS5” 协议,勾选 “对所有协议使用相同代理”。

通过以上步骤,即可在 Debian 系统上成功配置 dante Socks5 代理服务端。在实际使用中,可根据需求进一步调整访问规则和安全设置。

发表评论

zh_CNChinese