java-dns-cache-manipulator lets a JVM answer DNS for you
🌏 A tiny 0-dependency thread-safe Java™ lib for setting/viewing dns programmatically without touching host file, make unit/integration testing portable; and a tiny tool for setting/viewing dns of running JVM process.
At a glance
- What is it?
- The Java Dns Cache Manipulator is a small library and a small command line tool for setting and viewing the DNS cache inside a running JVM, without touching the host's own resolver configuration. The point of it is testability: a test that needs a name to resolve to a particular address can arrange that inside the process, and the same code can then be pointed at a real service without editing the machine it runs on.
- Who is it for?
- java-dns-cache-manipulator suits a Java team whose tests depend on a specific name resolving to a specific address, since it removes the need to edit the host's resolver configuration or to depend on a DNS server the test owns.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 73 days ago.
- What is it written in?
- Mainly Java, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 7, 2026, and from our analysis. They are not legal advice.
Star history
- alibaba/java-dns-cache-manipulator966 ★ · +0
| Repository | 2026-10-21 | 2026-11-07 |
|---|---|---|
| alibaba/java-dns-cache-manipulator | 966 | 966 |
0 Stars in the last 17 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
It manipulates the JVM's cache, not the machine's resolver
The project description sets out the scope in one sentence. DCM is a tiny, zero dependency, thread safe Java library for setting and viewing DNS programmatically without touching the host file, which makes unit and integration testing portable, and it also includes a tiny tool for setting and viewing the DNS of running JVM processes. That last clause is the important design constraint and the interesting capability. The library does not rewrite `/etc/hosts` and does not ask you to run a local DNS server, so a test that needs `api.example.internal` to resolve to `127.0.0.1` can arrange that in the process it is running in, and the same test suite can be pointed at a real environment by changing nothing. The tool exists for the case where you cannot control the process, so it reaches into a JVM that is already running, which is what you need when the DNS cache is the problem and the code under test is not yours.
The library's operations are a small, complete set
The feature list for the library is short enough to read twice, and the order of the items is the order of a workflow. You can set or reset a DNS cache entry, and once you do the JVM will not look DNS up again, and you can do that for a single DNS record or in batch through a properties file. You can view the content of a DNS cache entry, and the documentation is careful to say that this covers the positive cache and the negative cache. You can remove a DNS cache entry, which makes the JVM look that name up again. You can clear the whole cache, which re-looks up every domain name. And you can set or view the default DNS cache time of the JVM, again for both the positive and the negative side. The split between positive and negative caching is the detail that matters most in practice, because a negative entry means the name failed to resolve and a JVM that has cached that failure will not try again, which is exactly the kind of behaviour that makes a test flaky after the first run.
Batch configuration is a properties file
The user guide lists the ways of using the library, and the second is the one that scales. A single entry can be set directly in code, which is fine for a test that needs one name, and a batch of them can be configured through a `dns-cache.properties` file, which is the form you want when a test suite depends on a whole set of names resolving to local addresses. The file is a properties file rather than a bespoke format, which means it can be generated by a build step, passed as a system property or written by a fixture, and it does not need its own parser. The same guide then covers viewing the JVM DNS cache, removing an entry, clearing the cache and reading or setting the default cache time, so the operations available in code and the operations available to an operator are the same list.
Three precautions, and the one that surprises people
There is a precautions section for use, and it is worth reading before you file a bug. The first entry concerns JVM settings for Java 16 and later, which implies that the library needs particular flags to be able to do what it does in newer runtimes. The second is domain name case, which follows from the JVM's own behaviour, since the resolver cache is keyed by name and names are case insensitive in some contexts and not in others, so a lookup of `Example.com` and a lookup of `example.com` can end up as two entries or one depending on the runtime. The third is domain resolution cache, which is the point of the whole library, the JVM's own default cache lifetime, and which is why the library also lets you set and view that default. A library that hands you the cache also has to tell you that the cache is the thing it is manipulating, and these three entries are it doing that.
The tool reaches into a JVM you do not control
The second subproject is the tool, and its feature list is the same set of operations with one addition. You can download it, and the release assets include a `dcm-1.8.3.tar.gz` archive. Then you can set or reset a DNS cache entry, view the content of an entry, remove one, clear the cache, and set or view the DNS cache time of the JVM, all against a process that is already running. The extra capability is loading cache entries from a file, and manipulating the cache with a command line option at JVM startup, which is the version that works when the process has not started yet. That combination is what makes the tool useful in practice, since an operator investigating a resolution problem in a running service can set an entry and watch what changes, and a developer can bake the entries into the launch options of a service they are starting.
What the project is actually for
The requirement scenario in the documentation is about making tests portable, and the whole feature set is a consequence of that. Without this library, a test that depends on a name resolving to a local address has three bad options: change the host file, which is shared state that leaks between tests and between developers, stand up a DNS server, which is a service to run in CI, or hope the name resolves, which is not a test. DCM replaces all three with a per process setting. The zero dependency claim matters here, because a test utility that drags a DNS client library into your build is a nuisance, and the thread safety claim matters because a test runner may be running tests in parallel inside one JVM. The tool exists for the neighbouring case, where the code under test is a service you did not write and its resolution is not what you expected.
Versioning, Java support and the build
The release history shows a project that tracks the Java versions it supports rather than ignoring them. v1.8.2 was published in June 2024 with the note that it supports Java 21, v1.8.3 followed in September 2024, and v1.8.4-Alpha1 arrived in May 2026 with support for Java 25, still in alpha. There is also a compatibility note for people on older runtimes, that starting from DCM 1.7 the project moved up to Java 8, and that if you need Java 6 support you should stay on the 1.6.x line. The build is Maven, with the wrapper checked in as `mvnw` and `mvnw.cmd`, and the repository has separate workflows for a fast build and a strong build, with a codecov badge for coverage and published Javadocs. The library is published to Maven Central under the `com.alibaba` group with the artifact `dns-cache-manipulator`, and the licence is Apache-2.0. The last push to the repository was on 2026-08-27.
Editorial conclusion
java-dns-cache-manipulator suits a Java team whose tests depend on a specific name resolving to a specific address, since it removes the need to edit the host's resolver configuration or to depend on a DNS server the test owns. It is a poor fit if you need to influence resolution outside the JVM, since by design it does not touch the host file, and it is a poor fit if you are on an old JVM, since the current line targets Java 8 to 21 with a Java 25 build in an alpha release and the Java 6 support lives in the 1.6.x branch. Before you adopt it, check three things: whether the JVM you run in is covered by the version you pin, since the release notes pair releases with specific Java versions, how your CI image is configured, because the documentation has a precautions section specifically about JVM settings for Java 16 and later, and whether the positive and negative cache semantics match your test expectations, since the library distinguishes them explicitly.
Frequently asked questions
What does java-dns-cache-manipulator actually change?
It sets, views, removes and clears entries in the DNS cache inside the JVM, including the negative cache, and it can set or read the JVM's default DNS cache time. It does not touch the host's resolver configuration, which is what makes tests that depend on a name resolving portable.
What is the difference between the DCM library and the DCM tool?
The library is a zero dependency, thread safe API you call from inside your own process, and the tool is a command line utility for setting and viewing the DNS cache of running JVM processes, including loading entries from a file and setting them through a command line option at JVM startup.
Which Java versions does DCM support?
The library supports Java 8 to 21, with Java 25 support arriving in the v1.8.4-Alpha1 release from 2026-05-04. If you need Java 6 you have to stay on the 1.6.x line, since the project moved up to Java 8 with version 1.7.
How do I configure several DNS entries at once?
Through a dns-cache.properties file, which the user guide lists as the batch alternative to setting an entry directly in code. Because it is a properties file it can be generated by a build step or written by a test fixture, and the same operations are available in code and in the tool.
Is java-dns-cache-manipulator on Maven Central?
Yes, under the com.alibaba group with the artifact dns-cache-manipulator, and the licence is Apache-2.0. The repository is a Maven build with the wrapper checked in, and it publishes Javadocs alongside the code.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/alibaba-java-dns-cache-manipulator)Star history chart for your README
[](https://hysenlabs.com/projects/alibaba-java-dns-cache-manipulator)Was this useful?