MacOS – How to access Mac OS web server from mobile by local name

macosNetworkwebserver

I want to debug mobile version of my website on my iphone/android. But cannot open it on mobile. I've read some related questions and all they suggest is to add localname to /etc/hosts but I already have it, but still cannot access it from mobile.

Yes – I'm on the same WiFi.

Yes – I can access web server by IP, but not localname.

What did I miss?

Best Answer

If you can get to your web server via IP address but not by hostname that means that you do not have DNS configured. DNS is designed to translate between so-called "friendly names" and IP addresses via a DNS server.

You can't edit the /etc/hosts file on iOS without jailbreaking your iPhone.

What you need to do is be able to manually configure your router (assuming you have a common home router provided by your ISP) to point local addresses to specific local host names. Unfortunately most home routers don't let you modify DNS settings, instead they pass DNS through to the ISP's DNS servers or use a public DNS server.

So what you would need to do is set up a DNS server on your local network to point local IP addresses to specific host names and then set up your iPhone to use that DNS server in Settings > WiFi > [your Wifi network] > Configure DNS > Manual.

But honestly that is a lot of trouble, I'd just use the IP address.