Skip to content

[Bug]: Network is unreachable after turning on VPN #1307

Open

Description

@jkchen1095

I have done the following

  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Steps to reproduce

Reproduce:

  1. container system start
  2. container start -ai ubuntu
  3. open and connect to VPN on MAC host

Current behavior

then the client ubuntu container can no longer connect to internet

Expected behavior

then the client ubuntu container should connect to internet stably

Environment

- OS: Tahoe 26.2
- Xcode: xcode-select version 2416
- Container: container CLI version 0.9.0-35-g899081d (build: release, commit: 899081d)

Relevant log output

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added theissue type on Mar 12, 2026
  2. kennytm commented on Mar 13, 2026

    @kennytm

    it seems to loss internet connection only for destinations that needs to be routed through the VPN.

    for instance, when i set up a WireGuard peer with AllowIPs = 1.1.1.1/32 on the Mac, then:

    • ping 1.1.1.1 from the host - works
    • ping 1.0.0.1 from the host - works
    • ping 1.1.1.1 from the container - 100% lost
    • ping 1.0.0.1 from the container - works
  3. rsteneteg commented on Mar 25, 2026

    @rsteneteg

    I have the same problem on my Mac, I use a vpn for connecting to my workplace from home, and the vpn does not allow split tunnel, so everything must be routed over the vpn, but the subnet the containers use are not allowed over the vpn.

    If I use Docker Desktop for mac it works both with and without the VPN active.

  4. jglogan commented on Mar 26, 2026

    @jglogan
    Contributor

    @jkchen1095 @rsteneteg could you provide the output of this command?

    sudo lsof -i 53
    

    If there some other software than mDNSResponder listening on IPv4:*:53 then you're probably looking at a dupe of #402.

    What I want to check is whether this is a routing issue or a potential DNS issue. @kennytm tested with ping to IP addresses so that could mean a routing issue, or that the ICMP packets are getting blackholed for some other reason.

    I run container with a VPN active pretty much 100% of the time. Mostly full-tunnel but sometimes split tunnel.

  5. rsteneteg commented on Mar 26, 2026

    @rsteneteg

    @jkchen1095 @rsteneteg could you provide the output of this command?

    sudo lsof -i 53
    

    If there some other software than mDNSResponder listening on IPv4:*:53 then you're probably looking at a dupe of #402.

    What I want to check is whether this is a routing issue or a potential DNS issue. @kennytm tested with ping to IP addresses so that could mean a routing issue, or that the ICMP packets are getting blackholed for some other reason.

    I run container with a VPN active pretty much 100% of the time. Mostly full-tunnel but sometimes split tunnel.

    Hi,

    This the the output before I connect the vpn

    COMMAND   PID           USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    mDNSRespo 533 _mdnsresponder   32u  IPv4 0xee2130ac8aa1c032      0t0  UDP *:domain
    mDNSRespo 533 _mdnsresponder   47u  IPv6 0x532cd52a5b42035a      0t0  UDP *:domain
    mDNSRespo 533 _mdnsresponder   56u  IPv4 0xc2422d7c6ed06784      0t0  TCP *:domain (LISTEN)
    mDNSRespo 533 _mdnsresponder   58u  IPv6 0x5c8c3518b98aea86      0t0  TCP *:domain (LISTEN)
    

    and this is after

    COMMAND   PID           USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    mDNSRespo 533 _mdnsresponder   32u  IPv4 0xee2130ac8aa1c032      0t0  UDP *:domain
    mDNSRespo 533 _mdnsresponder   47u  IPv6 0x532cd52a5b42035a      0t0  UDP *:domain
    mDNSRespo 533 _mdnsresponder   56u  IPv4 0xc2422d7c6ed06784      0t0  TCP *:domain (LISTEN)
    mDNSRespo 533 _mdnsresponder   58u  IPv6 0x5c8c3518b98aea86      0t0  TCP *:domain (LISTEN)
    

    Even if I use IP rather than dns it also don't work.

    My works VPN only allows specific CIDRs to pass through the vpn :/ and the containers are not in those approved CIDRs

  6. menthena commented on Apr 29, 2026

    @menthena

    Similarly I have the same issue. With my personal Mac, I am able to curl as expected.

    $ container run -it --rm alpine/curl curl https://google.com
    <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>
    

    sudo lsof -i :53 output is empty.


    Workplace Macbook is behind ZScaler, and seeing "Could not contact DNS servers".

    $ sudo lsof -i :53
    Zscaler | root | UDP | ...:domain
    

    Unfortunately unable to kill the ZScaler process.

    container CLI version 0.12.1 (commit: e9891b3)

  7. ThomasSchoeller commented on May 22, 2026

    @ThomasSchoeller

    Problem is VPN client changes the default route and than NAT does not work anymore.

    in my case my VPN interface is utun6. Setting an explicit NAT rule fixes it for me.

    echo "nat on utun6 from 192.168.64.0/24 to any -> (utun6)" | pfctl -a "com.apple.internet-sharing" -N -f -

  8. goafabric commented on Jul 7, 2026

    @goafabric

    I bumped into the same problems with Zscaler.
    External and als Containers Internal DNS is blocked.
    External can be overriden with the mentioned --dns 8.8.8.8, but internal is then still non functional.
    For container machine this workaround is not availaible, so here the container image needs to be patched.

    Would be great if we could get a solution.
    Because the docker people eventually got it working.
    Otherwise for now apple containers as amazing as it is already, cannot be used with a zscaler corporate proxy.
    @goafabric remindme

  9. dwsteele commented on Jul 14, 2026

    @dwsteele

    Same issue with NordVPN.

  10. smparekh commented on Jul 22, 2026

    @smparekh

    Same issue with tailscale, although it is intermittent

  11. drewbroadley commented on Jul 28, 2026

    @drewbroadley

    I've got the same issue in #1986 where I've reported a DHCP ip lease change causing the same issues as above.

    It's a blocker to using Apple Containers.

  12. acdha commented on Jul 31, 2026

    @acdha

    At least part of the problem is that the container system always uses the default hardware interface for the ipv4Gateway and ipv6Gateway, which fails when you have a VPN which prevents split-tunneling by restricting all traffic other than the VPN itself. There doesn't seem to be a documented way to change that gateway.

  13. pjezek commented on Aug 21, 2026

    @pjezek

    It might not help every one, but in my case ipv4 is also affected by VPN (Forticlient with full tunnel). Workaround was to switch to ipv6:

    # start container, listens on ipv6
    container run -d -p '[::1]:8080:8000' --rm --name my-web-server python:alpine python3 -m http.server 8000 --bind ::
    
    # connect with curl (ipv6)
    curl -v -6 --noproxy '*'  "http://[$(container list --format yaml | yq -r '.[] | select(.id == "my-web-server") | .status.networks[0].ipv6Address | split("/")[0]')]:8000"
    
    # access port forward with curl
    curl -6 -v --noproxy '*' 'http://[::1]:8080'
    
    
  14. ThomasSchoeller commented on Aug 28, 2026

    @ThomasSchoeller

    Hey @acdha

    At least part of the problem is that the container system always uses the default hardware interface for the ipv4Gateway and ipv6Gateway, which fails when you have a VPN which prevents split-tunneling by restricting all traffic other than the VPN itself. There doesn't seem to be a documented way to change that gateway.

    Have you tried my workaround in #1307 (comment)
    this works perfectly for me. only after reboot or updates i have to redo adding the fw rule as it is not permanent (haven't looked in how to do it).

    Cheers
    Thomas

  15. hfoffani commented on Oct 17, 2026

    @hfoffani

    9. Problem is VPN client changes the default route and than NAT does not work anymore.
    in my case my VPN interface is utun6. Setting an explicit NAT rule fixes it for me.
    echo "nat on utun6 from 192.168.64.0/24 to any -> (utun6)" | pfctl -a "com.apple.internet-sharing" -N -f -

    Thanks @ThomasSchoeller It works for me.
    You run it like this:
    container run --rm --dns 10.64.0.1 docker.io/library/alpine nslookup api.github.com
    Add more DNS if you don't always exit through the VPN
    container run --rm --dns 10.64.0.1 --dns 1.1.1.1 docker.io/library/alpine nslookup api.github.com
    although it adds a few rounds of failures.

    Here's script I've added to my ~/.local/bin

    #!/usr/bin/env bash
    # Add a pf NAT rule so Apple `container` VMs can reach the internet through an
    # active full-tunnel VPN (workaround for apple/container#1307).
    # Run it after the VPN connects, and again after a reboot, update or reconnect.
    set -euo pipefail
    
    SUBNET="${CONTAINER_SUBNET:-192.168.64.0/24}"
    ANCHOR="com.apple.internet-sharing"
    
    IF=$(route -n get 1.1.1.1 2>/dev/null | awk '/interface:/ {print $2}')
    
    if [[ -z "$IF" ]]; then
      echo "No route to 1.1.1.1 (offline?)" >&2
      exit 1
    fi
    
    if [[ "$IF" != utun* ]]; then
      echo "Traffic goes out via $IF, not a VPN tunnel: no rule needed."
      exit 0
    fi
    
    if ! out=$(echo "nat on $IF from $SUBNET to any -> ($IF)" | sudo pfctl -a "$ANCHOR" -N -f - 2>&1); then
      echo "$out" >&2
      exit 1
    fi
    
    echo "Applied:"
    sudo pfctl -a "$ANCHOR" -s nat 2>&1 | grep '^nat' || true
    
  16. pmarques commented on Oct 29, 2026

    @pmarques

    One of the laptops I use has a GlobalProtect VPN and although I came across a few suggestions and scripts in this repo, nothing seemed to work. After some back and forth with one LLM, I managed to get it working.

    The is the script the LLM came up with

    ~/.bin/container-vpn
    #!/usr/bin/env bash
    # Make Apple `container` networking work while GlobalProtect is connected.
    #
    # GlobalProtect routes every local subnet (including the container vmnet subnet)
    # into its tunnel, so replies NATed back by vmnet get sent to utunX instead of the
    # container bridge. This loads a pf rule that re-routes those packets to the bridge.
    #
    # Usage: container-vpn [up|down|status]
    set -euo pipefail
    
    ANCHOR="com.apple/container-vpn"
    
    vpn_if() {
      route -n get default 2>/dev/null | awk '/interface:/ {print $2}'
    }
    
    # Bridge that holds the gateway address; only exists while a container is running.
    bridge_for() {
      local gw="$1" i
      for i in $(ifconfig -l); do
        [[ "$i" == bridge* ]] || continue
        ifconfig "$i" | grep -q "inet $gw " && { echo "$i"; return; }
      done
      echo "bridge100"
    }
    
    rules() {
      local tun="$1" name subnet base gw br
      container network ls | awk 'NR > 1 {print $1, $2}' | while read -r name subnet; do
        base="${subnet%/*}"
        gw="${base%.*}.1"
        br="$(bridge_for "$gw")"
        echo "# network $name ($subnet) via $br" >&2
        echo "pass out quick on $tun route-to $br inet from any to $subnet no state"
      done
    }
    
    up() {
      local tun
      tun="$(vpn_if)"
      if [[ "$tun" != utun* ]]; then
        echo "Default route is via '${tun:-none}', not a VPN tunnel; nothing to do." >&2
        exit 0
      fi
      echo "VPN interface: $tun" >&2
      rules "$tun" | sudo pfctl -a "$ANCHOR" -f - 2>/dev/null
      sudo pfctl -s info 2>/dev/null | grep -q 'Status: Enabled' || sudo pfctl -e 2>/dev/null
      status
    }
    
    down() {
      sudo pfctl -a "$ANCHOR" -F all 2>/dev/null
      echo "Removed rules from anchor $ANCHOR" >&2
    }
    
    status() {
      sudo pfctl -a "$ANCHOR" -vsr 2>/dev/null
    }
    
    case "${1:-up}" in
      up) up ;;
      down) down ;;
      status) status ;;
      *) echo "Usage: $(basename "$0") [up|down|status]" >&2; exit 1 ;;
    esac
    

    To run a container with external / internaet networking access, just run the script before starting any container. Hope this helps someone else.

    1. container system start
    2. container-vpn up
    3. Start any container
    Test result
    container run --rm alpine ping 1.1.1.1
    PING 1.1.1.1 (1.1.1.1): 56 data bytes
    64 bytes from 1.1.1.1: seq=0 ttl=55 time=10.318 ms
    64 bytes from 1.1.1.1: seq=1 ttl=55 time=11.172 ms
    ^C
    --- 1.1.1.1 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max = 10.318/10.745/11.172 ms
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions