2

Openvpn服务器端无法开通udp端口的故障排除

 4 months ago
source link: https://bajie.dev/posts/20240108-opnevpn_udp_port/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Openvpn服务器端无法开通udp端口的故障排除

2024-01-08 2 分钟阅读
openvpn server can’t use udp port

这个问题非常古怪,我们有两个机房。分别在两边假设了openvpn服务器,一个机房的ovpn就完全正常,而另一个机房的openvpn如果是tcp就没问题,如果是udp就报错,无法连接。把正常机房的openvpn完全复制一份拿过去,也是一样报错,太郁闷了!

错误提示是:

TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)  

非常古怪啊: 在内网用nc来试验udp是否正常:

nc -ul 1194  

在内网随便找一台机器测试:

nc -u xxxx 1194  

然后两边随便输入字符测试,没问题。

然后从公网测试,就出问题了。nc连接上以后,只能发送一次数据,然后管道就断裂了,无法再传数据。

nc -u 公网ip 1194  
aaa  
nc: Write error: Connection refused  

百思不得其解啊,试了若干次,才发现问题的症结所在。

错误的那台服务器,有两个网络地址: 172.16.8.4和172.16.8.1 其中8.4的地址是缺省地址,8.1的地址是用ifconfig手动后添加的。 而前端防火墙做得公网映射是映射到了8.1的1194端口

tcp由于双方是要校验来往src地址的,所以没问题,到了udp,只管发不管收,所以udp包就从8.4的缺省地址发出去,导致双方不一致,无法正常接收了。

解决方法也很简单,在openvpn服务器端的配置文件中强行指定local端的ip即可:

local 172.16.8.1  

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK