Jump to content

Flush DNS 10.6 -> 12.0


Recommended Posts

A simple command to Flush DNS cache. Compatible with 10.6 through to 12.0. Takes no arguments but asks for system password to run the task as an admin user.

 

Available on packal.org

 

Any issues, please let me know.

 

Update 04/08/2021: Added support for macOS Monterey 12.0. Commands remain the same based on early Betas.

Update 12/12/2020: Bug Fix

Update 06/12/2020: Support for macOS Big Sur 11.0 - Re-written code. Also allowed future to use the current command if it remains valid without future release 

Update 22/12/2019: Support for macOS Catalina 10.15

Update 20/1/2019: Support for macOS Mojave 10.14

Update 20/4/2018: Updated icon

Update 24/1/2018: Support for macOS High Sierra 10.13

Update 12/1/2017: Support for macOS Sierra 10.12

 

Screen Shot 2018-04-20 at 09.47.01.png1201939741_Screenshot2019-01-20at16_45_01.thumb.png.1f16b9cc7f0a574714923cbb780f29ef.png

 

Edited by harvey
Update 04/08/2021: Added support for macOS Monterey 12.0. Commands remain the same based on early Betas.
Link to comment
  • 2 weeks later...
  • 2 weeks later...
  • 11 months later...

Hi, I updated the script for Mac OS High Sierra and just added these lines of code:

elif [ ${array[1]} -eq 13 ]; then
     echo "Version ${ver} is macOS High Sierra"
     osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'

The final script is:

#!/bin/bash

# ver="10.11.1"
ver=`sw_vers -productVersion`

IFS='.' read -r -a array <<< "$ver"

# echo ${array[0]}
# echo ${array[1]}
# echo ${array[2]}

# if [ -z ${array[2]} ];then
#     echo "You have not installed any sub update"
# fi

if [ ${array[1]} -eq 6 ]; then
    echo "Version ${ver} is Snow Leopard"
    osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges'
elif [ ${array[1]} -eq 7 ] || [ ${array[1]} -eq 8 ] || [ ${array[1]} -eq 9 ]; then
    echo "Version ${ver} is one of the following: Lion, Mountain Lion or Mavericks"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then
    echo "Version ${ver} is Yosemite and 10.10.3 or less"
    osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges'
elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then
    echo "Version ${ver} is Yosemite and 10.10.4 or higher"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 11 ]; then
    echo "Version ${ver} is El Capitan"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 12 ]; then
     echo "Version ${ver} is macOS Sierra"
     osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 13 ]; then
     echo "Version ${ver} is macOS High Sierra"
     osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
else
    echo "Version ${ver} is Unknown"
    exit 1
fi
Link to comment
  • 2 months later...
  • 3 weeks later...
On 02/04/2018 at 3:24 AM, xilopaint said:

The color of the icon doesn't suit well in Alfred dark themes. Please, consider to change the icon's color to suit both light and dark themes or add an option to change the icon according the theme.

 

I'm not much of a designer. If your able to provide an icon I'm happy to consider it.

Link to comment
  • 8 months later...

Hi,

for macOS Mojave (10.14.x) 

 

#!/bin/bash

ver=`sw_vers -productVersion`

IFS='.' read -r -a array <<< "$ver"

if [ ${array[1]} -eq 6 ]; then
    echo "Version ${ver} is Snow Leopard"
    osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges'
elif [ ${array[1]} -eq 7 ] || [ ${array[1]} -eq 8 ] || [ ${array[1]} -eq 9 ]; then
    echo "Version ${ver} is one of the following: Lion, Mountain Lion or Mavericks"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then
    echo "Version ${ver} is Yosemite and 10.10.3 or less"
    osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges'
elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then
    echo "Version ${ver} is Yosemite and 10.10.4 or higher"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 11 ]; then
    echo "Version ${ver} is El Capitan"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 12 ]; then
     echo "Version ${ver} is macOS Sierra"
     osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 13 ]; then
     echo "Version ${ver} is macOS High Sierra"
     osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -eq 14 ]; then
     echo "Version ${ver} is macOS Mojave"
     osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
else
    echo "Version ${ver} is Unknown"
    exit 1
fi

 

Link to comment

 

