{"record":{"id":"a87427f21717cbf0","repo":"cloudflare/cloudflared","slug":"invalid-hostname-provided","errorCode":null,"errorMessage":"Invalid hostname provided","messagePattern":"Invalid hostname provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cloudflared/tunnel/cmd.go","lineNumber":243,"sourceCode":"\t\tFlags:       tunnelFlags(false),\n\t}\n}\n\nfunc TunnelCommand(c *cli.Context) error {\n\tsc, err := newSubcommandContext(c)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Run an adhoc named tunnel\n\t// Allows for the creation, routing (optional), and startup of a tunnel in one command\n\t// --name required\n\t// --url or --hello-world required\n\t// --hostname optional\n\tif name := c.String(cfdflags.Name); name != \"\" {\n\t\thostname, err := validation.ValidateHostname(c.String(\"hostname\"))\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"Invalid hostname provided\")\n\t\t}\n\t\ttunnelURL := c.String(\"url\")\n\t\tif tunnelURL == hostname && tunnelURL != \"\" && hostname != \"\" {\n\t\t\treturn fmt.Errorf(\"hostname and url shouldn't match. See --help for more information\")\n\t\t}\n\n\t\treturn runAdhocNamedTunnel(sc, name, c.String(CredFileFlag))\n\t}\n\n\t// Run a quick tunnel\n\t// A unauthenticated named tunnel hosted on <random>.<quick-tunnels-service>.com\n\tshouldRunQuickTunnel := c.IsSet(\"url\") || c.IsSet(ingress.HelloWorldFlag)\n\tif c.String(\"quick-service\") != \"\" && shouldRunQuickTunnel {\n\t\treturn RunQuickTunnel(sc)\n\t}\n\n\t// If user provides a config, check to see if they meant to use `tunnel run` instead\n\tif ref := config.GetConfiguration().TunnelID; ref != \"\" {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cmd/cloudflared/tunnel/cmd.go#L225-L261","documentation":"TunnelCommand validates the --hostname flag with validation.ValidateHostname before using it; when the value is not an acceptable hostname (empty, illegal characters, oversized labels, malformed punycode, etc.) the validation error is wrapped as 'Invalid hostname provided'. This guards the DNS route that will be created for the tunnel, since an invalid hostname would fail later at the Cloudflare API anyway.","triggerScenarios":"`cloudflared tunnel --hostname <value> ...` where <value> fails ValidateHostname: contains spaces or invalid characters, has empty labels (a..b), exceeds 253 chars or 63-char label limit, uses bad punycode, or is an empty string passed explicitly via --hostname \"\" with --name set.","commonSituations":"Typos in the hostname; quoting mistakes leaving stray characters or empty value; copying a full URL (https://example.com) instead of a bare hostname; IDN hostnames not properly punycoded; shell variable expanding to empty.","solutions":["Check the value passed to --hostname: it must be a bare, valid DNS hostname like app.example.com (no scheme, path, or spaces).","Strip scheme/path if you copied a URL: use --hostname app.example.com, not https://app.example.com/route.","Ensure --hostname is non-empty; if you don't want a hostname, omit the flag entirely instead of passing an empty string.","Punycode internationalized names before passing them (e.g. xn--bcher-kva.example)."],"exampleFix":"// before\ncloudflared tunnel run --name mytunnel --hostname https://app.example.com/\n\n// after\ncloudflared tunnel run --name mytunnel --hostname app.example.com","handlingStrategy":"validation","validationCode":"import \"golang.org/x/net/idna\"\nfunc validHostname(h string) bool {\n    if h == \"\" || strings.Contains(h, \"://\") || strings.ContainsAny(h, \" /\\t\") { return false }\n    _, err := idna.Lookup.ToASCII(h)\n    return err == nil\n}\n// call before: cloudflared tunnel run --hostname $HOSTNAME_ARG","typeGuard":null,"tryCatchPattern":"if err := runTunnel(); err != nil && strings.Contains(err.Error(), \"Invalid hostname provided\") { t.Fatalf(\"check --hostname value: %v\", err) }","preventionTips":["Pass bare hostnames (no scheme/path) to --hostname","Never pass --hostname with an empty value; omit the flag if unneeded","Punycode IDN names before passing them","Shell-quote hostname variables and verify expansion in scripts"],"tags":["cli","hostname","validation","dns"],"backgroundTag":"invalid-argument-value","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"}