System Settings shows one list of DNS servers per network. macOS itself keeps several resolvers, some tied to a domain or an interface, and Terminal can show all of them.
The command is built into macOS:
scutil --dns
Its description reads: reports the current DNS configuration. The output is a numbered list of resolvers. Each block has the name servers, the search domains, the network interface it belongs to and an order. A VPN or a split DNS setup adds resolvers that apply only to certain domains.
That is my first stop when a name resolves in the browser but not in a script, or the other way around. Apps ask the system, and the system picks a resolver by domain. A tool like dig talks to one server directly and skips that choice, so the two can disagree.
The long output is easier to read in pieces. To see only the name servers:
scutil --dns | grep nameserver
The caveat is the length. On a Mac with a VPN client installed the output can run to dozens of lines, so pipe it through less or grep.
Further reading: scutil on ss64