DEV.co
Open-Source Testing · alibaba

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.

Source: GitHub — github.com/alibaba/java-dns-cache-manipulator
964
GitHub stars
191
Forks
Java
Primary language
Apache-2.0
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryalibaba/java-dns-cache-manipulator
Owneralibaba
Primary languageJava
LicenseApache-2.0 — OSI-approved
Stars964
Forks191
Open issues13
Latest releasev1.8.4-Alpha1 (2026-05-04)
Last updated2026-06-18
Sourcehttps://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.

Quickstart

Get the java-dns-cache-manipulator source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/alibaba/java-dns-cache-manipulator.gitcd java-dns-cache-manipulator# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Portable Unit and Integration Testing

Eliminate host file configuration dependencies in CI/CD pipelines. Developers can set domain-to-IP mappings programmatically in test setup without requiring administrative privileges or manual configuration on build machines.

Performance and Stress Testing

Skip DNS resolution overhead in benchmarking scenarios by pre-populating cache. Run multi-scenario stress tests with different domain bindings per JVM process without affecting other test runs.

Runtime DNS Reconfiguration in Secured Environments

Update DNS bindings in running JVM processes (via DCM Tool) when SecurityManager is enabled and DNS caching is non-expiring. No need to restart the application or redeploy the DCM library.

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.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

java-dns-cache-manipulator FAQ

Can I use DCM in production to dynamically update DNS?
Not recommended. DCM is designed for testing. Production DNS updates should use proper DNS infrastructure (e.g., DNS failover, Route53, Consul). Using DCM in production bypasses standard DNS validation and operational visibility.
Does DCM affect the operating system's DNS resolver?
No. DCM only manipulates the in-memory DNS cache within a single JVM process. The OS-level DNS resolver and other JVM processes are unaffected.
What Java versions are supported?
Current version (1.8.4+) supports Java 8–21. Java 16+ requires special JVM flags (see README). For Java 6 support, use version 1.6.x.
Can I use DCM without modifying my test code?
Partially. You can use the standalone DCM Tool to manipulate running JVM processes without embedding the library. Alternatively, batch-load DNS mappings via dns-cache.properties file.

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.