You need a DNS-server for this. A small VM or a Raspberry Pi will be enough for most environments. "unbound" is a linux package that can be used here. It can be very lightweight.
If you found this post helpful, please give it Kudos. If my answer solves your problem, please click Accept as Solution so others can benefit from it.