Thanks @bigorno. I have updated logic to support 10.14 Mojave. New version is on Packal. Used a slightly better method:-

 

#!/bin/bash

ver=`sw_vers -productVersion`

IFS='.' read -r -a array <<< "$ver"

if [ ${array[1]} -eq 6 ]; then
    echo "Version ${ver} is Snow Leopard"
    osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges'
elif [ ${array[1]} -ge 7 -a ${array[1]} -le 9 ]; then
    echo "Version ${ver} is Lion, Mountain Lion or Mavericks"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then
    echo "Version ${ver} is Yosemite and 10.10.3 or less"
    osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges'
elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then
    echo "Version ${ver} is Yosemite and 10.10.4 or higher"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -ge 11 -a ${array[1]} -le 14 ]; then
    echo "Version ${ver} is El Capitan, Sierra, High Sierra or Mojave"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
else
    echo "Version ${ver} is Unknown"
    exit 1
fi

 

Link to comment
  • 11 months later...

Added Catalina (simple as 123 thanks to @harvey! )

 

#!/bin/bash

ver=`sw_vers -productVersion`

IFS='.' read -r -a array <<< "$ver"

if [ ${array[1]} -eq 6 ]; then
    echo "Version ${ver} is Snow Leopard"
    osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges'
elif [ ${array[1]} -ge 7 -a ${array[1]} -le 9 ]; then
    echo "Version ${ver} is Lion, Mountain Lion or Mavericks"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then
    echo "Version ${ver} is Yosemite and 10.10.3 or less"
    osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges'
elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then
    echo "Version ${ver} is Yosemite and 10.10.4 or higher"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -ge 11 -a ${array[1]} -le 14 ]; then
    echo "Version ${ver} is El Capitan, Sierra, High Sierra or Mojave"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -ge 14 -a ${array[1]} -le 15 ]; then
    echo "Version ${ver} is Catalina"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
else
    echo "Version ${ver} is Unknown"
    exit 1
fi

 

Link to comment
2 hours ago, Pierpaolo said:

Added Catalina (simple as 123 thanks to @harvey! )

 


#!/bin/bash

ver=`sw_vers -productVersion`

IFS='.' read -r -a array <<< "$ver"

if [ ${array[1]} -eq 6 ]; then
    echo "Version ${ver} is Snow Leopard"
    osascript -e 'do shell script "sudo dscacheutil -flushcache" with administrator privileges'
elif [ ${array[1]} -ge 7 -a ${array[1]} -le 9 ]; then
    echo "Version ${ver} is Lion, Mountain Lion or Mavericks"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif ([ ${array[1]} -eq 10 ] && [ -z ${array[2]} ]) || ([ ${array[1]} -eq 10 ] && [ ${array[2]} -le 3 ]); then
    echo "Version ${ver} is Yosemite and 10.10.3 or less"
    osascript -e 'do shell script "sudo discoveryutil mdnsflushcache" with administrator privileges'
elif [ ${array[1]} -eq 10 ] && [ ${array[2]} -ge 4 ]; then
    echo "Version ${ver} is Yosemite and 10.10.4 or higher"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -ge 11 -a ${array[1]} -le 14 ]; then
    echo "Version ${ver} is El Capitan, Sierra, High Sierra or Mojave"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
elif [ ${array[1]} -ge 14 -a ${array[1]} -le 15 ]; then
    echo "Version ${ver} is Catalina"
    osascript -e 'do shell script "sudo killall -HUP mDNSResponder" with administrator privileges'
else
    echo "Version ${ver} is Unknown"
    exit 1
fi

 

 

Thanks @Pierpaolo for the reminder. I have updated the logic to support 10.15. New version is on Packal.

Link to comment
  • 11 months later...
  • harvey changed the title to Flush DNS 10.6 -> 11.0
On 12/4/2020 at 9:58 PM, Samplex said:

@harveyAny update for Big Sur?

 

I have released a new version. The code has been completely re-written so please let me know if there are any issues.

 

I have also added logic to support 11.1+ so if the current command does not change, it should to continue to work without requiring an update.

 

Please ensure you use v2.0.1 

 

Updated link is https://www.packal.org/workflow/flush-dns-106-110

Edited by harvey
Added Link
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...