{"record":{"id":"715ec384d72d4de8","repo":"apache/cassandra","slug":"java-net-unknownhostexception","errorCode":null,"errorMessage":"java.net.UnknownHostException","messagePattern":"java\\.net\\.UnknownHostException","errorType":"console","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/CommandUtils.java","lineNumber":250,"sourceCode":"    public static SortedMap<String, SetHostStatWithPort> getOwnershipByDcWithPort(NodeProbe probe, boolean resolveIp,\n                                                                                  Map<String, String> tokenToEndpoint,\n                                                                                  Map<String, Float> ownerships)\n    {\n        SortedMap<String, SetHostStatWithPort> ownershipByDc = Maps.newTreeMap();\n        EndpointSnitchInfoMBean epSnitchInfo = probe.getEndpointSnitchInfoProxy();\n        try\n        {\n            for (Map.Entry<String, String> tokenAndEndPoint : tokenToEndpoint.entrySet())\n            {\n                String dc = epSnitchInfo.getDatacenter(tokenAndEndPoint.getValue());\n                if (!ownershipByDc.containsKey(dc))\n                    ownershipByDc.put(dc, new SetHostStatWithPort(resolveIp));\n                ownershipByDc.get(dc).add(tokenAndEndPoint.getKey(), tokenAndEndPoint.getValue(), ownerships);\n            }\n        }\n        catch (UnknownHostException e)\n        {\n            throw new RuntimeException(e);\n        }\n        return ownershipByDc;\n    }\n\n    private enum KeyspaceSet\n    {\n        ALL, NON_SYSTEM, NON_LOCAL_STRATEGY, ACCORD_MANAGED\n    }\n}\n","sourceCodeStart":232,"sourceCodeEnd":260,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/CommandUtils.java#L232-L260","documentation":"getOwnershipByDcWithPort resolves endpoint IPs to hostnames (via resolveIp/DNS reverse lookup) while computing token ownership per datacenter, and any java.net.UnknownHostException is rethrown as a RuntimeException. It means DNS could not reverse-map one of the cluster member IPs.","triggerScenarios":"Running ownership-reporting commands (e.g. `nodetool tablehistograms`, `nodetool tpstats`-style ownership output, RingState/OwnershipCommands) where a node's IP has no PTR record or DNS is unreachable.","commonSituations":"Cloud environments without reverse DNS for instance IPs; /etc/hosts entries missing; broken or slow DNS resolvers; nodes recently replaced leaving stale IPs in ring metadata.","solutions":["Add the node IPs to /etc/hosts (or DNS PTR records) so reverse resolution succeeds.","Fix the resolver configuration (resolv.conf) or VPN/DNS connectivity.","Enable/verify `broadcast_address`/`listen_address` settings so ring IPs are resolvable.","Report against the wrapped UnknownHostException cause to identify the failing IP."],"exampleFix":"// before\n# /etc/hosts missing cluster node IPs\n// after\n10.0.0.5 cassandra-1\n10.0.0.6 cassandra-2  # add entries so reverse lookup succeeds","handlingStrategy":"try-catch","validationCode":"// pre-resolve each endpoint IP before requesting ownership\nInetAddress addr = InetAddress.getByName(ip); // throws UnknownHostException early, locally diagnosable","typeGuard":null,"tryCatchPattern":"try { ownership = CommandUtils.getOwnershipByDcWithPort(probe, ...); }\ncatch (RuntimeException e) {\n    if (e.getCause() instanceof java.net.UnknownHostException uhe) { /* fix DNS/hosts, or fall back to IP display */ }\n    else throw e;\n}","preventionTips":["Maintain /etc/hosts or DNS PTR records for all cluster node IPs.","Verify DNS resolver health on the machine running nodetool.","Prune stale IPs after node replacement/decommission.","In cloud environments, prefer endpoints that support reverse DNS."],"tags":["dns","network","nodetool"],"backgroundTag":"unknown-host","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}