Skip to content

Instantly share code, notes, and snippets.

@finscn
Last active July 31, 2019 18:54
Show Gist options
  • Save finscn/61aab0cabe2599b8bf28 to your computer and use it in GitHub Desktop.
Save finscn/61aab0cabe2599b8bf28 to your computer and use it in GitHub Desktop.
dns setter
#!/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 127.0.0.1;;
2)
# ali DNS
networksetup -setdnsservers ${SERVICE} 223.5.5.5 223.6.6.6 127.0.0.1;;
3)
# openDNS
networksetup -setdnsservers ${SERVICE} 208.67.222.222 208.67.220.220 208.67.222.220 208.67.220.222 127.0.0.1;;
4)
# v2ex
networksetup -setdnsservers ${SERVICE} 199.91.73.222 178.79.131.110 127.0.0.1;;
5)
# 114
networksetup -setdnsservers ${SERVICE} 114.114.114.114 114.114.115.115 127.0.0.1;;
*)
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