podman icon indicating copy to clipboard operation
podman copied to clipboard

"Connection refused" using rootful podman and trying to access the host via `host.containers.internal`

Open jankap opened this issue 1 year ago • 6 comments

Issue Description

I spawn a service (Segger J-Link Remote Server) listening on port 19020 on my host, which is a Windows 11 (24H2) machine.

That service should be accessible by podman containers. For rootless containers, there seem to be multiple ways, e.g. using pasta, or host.docker.internal, see https://github.com/eriksjolund/podman-networking-docs?tab=readme-ov-file#outbound-tcpudp-connections-to-the-hosts-localhost. But how does this work for rootful containers? https://github.com/containers/podman/blob/main/docs/tutorials/basic_networking.md does not tell me or I don't understand.

As far as I understand, the default network for rootful containers uses a bridged network, so there must be a route created somewhere in the NAT. Is that implemented or not yet?

Steps to reproduce the issue

  1. spin up a service listening on a port on the host, e.g. & "C:\Program Files\SEGGER\JLink_V882\JLinkRemoteServer.exe" which listens on 19020
  2. spin up podman container:
podman run -it --rm busybox telnet localhost 19020
telnet: can't connect to remote host (127.0.0.1): Connection refused
  1. same for "magic url":
podman run -it --rm busybox telnet host.containers.internal 19020
telnet: can't connect to remote host (10.88.0.1): Connection refused
  1. using host network works, but causes other issues - I need to use the bridged version
podman run -it --rm --network=host busybox telnet localhost 19020
Connected to localhost
)�CSEGGER J-Link Remote Server V8.82 compiled 11:49:35 on Oct 29 2025
  1. magic url does not work with host network either (guess that makes sense):
podman run -it --rm --network=host busybox telnet host.containers.internal 19020
telnet: can't connect to remote host (10.255.255.254): Connection refused

Describe the results you received

Connection refused.

Describe the results you expected

An established connection to the Segger service, e.g., )�CSEGGER J-Link Remote Server V8.82 compiled 11:49:35 on Oct 29 2025 response

podman info output

Client:
  APIVersion: 5.6.2
  Built: 1759261014
  BuiltTime: Tue Sep 30 21:36:54 2025
  GitCommit: 9dd5e1ed33830612bc200d7a13db00af6ab865a4
  GoVersion: go1.25.1
  Os: windows
  OsArch: windows/amd64
  Version: 5.6.2
host:
  arch: amd64
  buildahVersion: 1.41.5
  cgroupControllers:
  - cpuset
  - cpu
  - io
  - memory
  - hugetlb
  - pids
  - rdma
  cgroupManager: cgroupfs
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.13-1.fc41.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.13, commit: '
  cpuUtilization:
    idlePercent: 98.21
    systemPercent: 0.51
    userPercent: 1.29
  cpus: 28
  databaseBackend: sqlite
  distribution:
    distribution: fedora
    variant: container
    version: "41"
  eventLogger: journald
  freeLocks: 2013
  hostname: DES53ENGC9GQB54
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 6.6.87.2-microsoft-standard-WSL2
  linkmode: dynamic
  logDriver: journald
  memFree: 26895618048
  memTotal: 33652060160
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: aardvark-dns-1.16.0-1.fc41.x86_64
      path: /usr/libexec/podman/aardvark-dns
      version: aardvark-dns 1.16.0
    package: netavark-1.16.1-1.fc41.x86_64
    path: /usr/libexec/podman/netavark
    version: netavark 1.16.1
  ociRuntime:
    name: crun
    package: crun-1.24-1.fc41.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.24
      commit: 54693209039e5e04cbe3c8b1cd5fe2301219f0a1
      rundir: /run/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
  os: linux
  pasta:
    executable: /usr/bin/pasta
    package: passt-0^20250919.g623dbf6-1.fc41.x86_64
    version: |
      pasta 0^20250919.g623dbf6-1.fc41.x86_64
      Copyright Red Hat
      GNU General Public License, version 2 or later
        <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
  remoteSocket:
    exists: true
    path: unix:///run/podman/podman.sock
  rootlessNetworkCmd: pasta
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: true
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 8589934592
  swapTotal: 8589934592
  uptime: 4h 0m 26.00s (Approximately 0.17 days)
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - docker.io
store:
  configFile: /usr/share/containers/storage.conf
  containerStore:
    number: 13
    paused: 0
    running: 2
    stopped: 11
  graphDriverName: overlay
  graphOptions:
    overlay.additionalImageStores:
    - /usr/lib/containers/storage
    overlay.imagestore: /usr/lib/containers/storage
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphRootAllocated: 1081101176832
  graphRootUsed: 439781429248
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Supports shifting: "true"
    Supports volatile: "true"
    Using metacopy: "true"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 250
  runRoot: /run/containers/storage
  transientStore: false
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 5.6.2
  BuildOrigin: Fedora Project
  Built: 1759190400
  BuiltTime: Tue Sep 30 02:00:00 2025
  GitCommit: 9dd5e1ed33830612bc200d7a13db00af6ab865a4
  GoVersion: go1.24.7
  Os: linux
  OsArch: linux/amd64
  Version: 5.6.2

