What It Does
A real run flushes the DNS cache with dscacheutil and restarts the DNS responder with a hang-up signal to mDNSResponder. It then tells you whether CHECK_HOST, apple.com by default, resolves before and after, along with the DNS servers and the IP address.
Only when you ask, RENEW_DHCP renews the DHCP lease on the interface that carries the default route. That drops the connection for a few seconds. It is skipped for a static IP address or when there is no default route. RESET_LOCATION switches the active network location to Automatic. It never deletes or edits a location, and it does nothing if Automatic is already active or does not exist.
It does not edit VPN, Wi-Fi or proxy settings. Switching to Automatic can put that location's existing settings into effect. It ends in ERROR if the name resolved before and does not now, or if a renewed lease did not return an address. Running it twice flushes twice, because a flush has no state to be already in, so the second run also reports CHANGED.
Before You Run It
- Run it with DRY_RUN=true first to see the steps it would take.
- Do not use RENEW_DHCP over a remote session you cannot lose. The link drops for a few seconds.
- Check what CHECK_HOST should be. If your network blocks apple.com, give a name you do expect to resolve.
- If it ends in ERROR, read the reported cause. Check DNS, DHCP or the active network location as indicated.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DRY_RUN=true to list every change without making any.
- What it changes: Flushes the DNS cache and restarts mDNSResponder; optionally renews the DHCP lease and switches the network location to Automatic.
- Restart: It never restarts the machine.
- Typical run: Under 30 seconds.
- Example answer: "Flushed DNS; apple.com resolves: before no, after yes; renewed DHCP on en0 (192.168.1.20)"
- Tested before listing on macOS 27 (Apple silicon VM) with /bin/bash 3.2, run as root, against its own test cases.
Inputs
Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.
- RENEW_DHCP: Renew the DHCP lease (drops the link briefly). Default false.
- RESET_LOCATION: Switch to the Automatic network location. Default false.
- CHECK_HOST: Name to resolve before and after. Default apple.com.
Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.