WSL2 - Podman Desktop - 从 Windows 中触发的容器访问内部服务 (VPN) 失败(在 WSL 中运行容器有效)

问题描述 投票:0回答:1

在Windows下使用podman时,通过curl访问内部服务失败:

PS C:\Users\<USER>> podman run docker.io/nicolaka/netshoot curl https://<INTERNAL_IP_OR_HOST>:6443/version --insecure
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (35) Recv failure: Connection reset by peer

当直接在 podmans WSL 发行版中触发相同的内部curl 请求时,一切正常:

PS C:\Users\<USER>> wsl -d podman-machine-default

You will be automatically entered into a nested process namespace where
systemd is running. If you need to access the parent namespace, hit ctrl-d
or type exit. This also means to log out you need to exit twice.

[<USER>@<HOSTNAME> ~]$ podman run docker.io/nicolaka/netshoot curl https://<INTERNAL_IP_OR_HOST>:6443/version --insecure
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "Unauthorized",
  "reason": "Unauthorized",
  "code": 401
100   157  100   157    0     0   2474      0 --:--:-- --:--:-- --:--:--  2492

直接从 Windows 下运行的容器进行 ping 工作正常(curl 失败):

PS C:\Users\<USER>> podman run docker.io/nicolaka/netshoot ping <INTERNAL_IP_OR_HOSTNAME>
PING <INTERNAL_IP_OR_HOSTNAME> (<INTERNAL_IP_OR_HOSTNAME>) 56(84) bytes of data.
64 bytes from <INTERNAL_IP_OR_HOSTNAME>: icmp_seq=1 ttl=60 time=12.2 ms

通过 podman 从 Windows 访问其他外部服务工作正常:

PS C:\Users\<USER>> podman run docker.io/nicolaka/netshoot curl https://google.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
100   220  100   220    0     0   1524      0 --:--:-- --:--:-- --:--:--  1527

有人见过类似的行为吗?

环境

  • Podman:4.6.1
  • Podman 桌面版:1.2.1
  • 节点操作系统:Windows 10
  • WSL 版本:2
  • WSL 发行版:启用 root 权限的默认 Podman Desktop 发行版 (podman-machine-default)

适应

添加了我的内部域的 DNS 服务器以启用内部主机名解析

  • /etc/wsl.conf >generateResolvConf=false
  • /etc/resolv.conf > 包含内部 DNS 服务器

因此,可以从 Windows 计算机以及 WSL 内部解析内部主机名。这不是DNS解析问题!

VPN 断开连接后,我可以直接访问内部服务,一切正常。

更新

Windows 中启动容器与 WSL 中启动容器的区别似乎在于数据包是碎片化的。需要在这个方向进一步研究。这是 Wireshark 跟踪:

Wireshark Trace

containers windows-subsystem-for-linux vpn wsl-2 podman
1个回答
0
投票

最终解决方案

问题如编辑部分中所示的 mtu 大小。 Podman 网络支持 MTU 大小的配置:

  • 创建具有调整后的 MTU 大小的新 podman 网络:
podman network create podman-lower-mtu --disable-dns --opt mtu=1300
  • 在 /usr/share/containers/containers.conf 下的 wsl 中将 default_network 设置为 podman-lower-mtu
  • 重新启动 WSL
© www.soinside.com 2019 - 2024. All rights reserved.