Podman in a container

No

Privileged Or Rootless

Privileged

Upstream Latest Release

Yes

Additional environment details

I installed podman via Podman Desktop, but I believe this is an underlying podman issue, not a Podman Desktop issue, correct?

There are in- and outbound firewall rules in place on the host that allow port 19020 connections.

Additional information

Thanks for any input.

jankap avatar Nov 10 '25 11:11 jankap

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Dec 11 '25 00:12 github-actions[bot]

Am I the only one with this request? 😁

I'd love to access services on the host without having to use --network=host.

Is that possible or not at the moment?

jankap avatar Dec 12 '25 12:12 jankap

localhost in container is a different host (in a different namespace) than localhost on host (unless you specify --network=host) - it shouldn't work, that's not a bug, it's a feature

host.containers.internal resolves to address that is owned by the host. It works as expected on linux machine:

❯ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.88.0.9 - - [21/Feb/2026 20:37:51] "GET / HTTP/1.1" 200 -
❯ podman run --rm -it alpine wget host.containers.internal:8000
Connecting to host.containers.internal:8000 (10.88.0.1:8000)
saving to 'index.html'
index.html           100% |******************************************************************************************************|  1060  0:00:00 ETA
'index.html' saved

Podman doesn't work on Windows natively, it uses WSL2, which is a kind of Linux VM. I guess that's where the issue is. host.containers.internal point to address owned by the Linux VM host. Linux doesn't run any service on port 19020 and is not aware that Windows does, so it responds with "Connection refused".

You will need to use address of the Windows host (I have no experience with WSL so I will be guessing):

  • host.wsl.internal
  • IP of adapter called "vEthernet (WSL)"
  • https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip
  • any address of windows network interface (non overlapping with Linux)

or try to play with that fishy feature... thou, connection working with --network=host makes me suspect that you've already did:

  • https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking

dbie0 avatar Feb 21 '26 20:02 dbie0

localhost in container is a different host (in a different namespace) than localhost on host (unless you specify --network=host) - it shouldn't work, that's not a bug, it's a feature

I see that, which is why I wanted to use host.containers.internal. It's much clearer than using localhost, but as I wrote in my first post, it does not work.

host.containers.internal resolves to address that is owned by the host. It works as expected on linux machine:

Okay, but it does not on Windows.

Podman doesn't work on Windows natively, it uses WSL2, which is a kind of Linux VM. I guess that's where the issue is. host.containers.internal point to address owned by the Linux VM host. Linux doesn't run any service on port 19020 and is not aware that Windows does, so it responds with "Connection refused".

Quite likely, yes.

You will need to use address of the Windows host (I have no experience with WSL so I will be guessing):

  • host.wsl.internal
podman run -it --rm busybox telnet host.wsl.internal 19020
telnet: bad address 'host.wsl.internal'
  • IP of adapter called "vEthernet (WSL)"

I think that one does not exist anymore when using mirrored mode.

  • https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip
# in WSL:
ip route show | grep -i default | awk '{ print $3}'
10.126.64.1

# in container
/ # telnet 10.126.64.1 19020
# timeout

Note this does not even work from inside WSL (also timeout), but connecting to localhost works (due to mirroring mode)

  • any address of windows network interface (non overlapping with Linux)
