abiosoft/colima · error

the last octet of gateway %q is not 2

Error message

the last octet of gateway %q is not 2

What it means

validateGatewayAddress enforces Lima's addressing convention: after confirming the gateway is IPv4, the fourth octet (ip4[3]) must be exactly 2. Lima reserves .1 for the host-side interface and .2 for the gateway inside the virtual network, so any other final octet is rejected with the address echoed.

Source

Thrown at config/configmanager/configmanager.go:144

func Teardown() error {
	dir := config.CurrentProfile().ConfigDir()
	if _, err := os.Stat(dir); err == nil {
		return os.RemoveAll(dir)
	}
	return nil
}

// Validates that gateway is a valid IPv4 address and that the last octet is “2”.
// Lima uses the last octet as 2 for gateways.
func validateGatewayAddress(gateway net.IP) error {
	ip4 := gateway.To4()
	if ip4 == nil {
		return fmt.Errorf("gateway %q is not IPv4", gateway)
	}

	// Check last octet
	if ip4[3] != 2 {
		return fmt.Errorf("the last octet of gateway %q is not 2", gateway)
	}

	return nil
}

// validateMounts ensures mount paths do not contain spaces, which are not
// supported by the underlying Lima runtime and otherwise fail silently.
// See https://github.com/abiosoft/colima/issues/1471.
func validateMounts(mounts []config.Mount) error {
	for _, m := range mounts {
		for _, p := range []string{m.Location, m.MountPoint} {
			if strings.Contains(p, " ") {
				return fmt.Errorf("mount path with spaces is not supported by the underlying Lima runtime: %q", p)
			}
		}
	}
	return nil
}

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Change the last octet to 2, e.g. 192.168.104.2, within a subnet that does not collide with the LAN
  2. Pick a different /24 subnet if .2 is already spoken for
  3. Omit gatewayAddress to keep default network settings

Example fix

# before
network:
  gatewayAddress: 192.168.104.1

# after
network:
  gatewayAddress: 192.168.104.2
Defensive patterns

Strategy: validation

Validate before calling

if ip4 := c.Network.GatewayAddress.To4(); ip4 != nil && ip4[3] != 2 {
    // adjust the last octet to 2 before running ValidateConfig
}

Try / catch

if err := configmanager.ValidateConfig(c); err != nil {
    if strings.Contains(err.Error(), "last octet") {
        // Lima reserves .2 for the gateway; change e.g. 192.168.104.1 to 192.168.104.2
    }
}

Prevention

When it happens

Trigger: gatewayAddress set to an IPv4 address ending in .1, .254, or any octet other than 2, such as 192.168.104.1 copied from a typical router gateway configuration.

Common situations: Reusing a home or office router address (conventionally .1) as the colima gateway; network plans where .2 is already assigned to another host; not realizing colima must own the .2 address in its subnet.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/d578cd425212ae6d. Report an issue: GitHub.