Ubuntu 配置 SOCKS5

一、安装

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

posted @ 2020-10-13 15:54  Anonymous_1  阅读(4758)  评论(2编辑  收藏  举报