/ # telnet 192.168.178.38 19020
telnet: can't connect to remote host (192.168.178.38): Connection refused
/ # ping 192.168.178.38
PING 192.168.178.38 (192.168.178.38): 56 data bytes
64 bytes from 192.168.178.38: seq=0 ttl=64 time=0.069 ms
64 bytes from 192.168.178.38: seq=1 ttl=64 time=0.164 ms
^C
--- 192.168.178.38 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.069/0.116/0.164 ms

or try to play with that fishy feature... thou, connection working with --network=host makes me suspect that you've already did:

  • https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking

Why fishy? But yes, I'm using mirrored mode networking which solves issues with DNS and proxies in my environment. I think it's made for my use-case, because the docs say

Connect to Windows servers from within Linux using the localhost address 127.0.0.1. IPv6 localhost address ::1 is not supported

And this is what I'm trying to do. If host.containers.internal resolves in the WSL host IP, I thought, accessing the Windows IP/Service would work, too due to mirror mode.

But apparently it does not, maybe another route or something is required.

Looks like currently, --network=host is the only solution on Windows :(

jankapte avatar Feb 27 '26 13:02 jankapte

I've done some testing and experiments I've set up Podman Desktop with WSL2 Backend, on Windows I used python3 http server listening on port 0.0.0.0:8000

1.Mirroring disabled

  • Windows interfaces:
    • Ethernet 10.0.100.30 (LAN)
    • vEthernet 172.30.208.1
  • WSL Linux interfaces:
    • lo 127.0.0.1, 10.255.255.254
    • eth0 172.30.220.52

Accessing from WSL VM: curl 127.0.0.1:8000 - fail curl 10.0.100.30:8000 - ok curl 172.30.208.1:8000 - ok

Accessing from a podman container container root-less: podman run --rm alpine/curl -fsSL 127.0.0.1:8000 - fail podman run --rm alpine/curl -fsSL 10.0.100.30:8000 - works podman run --rm alpine/curl -fsSL 172.30.208.1:8000 - works

Rootful: sudo podman run --rm alpine/curl -fsSL 127.0.0.1:8000 - fail sudo podman run --rm alpine/curl -fsSL 10.0.100.30:8000 - works sudo podman run --rm alpine/curl -fsSL 172.30.208.1:8000 - works

Conclusion

Works as expected.

2.Mirroring enabled

with: notepad $env:USERPROFILE\.wslconfig

[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

then: wsl --shutdown and wsl, then windows rebooted, vm recreated

  • Windows interfaces:
    • Ethernet 10.0.100.30 (LAN)
  • WSL Linux interfaces:
    • lo 127.0.0.1, 10.255.255.254
    • eth0 10.0.100.30
    • loopback0 no-ip-address

curl 10.0.100.30:8000 - fail curl 127.0.0.1:8000 - success

Conclusion

  • There is no classic way to reach Windows as interfaces are mirrored and there is no distinctive address
    • I tried searching for possibility of adding an interface that won't be mirrored, but did not find anything
  • loopback0 is shared by some trickery, seems like it is the only way to reach Windows from Linux.
    • I tried forwarding packets from container to 127.0.0.1 to utilize loopback0:
sysctl -w net.ipv4.conf.podman0.route_localnet=1

nft add table ip nat
nft add chain nat prerouting { type nat hook prerouting priority dstnat \; policy accept \; }
nft add chain nat postrouting { type nat hook postrouting priority srcnat \; policy accept \; }

nft add rule nat prerouting iifname "podman0" tcp dport 8000 dnat to 127.0.0.1:8000 counter

# Add SNAT rule as packets with non 127.0.0.1 address on windows loopback are ignored
nft add rule nat postrouting oifname "loopback0" ip daddr 127.0.0.1 snat to 127.0.0.1 counter

The success is limited. It works correctly once every X times. Most often SYN is received on Windows, SYN ACK response is sent back (see the screenshot from wireshark on windows), but SYN ACK is not seen on linux loopback0. I don't see any pattern in that.

Image

dbie0 avatar Feb 27 '26 20:02 dbie0

This is fixed with pomdna 6.1 in https://github.com/podman-container-tools/container-libs/pull/959

Luap99 avatar Jul 31 '26 15:07 Luap99