Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

编译: 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

测试

  1. 测试 ICMP:边缘节点互相ping,ping 10.0.0.1
  2. 测试 TCP:节点A nc -l 8080,节点B nc 10.0.0.1 8080,然后互相发送报文
  3. 测试 UDP:节点A nc -u -l 8080,节点B nc -u 10.0.0.1 8080
  4. 检查数据包路径:traceroute 10.0.0.2

Issues

腾讯云轻量服务器作为中心节点时不可用

  1. 确定防火墙放行了 5555 端口
  2. 确定 IPv4 转发已经打开
  3. 配置 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 并不是持久化的,重启就没了。

为什么 ping 老是发生重定向

其实是中心节点告诉边缘节点有更优路径可以选择,如果觉得烦可以在中心节点机器上关闭 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 和 UDP

不需要,使用 TCP 组件 VPN 会有 TCP over TCP 的问题,重传机制和拥塞避免的开销都会 double,内层 TCP 还会收到外层 TCP 队头阻塞的影响。 可以用 QUIC,没理由用 TCP。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages