16

I know how to change the DNS of my network from GUI Network Manager:

  1. Right click on the network manager icon in the panel and choose "Edit connections..."
  2. Select your connection from the wired or wireless tab, choose "Edit"
  3. Choose IPv4 settings tab
  4. Switch method to "Automatic (DHCP) addresses only"
  5. Enter the DNS you want in the box "Additional DNS servers" and press "Apply"

How do I do exactly the same thing from Terminal?

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
user246185
  • 1,047
  • 4
  • 10
  • 14

1 Answers1

22

nmcli connection show --active to obtain active connection name
nmcli connection edit double tab to list available connections and chose appropriate

   nmcli> remove ipv4.dns  
   nmcli> set ipv4.ignore-auto-dns yes
   nmcli> set ipv4.dns 8.8.8.8 8.8.4.4 (or other dns servers)      
   nmcli> save
   nmcli> quit 

nmcli connection down your_connection_name
nmcli connection up your_connection_name

EdiD
  • 4,327
  • 3
  • 23
  • 40
  • 3
    I think you also have to set `ipv4.ignore-auto-dns: yes` – Thomas Jan 14 '16 at 18:05
  • 1
    Careful with nmcli connection down, if you are on a remote ssh session you can lose connection to the node!! I think is better to call /etc/init.d/network restart – Carlos Verdes Jun 12 '18 at 07:03
  • There's also **nmcli connection modify "Wired connection 1" ipv4.dns "8.8.8.8"** and the default 192.168.1.1 that most people see cant be removed because I'm pretty sure It's seen by *ip route show* –  Nov 27 '18 at 13:37
  • If you care about speed and [privacy](https://www.reddit.com/r/privacy/comments/9to0go/is_cloudflare_11111001_dns_safe/) you might prefer [using 1.1.1.1, 1.0.0.1 (Cloudflare)](https://1.1.1.1/) instead of [Google's one](https://developers.google.com/speed/public-dns/). – Pablo Bianchi Sep 14 '19 at 18:35
  • /etc/init.d/network restart did not work. better yet, just do both commands with && between so it will come right back w/o losing connection. nmcli connection down && nmcli connection up – Dan Sep 11 '20 at 00:00
  • `nmcli connection up ` by itself (no `down`) worked for me in Raspbian 10. – datu-puti Oct 15 '20 at 17:51