Skip to content

Instantly share code, notes, and snippets.

@rhybroy
Forked from finscn/dns-setter.sh
Last active August 29, 2015 14:22
Show Gist options
  • Save rhybroy/48e03ca39e1f4645aec4 to your computer and use it in GitHub Desktop.
Save rhybroy/48e03ca39e1f4645aec4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Please run this shell with "sudo ..."
SERVICE=Wi-Fi
# You could change the service. List all network services via:
# networksetup -listallnetworkservices
echo ""
echo "Current DNS on ${SERVICE}:"
networksetup -getdnsservers ${SERVICE}
echo "======================"
echo "0 . Default (Empty)"
echo "1 . google DNS"
echo "2 . ali DNS"
echo "3 . openDNS"
echo "4 . v2ex"
echo "5 . 114"
echo "Choose new DNS on ${SERVICE} :"
read newDNS
case $newDNS in
0)
# default
networksetup -setdnsservers ${SERVICE} Empty;;
1)
# google DNS
networksetup -setdnsservers ${SERVICE} 8.8.8.8 8.8.4.4;;
2)
# ali DNS
networksetup -setdnsservers ${SERVICE} 223.5.5.5 223.6.6.6;;
3)
# openDNS
networksetup -setdnsservers ${SERVICE} 208.67.222.222 208.67.220.220 208.67.222.220 208.67.220.222;;
4)
# v2ex
networksetup -setdnsservers ${SERVICE} 199.91.73.222 178.79.131.110;;
5)
# 114
networksetup -setdnsservers ${SERVICE} 114.114.114.114 114.114.115.115;;
*)
echo " do nothing... ";;
esac
echo "======================"
echo "Current DNS on ${SERVICE}:"
networksetup -getdnsservers ${SERVICE}
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment