{"record":{"id":"8b7f8e2d8bc0613f","repo":"cloudflare/cloudflared","slug":"s-is-not-a-valid-hostname","errorCode":null,"errorMessage":"%s is not a valid hostname","messagePattern":"(.+?) is not a valid hostname","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/tunnel/subcommands.go","lineNumber":957,"sourceCode":"\t\t\t},\n\t\t\tbuildRouteIPSubcommand(),\n\t\t},\n\t}\n}\n\nfunc dnsRouteFromArg(c *cli.Context, overwriteExisting bool) (cfapi.HostnameRoute, error) {\n\tconst (\n\t\tuserHostnameIndex = 1\n\t\texpectedNArgs     = 2\n\t)\n\tif c.NArg() != expectedNArgs {\n\t\treturn nil, cliutil.UsageError(\"Expected %d arguments, got %d\", expectedNArgs, c.NArg())\n\t}\n\tuserHostname := c.Args().Get(userHostnameIndex)\n\tif userHostname == \"\" {\n\t\treturn nil, cliutil.UsageError(\"The third argument should be the hostname\")\n\t} else if !validateHostname(userHostname, true) {\n\t\treturn nil, errors.Errorf(\"%s is not a valid hostname\", userHostname)\n\t}\n\treturn cfapi.NewDNSRoute(userHostname, overwriteExisting), nil\n}\n\nfunc lbRouteFromArg(c *cli.Context) (cfapi.HostnameRoute, error) {\n\tconst (\n\t\tlbNameIndex   = 1\n\t\tlbPoolIndex   = 2\n\t\texpectedNArgs = 3\n\t)\n\tif c.NArg() != expectedNArgs {\n\t\treturn nil, cliutil.UsageError(\"Expected %d arguments, got %d\", expectedNArgs, c.NArg())\n\t}\n\tlbName := c.Args().Get(lbNameIndex)\n\tif lbName == \"\" {\n\t\treturn nil, cliutil.UsageError(\"The third argument should be the load balancer name\")\n\t} else if !validateHostname(lbName, true) {\n\t\treturn nil, errors.Errorf(\"%s is not a valid load balancer name\", lbName)","sourceCodeStart":939,"sourceCodeEnd":975,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/tunnel/subcommands.go#L939-L975","documentation":"dnsRouteFromArg validates the user-supplied hostname argument for `cloudflared tunnel route dns` with validateHostname(userHostname, true). If validation fails, it rejects the argument with '<hostname> is not a valid hostname'. The hostname must be a syntactically valid DNS name (FQDN allowed, wildcards only as the leading label).","triggerScenarios":"Running `cloudflared tunnel route dns <tunnel> <hostname>` where the third argument contains invalid characters, is not a valid domain (e.g. includes a scheme, path, underscore, port), is an IP address, or has a misplaced wildcard like `sub.*.example.com`.","commonSituations":"Passing a full URL (https://app.example.com) instead of a bare hostname, including a port (:8080), using a subdomain-only value (app) without a zone, or wildcard notation in the wrong position.","solutions":["Pass a bare hostname/FQDN without scheme, path, or port: `app.example.com`.","Place wildcards only at the start if allowed: `*.example.com`.","Ensure the hostname belongs to a zone in your Cloudflare account so DNS routing can succeed.","Check for hidden characters/typos; retype the hostname."],"exampleFix":"// before\ncloudflared tunnel route dns my-tunnel https://app.example.com:8080\n// after\ncloudflared tunnel route dns my-tunnel app.example.com","handlingStrategy":"validation","validationCode":"// Go: check the hostname argument before calling `tunnel route dns`\nimport \"net\"\nfunc validHostnameArg(h string) bool {\n\tif h == \"\" || strings.ContainsAny(h, \":/@ \") {\n\t\treturn false\n\t}\n\tif net.ParseIP(h) != nil {\n\t\treturn false\n\t}\n\tlabels := strings.Split(strings.TrimPrefix(h, \"*.\"), \".\")\n\treturn len(labels) >= 2\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip scheme, port, and path from hostnames before passing them.","Keep wildcards only as the leading label.","Confirm the hostname's zone exists in your Cloudflare account."],"tags":["cli","dns","hostname-validation","cloudflare"],"backgroundTag":"invalid-url-format","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}