Changing DNS in System Settings means a lot of clicking. networksetup does it in two commands.
First find the name of the network service. Then set its servers.
networksetup -listallnetworkservices
networksetup -getdnsservers Wi-Fi
sudo networksetup -setdnsservers Wi-Fi 9.9.9.9 149.112.112.112
The syntax is -setdnsservers networkservice dns1 [dns2] [...]. To go back to whatever the network hands out, put the word empty in place of the server addresses.
sudo networksetup -setdnsservers Wi-Fi empty
The man page says the command needs at least admin privileges to change network settings, so expect to use sudo.
The caveat is the service name. It has to match exactly, quotes included when it has spaces, and your Wi-Fi may not be called Wi-Fi. List the services first. Also remember a manual DNS setting stays when you switch to another network, which is exactly the thing people forget about a year later.
The reason to prefer the terminal here is repeatability. If you switch between a home and a work setup, a two line script beats remembering which pane in System Settings hides the DNS field. Keep the command in a note, with the reset line right below it.
Further reading: networksetup.8 man page, On this site: dig @server name tells you which DNS server is lying to you, On this site: tailscale dns status shows what MagicDNS is really doing