{"record":{"id":"7c007f4dcae56c47","repo":"abiosoft/colima","slug":"error-adding-route-for-s-via-s-w","errorCode":null,"errorMessage":"error adding route for %s via %s: %w","messagePattern":"error adding route for (.+?) via (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"environment/container/incus/route.go","lineNumber":41,"sourceCode":"\tvmIP := limautil.IPAddress(config.CurrentProfile().ID)\n\tif vmIP == \"127.0.0.1\" || vmIP == \"\" {\n\t\treturn nil\n\t}\n\n\tif !util.SubnetAvailable(BridgeSubnet) {\n\t\tlog.Warnf(\"subnet %s conflicts with host network, skipping route setup\", BridgeSubnet)\n\t\treturn nil\n\t}\n\n\tif err := embedded.InstallSudoers(c.host); err != nil {\n\t\treturn fmt.Errorf(\"error setting up sudoers for route: %w\", err)\n\t}\n\n\t// delete any stale route first (ignore errors)\n\t_ = c.removeContainerRoute()\n\n\tif err := c.host.RunQuiet(\"sudo\", \"/sbin/route\", \"add\", \"-net\", BridgeSubnet, vmIP); err != nil {\n\t\treturn fmt.Errorf(\"error adding route for %s via %s: %w\", BridgeSubnet, vmIP, err)\n\t}\n\n\treturn nil\n}\n\n// removeContainerRoute removes the macOS route for the Incus container subnet.\nfunc (c *incusRuntime) removeContainerRoute() error {\n\tif !util.MacOS() {\n\t\treturn nil\n\t}\n\n\tif !util.RouteExists(BridgeSubnet) {\n\t\treturn nil\n\t}\n\n\treturn c.host.RunQuiet(\"sudo\", \"/sbin/route\", \"delete\", \"-net\", BridgeSubnet)\n}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/environment/container/incus/route.go#L23-L59","documentation":"On macOS, colima runs 'sudo /sbin/route add -net <BridgeSubnet> <vmIP>' to make the incus bridge reachable from the host, and route returned non-zero. Despite the stale-route removal just before, the common cause is the route already existing (removal silently failed) or the VM IP being stale/invalid at that moment.","triggerScenarios":"host.RunQuiet('sudo','/sbin/route','add','-net',subnet,vmIP) fails: route already present (add is not idempotent), vmIP no longer assigned to the VM, sudo denied, or the subnet string is rejected.","commonSituations":"Repeated colima start/stop cycles leaving a stale route, VM IP changed after host network change (Wi-Fi to VPN), VPN clients manipulating the routing table concurrently.","solutions":["Remove the stale route manually: 'sudo route -n delete <BridgeSubnet>' then retry start","Check existing routes: 'netstat -rn | grep <BridgeSubnet>'","Verify the VM IP is current: 'colima list' / limactl output vs 'route get' results","Temporarily disconnect VPN if it fights colima's route management"],"exampleFix":"# before (stale route blocks add)\nroute add fails: 'File exists'\n# after\nsudo route -n delete 2001:db8:abcd::/64 2>/dev/null; colima restart","handlingStrategy":"fallback","validationCode":"// make route add idempotent: check existence first\nif util.RouteExists(BridgeSubnet) {\n    _ = c.removeContainerRoute()\n}","typeGuard":null,"tryCatchPattern":"if err := c.host.RunQuiet(\"sudo\", \"/sbin/route\", \"add\", \"-net\", BridgeSubnet, vmIP); err != nil {\n    if strings.Contains(err.Error(), \"File exists\") {\n        _ = c.removeContainerRoute()\n        return c.host.RunQuiet(\"sudo\", \"/sbin/route\", \"add\", \"-net\", BridgeSubnet, vmIP)\n    }\n    return fmt.Errorf(\"error adding route for %s via %s: %w\", BridgeSubnet, vmIP, err)\n}","preventionTips":["If start fails here, run 'sudo route -n delete <subnet>' once and restart colima","Keep colima and VPN clients from managing the same subnet — change BridgeSubnet if it collides","Always stop colima cleanly so routes get removed on teardown"],"tags":["macos","route","network","incus"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}