How can I access the WiFi router I am currently connected to via an unchanging hostname?

For command-line stuff like ping, or http in the browser to load the router's settings page.

The hostname should always point at whatever the current router's IP address is, as can be found manually by going to System Preferences > Network > Wi-Fi > Advanced > TCP/IP

enter image description here

I would like http://myrouter in Safari to do the same thing as visiting in this case. Maybe sometimes I will be connected to another wifi network where the router's IP is different, in that case I still want to be able to simply visit http://myrouter but this time get redirected to/shown for example.

Does this kind of hostname already exist? If not, how can I set that up?

  • If your router allows you to edit the DHCP/DNS info on your router you may be able to add a name there, but I don't believe that is possible as naming things on a network is done with a DNS server. And on an edge device (Mac, PC, iOS, etc) done with the hosts file. May 7, 2020 at 17:14

2 Answers 2


Thats not the way it works.

Your Mac is a client on the network(s) you attatch to and it gets its settings from from the DHCP server. In that DHCP response, theres a number of things including a DNS server assignment(s) which is where all the names on the network come from. Those name to address relationships are ultimately managed by the network admin.

Your client can’t arbitrarily assign names to IP addresses as your Mac is not the DNS server.

The /etc/hosts file is for you and you alone and must be manually updated (if necessary) when you change networks because there is nothing that’s mapping the actual router address to the name you’ve arbitrarily given it.

  • Why must it be manually updated? Can't I automate new network location detected to updating that file?
    – minseong
    May 7, 2020 at 17:38
  • You can automate the manual process
    – mmmmmm
    May 7, 2020 at 18:26
  • To what end? I do this for a living and have never needed to have a dns entry for an internet gateway
    – Allan
    May 7, 2020 at 18:48
  • Next question, for which interface? Multihomed networks often don’t connect to the same network, so there will be multiple routers. So, how do you want to differentiate the two?
    – Allan
    May 7, 2020 at 18:55
  • @Allan always wifi, and the purpose is to get into router configuration pages, public network "join" pages, ssh into my homes' routers, or (equivalently I guess) ssh into robot devices (got some robots providing their own wifi networks)
    – minseong
    Nov 25, 2020 at 22:06

Hostname-IP mappings are defined by the DHCP server, which in most home networks is the router/hotspot your Mac is currently connecting to. So there is no easy way for your Mac (as a DHCP client) to dynamically change myrouter.local to whatever IP address the router currently uses.

As a workaround, you can define a shell function to automatically open your default browser with the login page of your current router.

myrouter() {
  open $(networksetup -getinfo 'Wi-Fi' | sed -n -E '/^Router/s|.*: (.*)|http://\1/|p')

This looks up the currently connected Wi-Fi network, creates an IP-based URL for the router, and then uses open to open that URL in the default browser.

If the command line isn't your thing, you could also create a Shortcut instead of a shell function, and pin it to the Shortcut menulet for easy access.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .