Minecraft – ny way to prevent Minecraft from caching DNS

minecraft-java-edition

I have a Minecraft server hosted in my local network, and a hostname associated to it on a dns server.

When I change the dns record and update the ip of the server (new ip, same hostname), Minecraft still uses the old ip (I see it in the log console) and therefor won't connect to the server. When I use nsloockup on my computer (I'm on OSX), the hostname resolves to the right ip.

I've tried to set -Dsun.net.inetaddr.ttl=0 and -Dnetworkaddress.cache.ttl=0 in my JVM arguments, but it makes no difference.

Is there any way to clear Minecraft cached dns or to disable dns cashing completely ?

Best Answer

Minecraft caches the IP to prevent persistent DNS queries when the host's system may not have the cache enabled. As far as I recall, mine is disabled on my system and Minecraft still caches it.

Easiest fix is to restart the Minecraft server (as well as making sure the host system it runs on has the correct IP address assigned to it when you start it up).

A more-involved fix is to use a static IP for the computer it runs on, and have the external access to it route correctly, be it port-forwarding or a setup like BungeeCord (I have no idea if it still exists or not due to being out of Minecraft for a while).

An even-more involved setup is to have someone work on your server's codebase, someone probably familar with the server codebase, to add the ability to listen to a "request" to update its cached queries... something that may have to be re-done each time you update the server's executable / .jar file.

Quick Edit: Most Minecraft servers are assumed to be running on a static IP or behind a firewall that is port-forwarded to it. If you suggest the idea as a feature request on a Mojang member's Twitter, you might get enough of an audience to have them implement the idea... probably have it as a in-config-file toggle / console command for the base game. This way, custom server coders don't need to re-implement the idea if they make it first.