一台 macOS
电脑,在移动宽带家用宽带内网中,路由器下发的 IP: 192.168.1.207
一台 Ubuntu
云主机,是腾讯云轻量服务器,内网 IP: 10.0.24.5
,公网 IP: 20.111.10.10
在两台设备上配置了 WireGuard
,其中
Ubuntu
的 WireGuard IP: 10.66.66.1
,监听端口 61000
AllowedIPs: 10.66.66.2/32, 192.168.1.1/24
macOS
的 WireGuard IP: 10.66.66.2
,AllowedIPs: 0.0.0.0/0, ::/0
EndPoint: 20.111.10.10:61000
在 WireGuard
的每个 Peer
可以访问到各自的局域网内的服务
我在两个设备上 80
端口分别部署了 web
服务。同时 Home Router
的 80
也有 web
服务。
macOS
无法 ping
通 Ubuntu
,但是反过来可以。
Ubuntu
无法访问 macOS
上的 web
服务,但是反过来可以。
macOS ping Ubuntu WireGuard IP
myname@mac ~> ping 10.66.66.1
PING 10.66.66.1 (10.66.66.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^C
--- 10.66.66.1 ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss
myname@mac ~> sudo tcpdump host 10.66.66.1 -nn
tcpdump: data link type PKTAP
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on pktap, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes
09:08:45.842669 IP 198.18.0.1 > 10.66.66.1: ICMP echo request, id 3660, seq 0, length 64
09:08:45.842826 IP 192.168.1.207 > 10.66.66.1: ICMP echo request, id 30738, seq 0, length 64
09:08:46.845281 IP 198.18.0.1 > 10.66.66.1: ICMP echo request, id 3660, seq 1, length 64
09:08:46.845528 IP 192.168.1.207 > 10.66.66.1: ICMP echo request, id 30738, seq 1, length 64
09:08:47.849243 IP 198.18.0.1 > 10.66.66.1: ICMP echo request, id 3660, seq 2, length 64
09:08:47.849486 IP 192.168.1.207 > 10.66.66.1: ICMP echo request, id 30738, seq 2, length 64
^C
6 packets captured
28 packets received by filter
0 packets dropped by kernel
macOS ping Ubuntu LAN IP
myname@mac ~ [2]> ping 10.0.24.5
PING 10.0.24.5 (10.0.24.5): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^C
--- 10.0.24.5 ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss
myname@mac ~> sudo tcpdump host 10.0.24.5 -nn
tcpdump: data link type PKTAP
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on pktap, link-type PKTAP (Apple DLT_PKTAP), capture size 262144 bytes
09:10:32.262418 IP 198.18.0.1 > 10.0.24.5: ICMP echo request, id 29772, seq 0, length 64
09:10:32.262692 IP 192.168.1.207 > 10.0.24.5: ICMP echo request, id 57874, seq 0, length 64
09:10:33.264108 IP 198.18.0.1 > 10.0.24.5: ICMP echo request, id 29772, seq 1, length 64
09:10:33.264379 IP 192.168.1.207 > 10.0.24.5: ICMP echo request, id 57874, seq 1, length 64
09:10:34.265250 IP 198.18.0.1 > 10.0.24.5: ICMP echo request, id 29772, seq 2, length 64
09:10:34.265511 IP 192.168.1.207 > 10.0.24.5: ICMP echo request, id 57874, seq 2, length 64
^C
6 packets captured
44 packets received by filter
0 packets dropped by kernel
Ubuntu ping macOS LAN IP
myname@rus ~> ping 192.168.1.207
PING 192.168.1.207 (192.168.1.207) 56(84) bytes of data.
^C
--- 192.168.1.207 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4096ms
myname@rus ~> sudo tcpdump -i wg0 -nn
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wg0, link-type RAW (Raw IP), capture size 262144 bytes
09:14:47.520387 IP 10.66.66.1 > 192.168.1.207: ICMP echo request, id 16, seq 1, length 64
09:14:48.544447 IP 10.66.66.1 > 192.168.1.207: ICMP echo request, id 16, seq 2, length 64
09:14:49.568440 IP 10.66.66.1 > 192.168.1.207: ICMP echo request, id 16, seq 3, length 64
09:14:50.592437 IP 10.66.66.1 > 192.168.1.207: ICMP echo request, id 16, seq 4, length 64
09:14:51.616445 IP 10.66.66.1 > 192.168.1.207: ICMP echo request, id 16, seq 5, length 64
^C
5 packets captured
5 packets received by filter
0 packets dropped by kernel
Ubuntu curl macOS
任何地址都没响应,而且没有终端输出,tcpdump
也没有输出。请大家指点。
感谢大家的帮助。经过排查可能的原因是 macOS
使用的 WG
客户端软件的限制——使用官方的 WG
客户端其他条件不变的情况下是符合预期的。
1
neighbads 2022-12-01 09:33:57 +08:00 1
直接贴配置文件内容吧
|
2
extiing OP @neighbads
Ubuntu 配置 --- [Interface] Address = 10.66.66.1/24,fd42:42:42::1/64 ListenPort = 61000 PrivateKey = xxx PostUp = iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i eth0 -o wg0 -j ACCEPT; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer] PublicKey = xxx PresharedKey =xxx AllowedIPs = 10.66.66.2/32,fd42:42:42::2/128,192.168.1.1/24 --- macOS 配置 --- [Interface] Address = 10.66.66.2/32, fd42:42:42::2/128 PrivateKey = xxx DNS = 94.140.14.14, 94.140.15.15 MTU = 1280 [Peer] PublicKey = xxx AllowedIPs = "0.0.0.0/0, ::/0" Endpoint = 20.111.10.10:61000 PresharedKey = xxx PersistentKeepalive = 15 --- |
3
vmebeh 2022-12-01 09:53:47 +08:00
|
4
Huelse 2022-12-01 10:05:09 +08:00
wg 的 AllowedIPs 就是配置路由表,你要确保 ip 要从那个网卡走
像 Ubuntu 下的 mac.peer 应该是`AllowedIPs = 10.66.66.0/24, 192.168.1.0/24`,就意味着可以 192.168.1.1 之类的目标 ip 可以从这个 peer 走 对应 macos 配置的 peer 只需要`AllowedIPs = 10.66.66.0/24`,就可以访问 10.66.66.1 等 |
5
extiing OP @Huelse 感谢解答。从上面配置文件可以看到,Ubuntu 的 Peer AllowedIPs 是 10.66.66.0/24, 192.168.1.0/24 ,mac 的 Peer AlllowedIPs 是 0.0.0.0/0 ,::/0 ——满足访问条件的呀。现在清楚了为什么从 mac ping Ubuntu 是不通的,由于我的 mac 上一个服务会劫持 icmp 。但是从 Ubuntu 无法访问 192.168.1.207 这个 mac 的局域网 IP 的问题依然没解决。
|
6
me221 2022-12-01 10:30:49 +08:00
macos 开启转发了吗? 类似: `sysctl -w net.ipv4.ip_forward=1`
|
7
extiing OP @vmebeh 感谢解答。尝试了,但是没有好转。另,这个 PostUp 和 PostDown 是 这个项目自动配置的 https://github.com/angristan/wireguard-install 。
|
8
extiing OP |
9
me221 2022-12-01 10:51:22 +08:00
试试把 Ubuntu AllowedIPs = 10.66.66.2/32, fd42:42:42::2/128, 192.168.1.0/32
|
10
vmebeh 2022-12-01 11:05:34 +08:00
mac 上的 http 服务可以通过 10.66.66.2 访问吗
|
14
vmebeh 2022-12-01 12:24:47 +08:00 via iPhone
噢,192.168.1.207 也不行,也许是被 mac 防火墙阻挡了?
192.168.1.x 的其他机器可以访问其 http 服务吗 |
15
extiing OP @vmebeh 在 mac 上是可以访问 192.168.1.207 以及 192.168.1.0/24 网络中的所有开放服务的,但是不可以从 mac 的 WireGuard IP 访问 mac 本机的开放服务。目前仍不清楚原因,猜测可能是 Surge 的限制。
|
17
deepzz 2022-12-01 13:36:10 +08:00
macOS 不要路由所有流量,这个要特殊设置才行。
AllowedIPs: 10.66.66.0/24 https://deepzz.com/post/openwrt-and-wireguard-connect-homenet-anywhere.html |
19
Huelse 2022-12-22 22:43:16 +08:00 1
@extiing 不知道 op 解决问题了没有,这两天帮朋友配置 zerotier 的时候遇到了类似的问题,最终是通过 pf 转发实现的外部设备访问 mac 本地网络,你可以参考下
除了常规的关闭防火墙,ip.forwarding ,路由等设置外再开启 pf 转发,网络名称自行替换 "nat on en1 from feth3632:network to any -> (en1)" > /etc/pfzerotier.conf sudo pfctl -d sudo pfctl -e -f /etc/pfzerotier.conf pf enabled 就可以访问了 |