{"record":{"id":"c240c926274ee365","repo":"hashicorp/nomad","slug":"hostname-cannot-be-set-on-task-group-using-q-netw","errorCode":null,"errorMessage":"hostname cannot be set on task group using %q networking mode","messagePattern":"hostname cannot be set on task group using %q networking mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocrunner/network_manager_linux.go","lineNumber":38,"sourceCode":"\nfunc newNetworkManager(alloc *structs.Allocation, driverManager drivermanager.Manager) (nm drivers.DriverNetworkManager, err error) {\n\t// The defaultNetworkManager is used if a driver doesn't need to create the network\n\tnm = &defaultNetworkManager{}\n\ttg := alloc.Job.LookupTaskGroup(alloc.TaskGroup)\n\n\t// default netmode to host, this can be overridden by the task or task group\n\ttgNetMode := \"host\"\n\tif len(tg.Networks) > 0 && tg.Networks[0].Mode != \"\" {\n\t\ttgNetMode = tg.Networks[0].Mode\n\t}\n\n\tgroupIsolationMode := netModeToIsolationMode(tgNetMode)\n\n\t// Setting the hostname is only possible where the task groups networking\n\t// mode is group; meaning bridge or none.\n\tif len(tg.Networks) > 0 &&\n\t\t(groupIsolationMode != drivers.NetIsolationModeGroup && tg.Networks[0].Hostname != \"\") {\n\t\treturn nil, fmt.Errorf(\"hostname cannot be set on task group using %q networking mode\",\n\t\t\tgroupIsolationMode)\n\t}\n\n\t// networkInitiator tracks the task driver which needs to create the network\n\t// to check for multiple drivers needing to create the network.\n\tvar networkInitiator string\n\n\t// driverCaps tracks which drivers we've checked capabilities for so as not\n\t// to do extra work\n\tdriverCaps := make(map[string]struct{})\n\tfor _, task := range tg.Tasks {\n\t\t// the task's netmode defaults to the task group but can be overridden\n\t\ttaskNetMode := tgNetMode\n\t\tif len(task.Resources.Networks) > 0 && task.Resources.Networks[0].Mode != \"\" {\n\t\t\ttaskNetMode = task.Resources.Networks[0].Mode\n\t\t}\n\n\t\t// netmode host should always work to support backwards compat","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocrunner/network_manager_linux.go#L20-L56","documentation":"newNetworkManager builds the client's network manager for a task group. Setting a hostname is only supported when the group's networking mode maps to the 'group' isolation mode (bridge or none). If the group declares a hostname while using another mode (e.g. host), construction fails with this error before any network is created.","triggerScenarios":"tg.Networks is non-empty, tg.Networks[0].Hostname != \"\", and netModeToIsolationMode(tgNetMode) is not drivers.NetIsolationModeGroup — typically network { mode = \"host\" } combined with a hostname field.","commonSituations":"Users copy a jobspec from a bridge-mode example but switch mode to \"host\" while leaving hostname set; adding hostname to a task-level or host-mode network block; version upgrades where hostname validation got stricter.","solutions":["Remove the hostname field from the network block, or","Switch the group network mode to \"bridge\" (or \"none\") where hostname is supported.","Validate the jobspec with `nomad job validate` before submission to catch the mismatch.","If a static name is needed on host networking, set it inside the container via the task driver's own hostname option instead."],"exampleFix":"// before\nnetwork {\n  mode = \"host\"\n  hostname = \"my-app\" // not allowed in host mode\n}\n\n// after\nnetwork {\n  mode = \"bridge\"\n  hostname = \"my-app\"\n}","handlingStrategy":"validation","validationCode":"func hostnameAllowed(mode string, hostname string) error {\n    if hostname != \"\" && mode != \"bridge\" && mode != \"none\" {\n        return fmt.Errorf(\"hostname cannot be set on network mode %q\", mode)\n    }\n    return nil\n}","typeGuard":"func hostnameValidForMode(mode, hostname string) bool {\n    return hostname == \"\" || mode == \"bridge\" || mode == \"none\"\n}","tryCatchPattern":null,"preventionTips":["Run nomad job validate on jobspecs combining mode and hostname.","Only set hostname in group-level network blocks with bridge/none mode.","Keep jobspec templates per network mode to avoid copy/paste mismatches.","Document the mode/hostname constraint for teams authoring jobspecs."],"tags":["nomad","network","hostname","validation","jobspec"],"backgroundTag":"hostname-unsupported-network-mode","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"}