stun服务器作为NAT穿透的一环还很重要,之前一直用的小米的stun服务器,想着能不能自己搭建,研究了一下发现非常容易。

docker-compose

使用docker部署,docker-compose为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: '3'

services:
coturn:
image: instrumentisto/coturn
container_name: stun-server
ports:
- "3478:3478/udp"
command:
- --no-auth # 无身份验证,方便测试
- --no-tls
- --no-dtls
- --listening-port=3478
- --listening-ip=0.0.0.0
- --no-multicast-peers
- --no-cli
- --realm=【换成你的stun域名例如stun.miwifi.com】
- --fingerprint
restart: unless-stopped

realm可以改成你的stun域名即可。

解析

添加解析的时候直接添加stun的A解析到你的服务器ip即可。

防火墙

别忘了开3478的UDP端口,云服务商和主机的防火墙都要开。

检测命令

换成你的域名

1
stunclient stun.miwifi.com 3478

检测

目前国内能够连上的stun服务器

stun.miwifi.com 3478

stun.hitv.com 3478