{"record":{"id":"3df471c0fe521112","repo":"hashicorp/nomad","slug":"network-hostname-q-is-not-a-valid-dns-name","errorCode":null,"errorMessage":"network hostname %q is not a valid DNS name","messagePattern":"network hostname %q is not a valid DNS name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/network_hook.go","lineNumber":132,"sourceCode":"\ttg := h.alloc.Job.LookupTaskGroup(h.alloc.TaskGroup)\n\tif len(tg.Networks) == 0 || tg.Networks[0].Mode == \"host\" || tg.Networks[0].Mode == \"\" {\n\t\treturn nil\n\t}\n\n\tif h.manager == nil || h.networkConfigurator == nil {\n\t\th.logger.Trace(\"shared network namespaces are not supported on this platform, skipping network hook\")\n\t\treturn nil\n\t}\n\n\t// Perform our networks block interpolation.\n\tinterpolatedNetworks := taskenv.InterpolateNetworks(allocEnv, tg.Networks)\n\n\t// Interpolated values need to be validated. It is also possible a user\n\t// supplied hostname avoids the validation on job registrations because it\n\t// looks like it includes interpolation, when it doesn't.\n\tif interpolatedNetworks[0].Hostname != \"\" {\n\t\tif _, ok := dns.IsDomainName(interpolatedNetworks[0].Hostname); !ok {\n\t\t\treturn fmt.Errorf(\"network hostname %q is not a valid DNS name\", interpolatedNetworks[0].Hostname)\n\t\t}\n\t}\n\n\t// Our network create request.\n\tnetworkCreateReq := drivers.NetworkCreateRequest{\n\t\tHostname: interpolatedNetworks[0].Hostname,\n\t}\n\n\tvar checkedOnce bool\n\nCREATE:\n\tspec, created, err := h.manager.CreateNetwork(h.alloc.ID, &networkCreateReq)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create network for alloc: %v\", err)\n\t}\n\n\tif spec != nil {\n\t\th.spec = spec","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/network_hook.go#L114-L150","documentation":"The network_hook's Prerun validates the (possibly interpolation-resolved) network hostname with dns.IsDomainName before using it to create the allocation network. Job registration validation can be bypassed when a hostname contains interpolation syntax, so the client re-validates and rejects hostnames that are not valid DNS names.","triggerScenarios":"networks[0].Hostname is non-empty after interpolation and dns.IsDomainName returns false — e.g. hostname contains invalid characters, underscores, spaces, or failed interpolation leaving a literal placeholder like \"${node.unique.name}\".","commonSituations":"Users set group network hostname to a value with illegal DNS characters, or use node/job interpolation that resolves to a name with invalid characters (dots in wrong places, empty segments), or leave an uninterpolated ${...} string because the attribute doesn't exist.","solutions":["Change the group network hostname in the jobspec to a valid DNS label/domain name (letters, digits, hyphens, dot-separated).","If using interpolation, choose a node/job attribute that resolves to a DNS-safe value or wrap/sanitize it (e.g. use node.unique.id instead of names with underscores).","Run `nomad job validate` to catch interpolation/validation issues before submitting.","Re-run the job after fixing; the client caches nothing for this check so the next Prerun validates the new value."],"exampleFix":"// before\nnetwork {\n  mode = \"bridge\"\n  hostname = \"${node.unique.name}\" // may contain underscores/invalid chars\n}\n\n// after\nnetwork {\n  mode = \"bridge\"\n  hostname = \"my-app-1\" // valid DNS name\n}","handlingStrategy":"validation","validationCode":"import \"github.com/miekg/dns\"\nfunc isValidDNSName(name string) bool {\n    return name != \"\" && dns.IsDomainName(name) && !strings.Contains(name, \"${\")\n}","typeGuard":"func hostnameSafe(h string) bool {\n    if h == \"\" || strings.Contains(h, \"$\") { return h == \"\" }\n    return dns.IsDomainName(h)\n}","tryCatchPattern":"if err := hook.Prerun(); err != nil && strings.Contains(err.Error(), \"is not a valid DNS name\") {\n    // fix the jobspec hostname and resubmit\n}","preventionTips":["Run nomad job validate before submitting jobs with hostname set.","Use DNS-safe interpolation attributes (avoid names with underscores).","Keep hostnames as plain labels or dot-separated alphanumeric-hyphen strings.","Test interpolation output on a scratch client before production rollout."],"tags":["nomad","network","dns","hostname","validation"],"backgroundTag":"invalid-dns-hostname","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}