Skip to content

Instantly share code, notes, and snippets.

@anry200
Created March 30, 2021 12:45
Show Gist options
  • Save anry200/1566223d1f1e179369a73d4c2affff86 to your computer and use it in GitHub Desktop.
Save anry200/1566223d1f1e179369a73d4c2affff86 to your computer and use it in GitHub Desktop.
DNS on Mac override workaround to fix dns issues with InfoBlox

How to Set DNS Servers from the Command Line of macOS with networksetup

For example, to set a Mac with wi-fi to Google DNS of 8.8.8.8 the syntax would be:

networksetup -setdnsservers Wi-Fi 8.8.8.8

You can set multiple DNS servers if desired,

networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4

How to Clear All DNS Servers with networksetup

networksetup -setdnsservers Wi-Fi Empty

Checking DNS Settings with networksetup

networksetup -getdnsservers Wi-Fi

InfoBlox DNS issue fix

Workaround is to set DNS every second

#!/bin/bash

while true; do
  networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4
  sleep 1;
done
#!/bin/bash
while true; do
networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4
sleep 1;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment