How to change DNS servers?

How do I change DNS servers on Arch Linux?

I edited /etc/systemd/resolved.conf file and added the following line:

DNS=8.8.8.8 8.8.4.4

But I still get the DNS servers from my ISP

Fast: Via NetworkManager.
Slow: systemd-resolved - ArchWiki

Are you using a router? If you are, change in the router configuration.

I am.

But then DNS settings will be applied to everyone who connects through the router.

How do I change DNS settings using terminal?

no terminal needed - but nmtui can do that if you want
in the GUI NetworkManager:
change IPv4 settings to automatic, Addresses only
and supply your own DNS servers, separated by nothing but a comma

why would that be a bad thing?
would it be undesirable, somehow?

It would be a bad thing if it’s a DNS that others don’t want to use imo

Is there a way to change DNS settings using terminal? I just like using terminal because I believe it helps me to learn more about the system.

Simple: nmtui
Advanced: nmcli, see man page :wink:

if that is so, maybe …
most “users” just use the default, whatever that is …
If they would want to use a specific one - they could always choose it :wink:

since NetworkManager is the tool that manages your connections
you have limited options to control it via command line
nmtui is one of them
using the graphical UI is another
… or
disable NetworkManager - and use some other tool to manage your network connections
or do it entirely by hand …
it’s not as much fun as it may appear to be - helpful tools are great :wink:

Hmmmm…anyone on my network that doesn’t like it, tough mammaries: disconnect from my network.

I imagine you already found a way to do this, but for posterity and for anyone else who finds this thread looking specifically for a CLI / terminal method to control DNS only to come away without an answer (like I did for use in a script) this is the method I have settled on:

  1. nmcli con to list your connections and pick out the NAME value of the one you want to change DNS settings for
  2. (optional) nmcli conn modify "NAME" ipv4.ignore-auto-dns yes to bypass the default DNS resolvers specified by your router / gateway
  3. (optional) nmcli conn show "NAME" | grep dns before and after the next step is handy to check it’s worked before actually reconnecting to apply the new DNS resolvers, just in case you lose Internet connectivity by applying “wrong” settings and struggle to research a way to fix it
  4. nmcli conn modify "NAME" ipv4.dns "94.140.14.14 94.140.15.15" to set your preferred DNS resolvers
  5. nmcli con down "NAME" followed by nmcli con up "NAME" to reconnect with your specified DNS resolvers

You can use nmcli conn modify "NAME" ipv4.dns "" (empty quotes after ipv4.dns) followed by the down/up commands in step 5 to remove manually set DNS resolvers.

3 Likes

Bumping old threads is discouraged by the forum rules.