lima-vm/lima · error

invalid IP address: %v

Error message

invalid IP address: %v

What it means

After the gateway CIDR parses, Lima rejects unspecified (0.0.0.0 or ::) and loopback (127.x.x.x, ::1) addresses because a gateway in those ranges cannot be a usable network gateway. The check runs on the parsed gwIP before the networks.yaml entry is written.

Source

Thrown at cmd/limactl/network.go:228

		}
		yq := fmt.Sprintf(`.networks.%q = {"mode":%q,"interface":%q}`, name, mode, intf)
		return networkApplyYQ(ctx, yq)
	default:
		if gateway == "" {
			return fmt.Errorf("network mode %#q requires specifying gateway", mode)
		}
		if intf != "" {
			return fmt.Errorf("network mode %#q does not support specifying interface", mode)
		}
		if !strings.Contains(gateway, "/") {
			gateway += "/24"
		}
		gwIP, gwMask, err := net.ParseCIDR(gateway)
		if err != nil {
			return fmt.Errorf("failed to parse CIDR %#q: %w", gateway, err)
		}
		if gwIP.IsUnspecified() || gwIP.IsLoopback() {
			return fmt.Errorf("invalid IP address: %v", gwIP)
		}
		gwMaskStr := "255.255.255.0"
		if gwMask != nil {
			gwMaskStr = net.IP(gwMask.Mask).String()
		}
		// TODO: check IP range collision

		yq := fmt.Sprintf(`.networks.%q = {"mode":%q,"gateway":%q,"netmask":%q,"interface":%q}`, name, mode, gwIP.String(), gwMaskStr, intf)
		return networkApplyYQ(ctx, yq)
	}
}

func networkApplyYQ(ctx context.Context, yq string) error {
	filePath, err := networks.ConfigFile()
	if err != nil {
		return err
	}
	yContent, err := os.ReadFile(filePath)

View on GitHub (pinned to dd909d0973)

Solutions

  1. Use a real routable/private gateway IP such as 192.168.5.1 or 10.0.2.1
  2. Remove 0.0.0.0/loopback placeholders from scripts and substitute an actual subnet gateway
  3. If DHCP/bridged behavior was intended, switch to --mode bridged --interface <if> instead

Example fix

// before
limactl network create mynet --gateway 127.0.0.1
// after
limactl network create mynet --gateway 192.168.5.1
Defensive patterns

Strategy: validation

Validate before calling

gw="192.168.104.1"
python3 - <<EOF
import ipaddress
ip = ipaddress.ip_interface("$gw/24").ip
assert not ip.is_unspecified and not ip.is_loopback, "gateway must not be 0.0.0.0/loopback"
EOF

Prevention

When it happens

Trigger: Running `limactl network create <name> --gateway 0.0.0.0` (or `127.0.0.1`, `::`, `::1`) with a non-bridged mode.

Common situations: Placeholder gateway values left in scripts; misunderstanding loopback as a valid internal gateway; templated configs with a default 0.0.0.0 gateway never filled in.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/dc8ff3c754003b86. Report an issue: GitHub.