I was surprised how easy is to edit DNS Settings using the macOS Terminal. I also noticed using the GUI in the mac sometimes doesn’t ‘keep’ the settings for some reason. After I visited one of my favorite local beer breweries in Brooklyn one of my clients contacted me.
The issue was setting up a local DNS for all the macOS clients at their office. All the clients mac computers were joined to AD and were loosing their network shared connection. Usually when you join a mac to Active Directory it auto-mounts the user’s network drive.
I found the issue was a bad DNS configuration. So, I remote to the clients office and ran the following Terminal commands:
Edit DNS Settings using our friend the Terminal
To identify the current network devices/services:
networksetup -listallnetworkservicesYou should see an output:
Ethernet
Thunderbolt Bridge
Wi-FiIn this case, we wanted to check the DNS for Ethernet:
networksetup -getdnsservers "Ethernet"If none are set, you will see:
There aren't any DNS Servers set on Ethernet.Oh oh! This was the issue for this client. So, I fixed it running:
sudo networksetup -setdnsservers "Ethernet" 172.16.100.2 172.16.100.3Run again to verify:
networksetup -getdnsservers "Ethernet"You should see the newly DNS servers set:
172.16.100.2
172.16.100.3If you need to do this for Wi-Fi, just replace Ethernet with Wi-Fi:
sudo networksetup -setdnsservers "Wi-Fi" 172.16.100.2 172.16.100.3In case you need to revert and set DNS to DHCP: (automatically assigned DNS)
sudo networksetup -setdnsservers "Ethernet" "Empty"or
sudo networksetup -setdnsservers "Ethernet" "DHCP"You may need to flush the cache:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderThat’s all! To Edit DNS Settings using the Terminal in macOS is simple. If you have any questions contact me. Also, if you like to support me consider shopping one of my designs:





