{"record":{"id":"2d80936de65faf32","repo":"lima-vm/lima","slug":"network-mode-q-requires-specifying-interface","errorCode":null,"errorMessage":"network mode %#q requires specifying interface","messagePattern":"network mode %#q requires specifying interface","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/network.go","lineNumber":209,"sourceCode":"\tgateway, err := flags.GetString(\"gateway\")\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tintf, err := flags.GetString(\"interface\")\n\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() {","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/network.go#L191-L227","documentation":"All non-bridged modes that require explicit topology (host, routed) must be given a gateway address; if --gateway is empty, networkCreateAction returns this error at cmd/limactl/network.go:209 (the default branch of the mode switch). The gateway is written into the network's yq definition as part of creation.","triggerScenarios":"`limactl network create <name> --mode host` (or routed) without --gateway, or with --gateway \"\" coming from an empty shell variable.","commonSituations":"Scripts where a GATEWAY variable is unset; forgetting that host/routed modes differ from bridged/shared mode requirements; copying a shared-mode example command for a host-mode network.","solutions":["Add the flag: `limactl network create <name> --mode host --gateway <subnet-gateway-ip>`","Use --mode shared if you don't want to manage gateways manually","Ensure the variable supplying --gateway is set and non-empty in scripts"],"exampleFix":"// before\nlimactl network create lima-net --mode host\n# Error: network mode \"host\" requires specifying gateway\n// after\nlimactl network create lima-net --mode host --gateway 192.168.5.1","handlingStrategy":"validation","validationCode":"MODE=host; GW=\"${GATEWAY:-}\"\n[ \"$MODE\" = \"host\" -o \"$MODE\" = \"routed\" ] && [ -z \"$GW\" ] && { echo \"$MODE requires --gateway\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := cmd.Execute(); err != nil {\n\tif strings.Contains(err.Error(), \"requires specifying gateway\") {\n\t\tfmt.Fprintln(os.Stderr, \"add e.g. --gateway 192.168.5.1 for host/routed mode\")\n\t\tos.Exit(2)\n\t}\n\tos.Exit(1)\n}","preventionTips":["Always pass --gateway for host and routed modes","Fail fast in scripts when the gateway variable is empty","Prefer --mode shared when gateway management is unnecessary"],"tags":["network","cli","gateway"],"backgroundTag":"missing-required-flag","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}