{"record":{"id":"002eff49bdf5cee3","repo":"lima-vm/lima","slug":"network-mode-q-requires-specifying-gateway","errorCode":null,"errorMessage":"network mode %#q requires specifying gateway","messagePattern":"network mode %#q requires specifying gateway","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/network.go","lineNumber":215,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\tctx := cmd.Context()\n\n\tswitch mode {\n\tcase networks.ModeBridged:\n\t\tif gateway != \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q does not support specifying gateway\", mode)\n\t\t}\n\t\tif intf == \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q requires specifying interface\", mode)\n\t\t}\n\t\tyq := fmt.Sprintf(`.networks.%q = {\"mode\":%q,\"interface\":%q}`, name, mode, intf)\n\t\treturn networkApplyYQ(ctx, yq)\n\tdefault:\n\t\tif gateway == \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q requires specifying gateway\", mode)\n\t\t}\n\t\tif intf != \"\" {\n\t\t\treturn fmt.Errorf(\"network mode %#q does not support specifying interface\", mode)\n\t\t}\n\t\tif !strings.Contains(gateway, \"/\") {\n\t\t\tgateway += \"/24\"\n\t\t}\n\t\tgwIP, gwMask, err := net.ParseCIDR(gateway)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to parse CIDR %#q: %w\", gateway, err)\n\t\t}\n\t\tif gwIP.IsUnspecified() || gwIP.IsLoopback() {\n\t\t\treturn fmt.Errorf(\"invalid IP address: %v\", gwIP)\n\t\t}\n\t\tgwMaskStr := \"255.255.255.0\"\n\t\tif gwMask != nil {\n\t\t\tgwMaskStr = net.IP(gwMask.Mask).String()\n\t\t}","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/network.go#L197-L233","documentation":"`limactl network create` validates flag combinations per network mode. Any mode other than \"bridged\" (the default switch case) requires a --gateway value, because the gateway IP/netmask is written into the networks.yaml entry for that mode. If --gateway is empty for such a mode, the command aborts before applying the yq edit.","triggerScenarios":"Running `limactl network create <name>` (or with --mode set to a non-bridged mode such as host/shared) without passing --gateway.","commonSituations":"Users copying a bridged-mode example (which forbids gateway) and applying it to another mode; scripts omitting --gateway because bridged does not need it; newer modes added to the default branch that users are unaware require a gateway.","solutions":["Pass --gateway with a valid CIDR, e.g. `limactl network create mynet --gateway 192.168.5.1`","If bridged networking was intended, pass --mode bridged plus --interface <host-if> instead of a gateway","Check `limactl network create --help` for the mode-specific flag requirements"],"exampleFix":"// before\nlimactl network create lima-shared --mode shared\n// after\nlimactl network create lima-shared --mode shared --gateway 192.168.104.1","handlingStrategy":"validation","validationCode":"gateway=\"192.168.104.1\"\nmode=\"shared\"\nif [ \"$mode\" != \"bridged\" ] && [ -z \"$gateway\" ]; then\n  echo \"--gateway is required for mode $mode\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --gateway for non-bridged network modes","Use --mode bridged --interface <if> only when bridging a host interface","Check `limactl network create --help` before scripting the command"],"tags":["network","cli","missing-flag"],"backgroundTag":"missing-required-flag","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}