2

I'm trying to change the default DNS server on my macos laptop. What I have:

% scutil --dns

DNS configuration

resolver #1
  search domain[0] : example.com
  nameserver[0] : aa.bb.cc.dd.ee
  flags    : Request A records
  reach    : 0x00000002 (Reachable)
  order    : 50000

resolver #2
  domain   : local
  options  : mdns
  timeout  : 5
  flags    : Request A records
  reach    : 0x00000000 (Not Reachable)
  order    : 300000

... <CUT> ...

DNS configuration (for scoped queries)

resolver #1
  search domain[0] : lan
  nameserver[0] : 192.168.1.1
  if_index : 6 (en0)
  flags    : Scoped, Request A records
  reach    : 0x00020002 (Reachable,Directly Reachable Address)

The goal is to replace default/global/primary (how does it called properly?) resolver #1: search domain[0] : example.com and nameserver[0] : aa.bb.cc.dd.ee with anything else, for example 8.8.8.8.

What has been done so far:

  • editing /etc/resolv.conf, obviously didn't help much, except maybe for ping and nslookup.
  • tried https://superuser.com/a/86188/927968 solution, which has no visible effect. At least, scutil --dns didn't show any change
  • tried https://superuser.com/a/86245/927968, but this nicely changes DNS configuration (for scoped queries) not the upper main/global/primary section.

So, I stuck. Could you please, explain, what I do wrong and how to achieve the goal.

  • If the [standard method](https://www.macinstruct.com/tutorials/how-to-change-your-macs-dns-servers/) doesn't work for you, please add a screenshot of the DNS tab. – harrymc Oct 28 '22 at 19:55
  • @harrymc, I was seeking for the CLI based solution. Anyway, thank you for the suggestion. – Mikhail Zakharov Oct 28 '22 at 21:23

1 Answers1

3

How about

Find the network services with:

$ networksetup -listallnetworkservices

Ethernet
USB 10/100/1000 LAN
Thunderbolt Bridge
Wi-Fi

then for each service

$ sudo networksetup -setdnsservers <networkservice> empty
$ sudo networksetup -setdnsservers <networkservice> 8.8.8.8 9.8.4.4

Flush or Reset DNS Cache

$ sudo killall -HUP mDNSResponder; sleep 2; echo macOS DNS Cache Reset | say
Pat
  • 3,020
  • 17
  • 25
  • Unfortunately no, this doesn't help. It looks like, `-setdnsservers ` changes only `DNS configuration (for scoped queries)` even if iterate over all the services. – Mikhail Zakharov Oct 28 '22 at 19:33
  • The topic closed. Discovered, a VPN client sets the "Global" unchangeable DNS. Thank you all, without the VPN, the solution by @Pat works well. – Mikhail Zakharov Oct 29 '22 at 16:07
  • @DavidPostill Well, thank you for your valuable remark and advise. I have invested some time already, but spent my reputation to the "bounty". I will, raise it for sure, to be able upvoting back again. – Mikhail Zakharov Oct 29 '22 at 16:11