{"record":{"id":"20e607cc54f610f5","repo":"XTLS/Xray-core","slug":"unable-to-set-routes","errorCode":null,"errorMessage":"unable to set routes","messagePattern":"unable to set routes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/tun/tun_windows.go","lineNumber":116,"sourceCode":"\t\t\tMetric:      0,\n\t\t}\n\t\tif ip.Addr().Is4() {\n\t\t\thas4 = true\n\t\t\troute.NextHop = netip.IPv4Unspecified()\n\t\t} else {\n\t\t\thas6 = true\n\t\t\troute.NextHop = netip.IPv6Unspecified()\n\t\t}\n\t\troutesMap[route] = struct{}{}\n\t}\n\troutesData := make([]*winipcfg.RouteData, 0, len(routesMap))\n\tfor route := range routesMap {\n\t\tr := route\n\t\troutesData = append(routesData, &r)\n\t}\n\terr := t.luid.SetRoutes(routesData)\n\tif err != nil {\n\t\treturn errors.New(\"unable to set routes\").Base(err)\n\t}\n\n\tif len(t.options.Gateway) > 0 {\n\t\taddresses := make([]netip.Prefix, 0, len(t.options.Gateway))\n\t\tfor _, address := range t.options.Gateway {\n\t\t\taddresses = append(addresses, netip.MustParsePrefix(address))\n\t\t}\n\t\terr := t.luid.SetIPAddresses(addresses)\n\t\tif err != nil {\n\t\t\treturn errors.New(\"unable to set ips\").Base(err)\n\t\t}\n\t}\n\n\tif has4 {\n\t\tipif, err := t.luid.IPInterface(windows.AF_INET)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/proxy/tun/tun_windows.go#L98-L134","documentation":"On Windows, Xray programs the TUN's routes via the winipcfg interface (LUID.SetRoutes). Failure wraps into this error. Typical base causes: insufficient privileges (route manipulation on Windows requires Administrator/SYSTEM), the wintun adapter being in a transient state, or conflicting route entries held by another process.","triggerScenarios":"Running Xray as a normal user; the Wintun adapter still initializing; another VPN client holding overlapping routes; Windows NRPT or firewall products locking the route table.","commonSituations":"First run without elevation; running as a service under a non-privileged account; conflicts with commercial VPN software; rapid restarts where the old adapter instance is not yet torn down.","solutions":["Run Xray as Administrator (or as a service under LocalSystem)","Disconnect other VPN clients and retry","Wait a few seconds after adapter creation/removal before restarting Xray","Reboot if the Wintun adapter is stuck in a bad state, then retry"],"exampleFix":"# before\nxray.exe run -c config.json  # normal user prompt\n\n# after (elevated)\n# right-click terminal -> Run as administrator\nxray.exe run -c config.json","handlingStrategy":"retry","validationCode":"// check elevation on windows before starting tun mode\nif !isAdmin() { // tokenGetTokenInformation based check\n\tlog.Fatal(\"run as administrator\")\n}","typeGuard":null,"tryCatchPattern":"for attempt := 1; attempt <= 3; attempt++ {\n\terr := startTun(cfg)\n\tif err == nil || !strings.Contains(err.Error(), \"unable to set routes\") { break }\n\ttime.Sleep(2 * time.Second) // let adapter/vpn teardown settle\n}","preventionTips":["Always run windows xray tun mode elevated","Disconnect other VPN clients first","Add a short retry/backoff around adapter setup"],"tags":["tun","windows","routing","winipcfg","permissions"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}