The following commands work on macOS High Sierra, not tested in previous versions
$ scutil --dns | grep 'nameserver\[[0-9]*\]'
$ networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4
$ networksetup -setdnsservers Wi-Fi empty
$ sudo killall -HUP mDNSResponder