.dev Domains resolving to localhost on macOS
2022-02-12 | #macOS | @Acidus
I noticed soon after launching my capsule here at gemi.dev that something strange was happening. While creating the capsule, I had hacked my /etc/hosts file so "gemi.dev" would resolve to 127.0.0.1. Later, I noticed I would get connection errors when I tried to access gemi.dev on my Mac where I had developed the capsule, but it would work from my phone. I assumed my Gemini client was trying to connect to locahost and removed the /etc/hosts entry, but I kept having the problem. I thought macOS had cached the lookup somewhere, but I couldn't find where. After rebooting the Mac I still had problems connecting to gemi.dev. It was annoying, but I assumed I had done something dumb.
Then, I ran into something strange again while building the crawler that powers Kennedy, my Gemini search engine. I was getting connection errors when trying to access *any* capsules using the .dev TLD. OK, so this a bigger issue. I went searching and turns out, macOS has another system that allows for overriding DNS: /etc/resolver/.
For some reason, my Mac had an entry in /etc/resolver/ that was making all lookups for the .dev TLD resolve to locahost. Guess I didn't need that /etc/hosts entry during development!
You can go ahead and see if there files for a TLD in the /etc/resolver/ directory:
ls -l /etc/resolver
If so, rename it. I had a "dev" file, so I renamed it to "dev.ignore" which apparently is enough.
sudo mv dev dev.ignore
Some of the advice says to "rm" the file. I first did this, and roughly 20 seconds later macOS Monterey straight-up kernel panicked on me and rebooted. so... yeah, use "mv" instead.
I'm not entirely sure why I had "dev" in my /etc/resolver/ directory to begin with. I hadn't done that, and some of the other Stack Overflow answers mention Ruby development, and something called Pow, which didn't really seem to apply to me. Oh well.
If you have a Mac, and have trouble connecting to any .dev sites, hopefully this helps you fix the issue. It also helps serve as two key reminders:
- MacOS is not Linux. This is easy to forget if you are just using typical command line tools. But as soon as you get into configuring parts of the OS or services you see how different it actually is. My mistake was assuming /etc/hosts was the only way to override DNS.
- If something simple isn't working like it should, and it not obvious why it is not working, it could be a symptom of a larger issue. Keep digging.
Oh, and please try my search engine Kennedy. The best way to make it better is to get more real world queries running through it.