当前位置: 首页 > news >正文

Centos7.9安装Dante

1. 背景

公司的专线服务商时不时就换一下公网IP,造成我们频繁更换对外报备的IP白名单,每次走流程很麻烦,所以在IDC内搭建一个Dante服务,进行socks代理。

2. 参考

  1. Dante官网

3. 概念

Dante是一个免费的Socks服务器,实现了RFC 1928及相关标准。这是一款灵活的产品,可用于提供便捷且安全的网络连接

4. 环境

  • 虚拟机 16C/32G/200G
  • 操作系统 Centos 7.9
  • 软件 Dante v1.4.4

5. 部署

5.1 下载

  • 官网下载,当前稳定版本是1.4.4
cd /public/software
wget https://www.inet.no/dante/files/dante-1.4.4.tar.gz

5.2 安装

  1. 解压
cd /public/software
tar -zxvf dante-1.4.4.tar.gz && cd dante-1.4.4
  1. 创建目录
# 配置文件目录
mkdir -p /etc/danted
# 日志文件目录
mkdir -p /var/log/danted/
  1. 创建服务运行账号
useradd -r -s /bin/false xxxkkk
  1. 创建服务使用账号
  • 创建服务使用账号组
groupadd proxy_group
  • 创建服务使用账号
useradd -s /bin/false xuser
  • 把服务使用账号添加到组
usermod -aG proxy_group xuser
  • 查看组内账号
# 查看执行的命令
getent group proxy_group# 输出的结果
proxy_group:x:1003:xuser
  1. 编译
  • 详细编译参数请见 ./configure --help
  • 准备编译环境
sudo yum install pam-devel -y
  • 编译安装,支持pam认证
# 编译命令,支持pam认证方式(本例未使用)./configure --with-pam# 输出结果
......Configure status:Client:            Enabled
Server:            Enabled
Preloading:        Enabled
Libwrap:           Disabled, tcpd.h missing
BSD Auth:          Disabled, usable bsd_auth.h not found
PAM:               Enabled   # 启用状态
GSSAPI:            Enabled
KRB5:              Enabled
SASL:              Not found/disabled
UPNP:              Not found/disabled
Compatability:     issetugid setproctitle strlcpy strvisModules:redirect:          Not found
bandwidth:         Not found
ldap:              Not found
pac:               Not found
  1. 安装
make && make install
# 验证安装包
/usr/local/sbin/sockd -vv | grep build:
# 输出结果,显示已有pam模块
build: gssapi mon-data mon-disconnect pam preload sess2

5.3 配置

  1. 拷贝配置文件
cp /public/software/dante-1.4.4/example/sockd.conf /etc/danted/
ln -s /etc/danted/sockd.conf /etc/
  1. 编辑sockd配置文件
    参考官方文档 https://www.inet.no/dante/doc/1.4.x/sockd.conf.5.html
