在某些复杂的网络环境下,仅使用简单的配置可能会遇到 No route to host
的问题。
具体表现是使用 traceroute
命令无法访问到目标 IP(10.1.1.5
是另一台 Wireguard Peer 设备的地址)。
$ traceroute 10.1.1.5
traceroute to 10.1.1.5 (10.1.1.5), 30 hops max, 60 byte packets
1 Workstation (192.168.1.2) 3061.720 ms !H 3061.660 ms !H 3061.644 ms !H
解决方法是在 Wireguard 配置文件中添加 Table
选项。
[Interface]
PrivateKey = cJOQ7OfmkIoLS3BzmE+kNhJ950TZXsIkROiEi8kjPoK=
Address = 10.1.1.2/32
MTU = 1280
Table = 200
PostUp = /sbin/ip rule add to 10.1.1.0/24 table 200 priority 101
PostDown = /sbin/ip rule del to 10.1.1.0/24 table 200 priority 101