Set MacOS Location based on WiFi name


Sometimes you want to have different network settings based on your location. For example in my scenario I need to have custom defined DNS for my home WiFi network, however in the office I’m fine with the default automatic settings. Unfortunately unlike Linux MacOS (OS X) doesn’t allow you to set custom per WiFi network settings, however you can overwrite DNS per Location.

I use DNS ad blocking at home, but unfortunately my router doesn’t support setting custom DNS name network-wide, so I have to reconfigure it on per-device basis.

What the hell is «location»? In macOS, «location» refers to a feature that allows you to quickly switch between different network configurations based on your current location or network environment. It is particularly useful for users who frequently connect to different networks, such as at home, work, or public places.

When you create a new location in macOS, you can customize various network settings, including:

  1. Wi-Fi networks: You can specify which Wi-Fi networks to connect to automatically or manually.
  2. Ethernet settings: You can configure Ethernet settings, such as IP address, subnet mask, router, and DNS servers.
  3. VPN settings: You can set up and enable/disable VPN connections for each location.
  4. Proxy settings: You can configure proxy settings, such as enabling/disabling proxies and specifying proxy servers.
  5. Default printer: You can set a default printer for each location.

One boring thing about location is that you need to change it manually. However, there’s a solution by rimar which I want to share with you. It automatically changes the MacOS network location when a configured Wi-Fi (SSID) becomes connected.

  1. First create at least 2 locations: Home and Work (you can pick any name, it’s just an example), set the desired location settings.

  2. Download a fork with fixes for the latest MacOS. In the latest version of MacOS (Sonoma 14.4) they deprecated airport command.

   git clone https://github.com/matteofilippetto/wifi-location-changer
  1. Copy sample config file and adjust it accordingly:
   cd wifi-location-changer
   cp ./locationchanger.conf.sample ./locationchanger.conf

Here’s my example of it:

   Home "my awesome home net"
   Work "boring Work Wifi"
  1. Run ./install.sh

That’s it. Now every time you connect to configured WiFi network, script will change you location and apply according network settings.

comments powered by Disqus