vim /etc/sockd.conf
# 修改了日志存储路径
# the server will log both via syslog, to stdout and to /var/log/sockd.log
logoutput: syslog stdout /var/log/danted/sockd.log
logoutput: stderr# 修改了监听的IP和端口
# The server will bind to the address 10.1.1.1, port 1080 and will only
# accept connections going to that address.
internal: 0.0.0.0 port = 10800
# Alternatively, the interface name can be used instead of the address.
#internal: eth0 port = 1080# 修改了出口使用的IP,也可以使用网卡
# all outgoing connections from the server will use the IP address
# 195.168.1.1
external: 192.168.15.12# 修改socks策略,使用username。
# methods for socks-rules.
# socksmethod: username none #rfc931
socksmethod:  username# 修改客户端策略
# methods for client-rules.
# clientmethod: none# 定义普通用户允许服务
# when doing something that can require privilege, it will use the
# userid "sockd".
#user.privileged: sockd
user.privileged: root# when running as usual, it will use the unprivileged userid of "sockd".
#user.unprivileged: sockd
user.unprivileged: xxxkkk# 修改允许连接的IP
# This is identical to above, but allows clients without a rfc931 (ident)
# too.  In practice this means the socks server will try to get a rfc931
# reply first (the above rule), if that fails, it tries this rule.
client  pass {from: 10.10.20.0/24 port 1-65535 to: 0.0.0.0/0log: error connect disconnect
}# drop everyone else as soon as we can and log the connect, they are not
# on our net and have no business connecting to us.  This is the default
# but if you give the rule yourself, you can specify details.
client block {from: 0.0.0.0/0 to: 0.0.0.0/0log: connect error
}# 修改允许socks连接的IP
# everyone from our internal network, 10.0.0.0/8 is allowed to use
# tcp and udp for everything else.
socks pass {from: 10.10.20.0/24 to: 0.0.0.0/0protocol: tcp udplog: error connect disconnectsocksmethod: username# 只有proxy_group组内账号可以连接group: proxy_group# user 关键字含义类似group
}# last line, block everyone else.  This is the default but if you provide
# one  yourself you can specify your own logging/actions
socks block {from: 0.0.0.0/0 to: 0.0.0.0/0log: connect error
}

5.4 测试

  • 服务帮助命令详见 /usr/local/sbin/sockd --help
  1. 启动服务
/usr/local/sbin/sockd -f /etc/sockd.conf
  1. 查看服务
# 查看服务端口命令
netstat -nltp | grep sockd
# 命令输出结果
tcp        0      0 0.0.0.0:10800           0.0.0.0:*               LISTEN      25885/sockd   

5.5 管理

  1. 创建danted.service文件
vim /etc/systemd/system/danted.service 
[Unit]
Description=SOCKS (v4 and v5) proxy daemon (danted)
Documentation=man:danted(8) man:danted.conf(5)
After=network.target[Service]
Type=simple
PIDFile=/run/danted.pid
Environment="OPTIONS=-f /etc/sockd.conf"
EnvironmentFile=-/etc/danted/danted.conf
ExecStart=/usr/local/sbin/sockd $OPTIONS
Restart=always
#Restart=on-failure
RuntimeDirectory=danted[Install]
WantedBy=multi-user.target
  1. 加入systemd管理
  • 加载配置文件
systemctl daemon-reload
  • 设置开机自启动,并启动服务
systemctl enable danted && systemctl start danted 
  • 查看服务执行状态命令
systemctl status danted
  • 命令输出结果
● danted.service - SOCKS (v4 and v5) proxy daemon (danted)Loaded: loaded (/etc/systemd/system/danted.service; enabled; vendor preset: disabled)Active: active (running) since 六 2025-08-16 15:54:31 CST; 9min agoDocs: man:danted(8)man:danted.conf(5)Main PID: 32481 (sockd)CGroup: /system.slice/danted.service├─32481 /usr/local/sbin/sockd -f /etc/sockd.conf├─32482 sockd: monitor-child├─32483 sockd: negotiate-child: 0/96├─32484 sockd: request-child: 0/1├─32485 sockd: request-child: 0/1├─32486 sockd: request-child: 0/1├─32487 sockd: request-child: 0/1├─32488 sockd: request-child: 0/1├─32489 sockd: request-child: 0/1├─32490 sockd: request-child: 0/1├─32491 sockd: request-child: 0/1├─32492 sockd: request-child: 0/1├─32493 sockd: request-child: 0/1├─32494 sockd: request-child: 0/1├─32495 sockd: request-child: 0/1├─32496 sockd: request-child: 0/1├─32497 sockd: request-child: 0/1├─32498 sockd: request-child: 0/1├─32499 sockd: request-child: 0/1└─32500 sockd: io-child: 0/32 (0 in progress)

5.6 日志

  1. 增加logrotate配置
vim /etc/logrotate.d/dantedlog
/var/log/danted/*.log
{dailyrotate 10compressdelaycompressmissingoknotifemptypostrotate/bin/kill -HUP `cat /var/run/sockd.pid 2> /dev/null` 2> /dev/null || trueendscript
}
  1. 测试日志轮转
logrotate -f /etc/logrotate.conf
  1. 查看日志轮转
    在这里插入图片描述

6. 使用

6.1 客户端

  • danted开启了验证,所以需要使用代理客户端程序进行socks连接。

  • Windos系统自带“代理”仅支持socks v4(配置见下图),不支持socks v5的鉴权功能(本例开启了鉴权),而且仅能代理http、https、ftp。如果只代理http和https请考虑squid软件。

    • Windos客户端连接(仅供参考,不适用本例)
      注意:使用socks代理的写法,socks=192.168.15.12
      在这里插入图片描述
  1. 代理客户端软件
    本例使用Netch软件说明(https://github.com/netchx/netch),版本v1.9.7

  2. 配置Netch

  • 配置socks服务器
    在这里插入图片描述

  • 配置信息

    • 地址 dante服务器IP和端口
    • 用户名 账号(xuser已创建,且已添加至proxy_group组中)
    • 密码 账号设置的密码
    • 版本 5(socks v5)
      在这里插入图片描述
  • 模式

    • 选择Bypass LAN(绕过局域网)
      在这里插入图片描述

6.2 测试

1. 测试授权账号(xuser)

  • 启动Netch
    在这里插入图片描述

  • 查看出口IP
    出口IP已变更为代理出口IP(本例中192.168.15.12的互联网出口IP如下)
    在这里插入图片描述

  • 测试TCP代理
    客户端使用tcping 测试 114.114.114.114 的53端口
    在这里插入图片描述

  • 查看dante服务端日志显示TCP代理连接
    在这里插入图片描述

2. 测试非授权账号(xxxkkk)
本例中xxxkkk是dante服务器系统账号,但不是proxy_group组内授权账号。

  • 配置使用xxxkkk账号
    在这里插入图片描述

  • 启用Netch
    在这里插入图片描述

  • 查看dante服务端日志显示拒绝代理连接
    在这里插入图片描述

http://www.xdnf.cn/news/1313353.html

相关文章:

  • 深度解析Java synchronized关键字及其底层实现原理
  • python---包
  • 《WINDOWS 环境下32位汇编语言程序设计》第2章 准备编程环境
  • 深入剖析 TOTP 算法:基于时间的一次性密码生成机制
  • IOMMU多级页表查找的验证
  • 【计算机网络架构】混合型架构简介
  • 39.离散化与哈希
  • 模型训练监控:TensorBoard与Weights Biases (WB) 使用详解
  • 《A Practical Guide to Building Agents》文档学习
  • 写一个linux脚本,要求实现查找9010端口,如果端口存在则kill,否则不处理,返回对应的提示
  • 24. async await 原理是什么,会编译成什么
  • Linux系统top命令详细指南
  • 安卓11 12系统修改定制化_____如何去除安卓11 12的系统签名验证
  • 基于Transformer的机器翻译——模型篇
  • 《后室Backrooms》中文版,购物误入异空间,怪物追逐,第一人称冒险逃生
  • 安卓11 12系统修改定制化_____修改系统 解锁system分区 去除data加密 自由删减系统应用
  • 服务器配置开机自启动服务
  • 线程池与异步编程——语法归纳
  • 存算分离与云原生:数据平台的新基石
  • 机器学习的特征工程(特征构造、特征选择、特征转换和特征提取)详解
  • 探秘gRPC——gRPC原理详解
  • 胶质母细胞瘤对化疗的敏感性由磷脂酰肌醇3-激酶β选择性调控
  • 【CV 目标检测】Fast RCNN模型①——与R-CNN区别
  • 软件需求管理过程详解
  • 11、软件需求工程
  • 基于 LoRA的广义知识蒸馏(GKD)训练
  • Java基础 8.16
  • 一汽红旗7月销量37324辆 同比增长21.1%
  • ESP32 C3 开发板使用教程 01-测试显示屏
  • k8sday08深入控制器(3/3)