java-dns-cache-manipulator
Java DNS Cache Manipulator is a lightweight, zero-dependency library for programmatically setting and viewing DNS cache entries in JVM processes without modifying system host files. It is designed to make unit and integration testing portable across environments and supports Java 8–21 with IPv6.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | alibaba/java-dns-cache-manipulator |
| Owner | alibaba |
| Primary language | Java |
| License | Apache-2.0 — OSI-approved |
| Stars | 964 |
| Forks | 191 |
| Open issues | 13 |
| Latest release | v1.8.4-Alpha1 (2026-05-04) |
| Last updated | 2026-06-18 |
| Source | https://github.com/alibaba/java-dns-cache-manipulator |
What java-dns-cache-manipulator is
DCM provides thread-safe APIs to inject DNS cache entries, query cached entries, and control TTL independently of the OS. It includes both a library component and a command-line tool for remote JVM manipulation, bypassing the need for host file modifications or SecurityManager DNS expiry restrictions.
Get the java-dns-cache-manipulator source
Clone the repository and explore it locally.
git clone https://github.com/alibaba/java-dns-cache-manipulator.gitcd java-dns-cache-manipulator# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Thread-safe design confirmed; review multithreading test coverage to ensure DNS cache mutations do not cause race conditions in your test concurrency profile.
- Java 16+ requires special JVM flags to allow DNS cache manipulation; verify your target Java versions and test environments support these flags before deployment.
- Domain name case sensitivity and negative DNS cache (failed lookups) are handled separately; test both positive and negative cache scenarios relevant to your application.
- IPv6 support is included; if your test infrastructure or application uses IPv6, validate caching behavior for AAAA records and IPv6 address format.
- Batch configuration via `dns-cache.properties` file is available; consider externalizing test DNS mappings to reduce test code coupling.
When to avoid it — and what to weigh
- Production DNS Resolution Critical Path — DCM is designed for testing and development. Relying on programmatic DNS cache manipulation in production systems handling real DNS traffic introduces operational complexity and bypasses standard DNS infrastructure.
- Dynamic DNS or Multi-Tenant DNS Switching — If your application requires frequent, automatic DNS failover or dynamic DNS updates based on external events, use proper DNS services and health-check mechanisms instead of in-memory cache manipulation.
- Cross-JVM or System-Wide DNS Control — DCM operates at JVM process level only. If you need coordinated DNS control across multiple applications or system-wide DNS resolution, use OS-level DNS configuration or a centralized DNS service.
- Lightweight Dependency Constraints — While DCM claims zero dependencies, adding it as a library dependency in production code (even if not used) introduces maintenance and security review overhead. Reserve for test or tool-only codebases.
License & commercial use
Licensed under Apache License 2.0 (Apache-2.0), a permissive OSI-approved license. Grants rights to use, modify, and distribute the software under clear conditions, including commercial use and redistribution.
Apache 2.0 is a permissive license that permits commercial use, modification, and distribution. No license fees or approval required. Ensure compliance with Apache 2.0 conditions (attribution, license notice preservation, disclaimer of warranty). Verify your legal team's acceptance of these terms before integrating into commercial products.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
DNS cache manipulation at the JVM level bypasses OS-level DNS validation. Ensure that test data and domain-to-IP mappings are controlled in test environments only; never expose DCM tool or library to untrusted input in production. When SecurityManager is enabled, DCM bypasses its DNS cache expiry policies—understand the security implications of long-lived, manually-set cache entries. No known CVEs reported in the data, but review open issues and commit history for security patches.
Alternatives to consider
Mockito / WireMock DNS Mocking
For HTTP-level mocking, WireMock and Mockito can stub DNS-dependent code without JVM-level cache manipulation. Trade-off: requires code-level spy/mock configuration; cannot control actual JVM DNS cache.
TestContainers with embedded DNS server
Spin up isolated DNS server per test; provides realistic DNS behavior and cleaner test isolation. Trade-off: heavier resource overhead, more complex test setup, slower startup.
Host file manipulation or Docker network alias
Traditional approach: edit /etc/hosts (or Windows hosts) or use Docker network aliases. Trade-off: requires admin privileges, CI/CD setup friction, not portable across developer machines.
Build on java-dns-cache-manipulator with DEV.co software developers
Need DNS mocking for portable tests? Evaluate java-dns-cache-manipulator for zero-dependency, thread-safe JVM DNS cache control. Ideal for CI/CD pipelines and performance testing. Review the documentation and assess Java version compatibility with your environment before adoption.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
java-dns-cache-manipulator FAQ
Can I use DCM in production to dynamically update DNS?
Does DCM affect the operating system's DNS resolver?
What Java versions are supported?
Can I use DCM without modifying my test code?
Software development & web development with DEV.co
From first prototype to production, DEV.co delivers software development services around tools like java-dns-cache-manipulator. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across open-source testing and beyond.
Simplify Your DNS Testing Strategy
Need DNS mocking for portable tests? Evaluate java-dns-cache-manipulator for zero-dependency, thread-safe JVM DNS cache control. Ideal for CI/CD pipelines and performance testing. Review the documentation and assess Java version compatibility with your environment before adoption.