{"record":{"id":"5993ddecd8989776","repo":"prestodb/presto","slug":"fully-qualified-name-of-localhost-should-not-resol","errorCode":null,"errorMessage":"Fully qualified name of localhost should not resolve to 'localhost'. System configuration error?","messagePattern":"Fully qualified name of localhost should not resolve to 'localhost'\\. System configuration error\\?","errorType":"exception","errorClass":"ClientException","httpStatus":null,"severity":"error","filePath":"presto-client/src/main/java/com/facebook/presto/client/SpnegoHandler.java","lineNumber":261,"sourceCode":"        if (useCanonicalHostname) {\n            serviceHostName = canonicalizeServiceHostName(hostName);\n        }\n        return format(\"%s@%s\", serviceName, serviceHostName.toLowerCase(Locale.US));\n    }\n\n    private static String canonicalizeServiceHostName(String hostName)\n    {\n        try {\n            InetAddress address = InetAddress.getByName(hostName);\n            String fullHostName;\n            if (\"localhost\".equalsIgnoreCase(address.getHostName())) {\n                fullHostName = InetAddress.getLocalHost().getCanonicalHostName();\n            }\n            else {\n                fullHostName = address.getCanonicalHostName();\n            }\n            if (fullHostName.equalsIgnoreCase(\"localhost\")) {\n                throw new ClientException(\"Fully qualified name of localhost should not resolve to 'localhost'. System configuration error?\");\n            }\n            return fullHostName;\n        }\n        catch (UnknownHostException e) {\n            throw new ClientException(\"Failed to resolve host: \" + hostName, e);\n        }\n    }\n\n    private interface GssSupplier<T>\n    {\n        T get()\n                throws GSSException;\n    }\n\n    private static <T> T doAs(Subject subject, GssSupplier<T> action)\n            throws GSSException\n    {\n        try {","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-client/src/main/java/com/facebook/presto/client/SpnegoHandler.java#L243-L279","documentation":"canonicalizeServiceHostName resolves the host to a fully qualified name via InetAddress canonical host names, and refuses 'localhost' as the result, throwing a ClientException. SPNEGO service principals must contain the real FQDN (HTTP/host.example.com@REALM); a localhost resolution means the machine's hostname/network is misconfigured and the resulting principal would not match the KDC.","triggerScenarios":"makeServicePrincipal -> canonicalizeServiceHostName when InetAddress.getLocalHost().getCanonicalHostName() (or the given address's) resolves to the string 'localhost'.","commonSituations":"/etc/hosts maps the machine's hostname to 127.0.0.1 or lists 'localhost' as canonical name; hostname set to 'localhost'; reverse DNS returning 'localhost'; container images with incomplete hostname setup.","solutions":["Fix /etc/hosts so the machine's real hostname maps to its real IP, with 127.0.0.1 pointing only to 'localhost'.","Set a proper hostname (hostnamectl set-hostname host.example.com).","Fix reverse DNS (PTR record) with your DNS admin so the IP canonicalizes to the FQDN.","Verify with: hostname -f (must not print 'localhost')."],"exampleFix":"// before (in /etc/hosts)\n127.0.0.1  myhost.example.com myhost localhost\n// after\n127.0.0.1  localhost\n10.0.0.5   myhost.example.com myhost","handlingStrategy":"validation","validationCode":"String fqdn = InetAddress.getLocalHost().getCanonicalHostName();\nif (\"localhost\".equalsIgnoreCase(fqdn)) {\n    throw new IllegalStateException(\"Fix /etc/hosts or hostname: FQDN resolves to localhost\");\n}","typeGuard":null,"tryCatchPattern":"try { ... } catch (ClientException e) { if (e.getMessage().contains(\"should not resolve to 'localhost'\")) { /* fix hostname/DNS config */ } throw e; }","preventionTips":["Ensure hostname -f does not return 'localhost'","Keep 127.0.0.1 mapped only to localhost in /etc/hosts","Configure proper reverse DNS (PTR records)","Set real hostnames in container images"],"tags":["kerberos","spnego","dns","hostname"],"backgroundTag":"localhost-hostname-resolution","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}