How to Change DNS of network from Terminal?
23,537
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
Related videos on Youtube
Author by
user246185
Updated on September 18, 2022Comments
-
user246185 over 1 year
I know how to change the DNS of my network from GUI Network Manager:
- Right click on the network manager icon in the panel and choose "Edit connections..."
- Select your connection from the wired or wireless tab, choose "Edit"
- Choose IPv4 settings tab
- Switch method to "Automatic (DHCP) addresses only"
- 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 over 4 yearsThe (current) TUI Network Manager alternative is called
nmtui
.
-
Thomas over 8 yearsI think you also have to set
ipv4.ignore-auto-dns: yes
-
Carlos Verdes almost 6 yearsCareful 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
-
Admin over 5 yearsThere'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
-
Pablo Bianchi over 4 yearsIf you care about speed and privacy you might prefer using 1.1.1.1, 1.0.0.1 (Cloudflare) instead of Google's one.
-
Dan over 3 years/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
-
anscmc over 3 years
nmcli connection up <your_connection_name>
by itself (nodown
) worked for me in Raspbian 10.