lima-vm/lima · error
failed to get hostname for instance %#q, err: %w (out=%#q)
Error message
failed to get hostname for instance %#q, err: %w (out=%#q)
What it means
getSSHAddress resolves the instance IP by asking the distro for its hostname resolution (e.g. via `hostname -I`-style wsl command). If the command fails, or yields nothing routable (empty or loopback like 127.0.1.1), Lima cannot produce a reachable SSH address.
Source
Thrown at pkg/driver/wsl2/vm_windows.go:290
return strings.TrimSpace(string(out)), nil
}
// Alpine
cmd = exec.CommandContext(ctx, "wsl.exe", "-d", distroName, "sh", "-c", `ip route get 1 | awk '{gsub("^.*src ",""); print $1; exit}'`)
out, err = cmd.CombinedOutput()
if err == nil {
return strings.TrimSpace(string(out)), nil
}
// fallback
cmd = exec.CommandContext(ctx, "wsl.exe", "-d", distroName, "hostname", "-i")
out, err = cmd.CombinedOutput()
if err == nil {
ip := net.ParseIP(strings.TrimSpace(string(out)))
// some distributions use "127.0.1.1" as the host IP, but we want something that we can route to here
if ip != nil && !ip.IsLoopback() {
return strings.TrimSpace(string(out)), nil
}
}
return "", fmt.Errorf("failed to get hostname for instance %#q, err: %w (out=%#q)", instName, err, string(out))
}
View on GitHub (pinned to dd909d0973)
Solutions
- Ensure the instance is running (`limactl start <instance>`) before querying its SSH address
- Check the out= portion; if empty, boot the distro manually (`wsl -d lima-<instance>`) and inspect /etc/hosts and `hostname -I`
- If only 127.0.1.1 is returned, verify guest networking: `wsl -d lima-<instance> ip addr`, restart WSL networking (`wsl --shutdown` then start)
- Update WSL (`wsl --update`) — newer versions provide proper localhost/NAT addressing
Defensive patterns
Strategy: retry
Validate before calling
// Only query SSH address when instance is running
const state = await limactlInspect(inst);
if (state.status !== 'Running') throw new Error('Start the instance first'); Type guard
function isSSHAddrError(e) { return /failed to get hostname/.test(String(e)); } Try / catch
async function sshAddressWithRetry(inst, attempts = 5) {
for (let i = 0; i < attempts; i++) {
try { return await limactlShell(inst, 'hostname -I'); }
catch (e) {
if (!/failed to get hostname/.test(String(e)) || i === attempts - 1) throw e;
await new Promise(r => setTimeout(r, 2000)); // wait for guest networking
}
}
} Prevention
- Wait for full guest boot before resolving the SSH address
- Check guest /etc/hosts doesn't map hostname solely to 127.0.1.1
- If only loopback IPs are returned, `wsl --shutdown` and restart to reset NAT networking
- Keep WSL updated for reliable localhost forwarding
When it happens
Trigger: InspectStatus calls getSSHAddress; the wsl command used to fetch the guest IP exits non-zero (distro stopped/broken) or returns only loopback addresses such as 127.0.1.1 used by some Debian-based distros.
Common situations: Instance not fully booted so the guest networking isn't up; distro stopped, so wsl commands return errors; /etc/hosts in the distro maps hostname only to 127.0.1.1; unusual distro without standard hostname tooling.
Related errors
- cannot use `--sync` with a wsl2 instance, the host directory
- unimplemented
- failed to run `wsl.exe --distribution %s`: %w (out=%#q)
- failed to run `wsl.exe --import %s %s %s`: %w (out=%#q)
- failed to run `wsl.exe --terminate %s`: %w (out=%#q)
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/9c103b3031508fb6.
Report an issue: GitHub.