部署完openvpn之后一个小时重新认证一次

现象

终端连接openvpn之后,时间久了连接会自动断开,还需要手动重新连一遍。

原因分析

1、查看认证日志记录,发现刚好每隔一个小时整会重新认证一次,认证次数多的话后面就会认证失败。怀疑是配置文件中,有类似于定时认证的相关配置,查看配置文件,没有找到类似配置。

local x.x.x.x

port xxxx

proto udp

dev tun

ca ca.crt

cert server.crt

key server.key

dh dh.pem

auth SHA512

tls-crypt tc.key

topology subnet

server 10.8.0.0 255.255.255.0

push "redirect-gateway def1 bypass-dhcp"

ifconfig-pool-persist ipp.txt

push "dhcp-option DNS 114.114.114.114

push "dhcp-option DNS 8.8.8.8"

keepalive 10 120

cipher AES-256-CBC

user nobody

group nobody

persist-key

persist-tun

status openvpn-status.log

verb 3

crl-verify crl.pem

explicit-exit-notify

plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf

client-cert-not-required

username-as-common-name

2、查看openvpn官网文档,发现有一个默认开启的参数reneg-sec,详细解释如下:

–reneg-sec n

Renegotiate data channel key after nseconds (default=3600).When using dual-factor authentication, note that this default value may cause the end user to be challenged to reauthorize once per hour.

Also, keep in mind that this option can be used on both the client and server, and whichever uses the lower value will be the one to trigger the renegotiation. A common mistake is to set –reneg-secto a higher value on either the client or server, while the other side of the connection is still using the default value of 3600 seconds, meaning that the renegotiation will still occur once per 3600 seconds. The solution is to increase –reneg-sec on both the client and server, or set it to 0 on one side of the connection (to disable), and to your chosen value on the other side.

该参数默认值是3600秒,也就是默认1个小时openvpn就会重新协商一下数据通道key,正常VPN不会断开,不会影响VPN用户的使用,但是因为我的VPN使用了双因素认证,令牌是有时效的,所以刚开始还能重认证通过,后面超过一定次数,令牌过期后就不行了,就会导致VPN断开,需要重连才行。

解决方法

在openvpn服务端或者客户端任意一端配置文件中配置reneg-sec 0即可。


部署完openvpn之后一个小时重新认证一次
http://localhost:8090/archives/V7lX0IPF
作者
好瞌睡啊
发布于
2021年04月23日
许可协议