DNS switch script

Work environment for a change dns, and have to change back home, in the mac environment, every time you need to manually open network preferences to modify, very cumbersome, therefore wrote a script, you can switch operation mode and non-operation mode .

Script dnsexchange.sh:

#!/bin/bash
read -p "switch to working mode? y/n: " val
echo 'this option is '$val
if [ $val == 'y' ]
then
        networksetup -setdnsservers Wi-Fi 192.168.10.111
        dscacheutil -flushcache
elif [ $val == 'n' ]
then
        networksetup -setdnsservers Wi-Fi empty
        dscacheutil -flushcache
else
        echo "please input right option!"
fi

Finally, add to the script executable permissions: chmod + x dnsexchange.sh

Guess you like

Origin www.cnblogs.com/mojiruo/p/11334415.html