编译: GOOS=linux GOARCH=amd64 go build -ldflags="-s -w"
在中心节点启用 IP 转发: sudo nano /etc/sysctl.conf net.ipv4.ip_forward=1 sudo sysctl -p cat /proc/sys/net/ipv4/ip_forward
使用 tcpdump 监控 tun0 接口上的流量: tcpdump -i tun0 -n
测试
- 测试 ICMP:边缘节点互相ping,ping 10.0.0.1
- 测试 TCP:节点A nc -l 8080,节点B nc 10.0.0.1 8080,然后互相发送报文
- 测试 UDP:节点A nc -u -l 8080,节点B nc -u 10.0.0.1 8080
- 检查数据包路径:traceroute 10.0.0.2
- 确定防火墙放行了 5555 端口
- 确定 IPv4 转发已经打开
- 配置 iptables
# 查看 iptables 规则
sudo iptables -L -n -v
# 或者
sudo iptables -t nat -L -v -n
# 【试了一下不需要!】启用源地址转换(SNAT)
iptables -t nat -A POSTROUTING -o eth0 -s 10.0.0.0/24 -j MASQUERADE
# 允许 tun 设备流量
iptables -A FORWARD -i tun0 -j ACCEPT
iptables -A FORWARD -o tun0 -j ACCEPT
这样配置完 iptables 并不是持久化的,重启就没了。
其实是中心节点告诉边缘节点有更优路径可以选择,如果觉得烦可以在中心节点机器上关闭 ICMP 转发:
临时设置
sysctl -w net.ipv4.conf.all.send_redirects=0
sysctl -w net.ipv4.conf.default.send_redirects=0
永久设置,编辑 /etc/sysctl.conf
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
然后 sysctl -p
不需要,使用 TCP 组件 VPN 会有 TCP over TCP 的问题,重传机制和拥塞避免的开销都会 double,内层 TCP 还会收到外层 TCP 队头阻塞的影响。 可以用 QUIC,没理由用 TCP。