How do I change my DNS on the terminal?

EDITED:

I modified my netplan settings but it still does not work.

Ubuntu 20.04

cat /etc/netplan/01-network-manager-all.yaml :

 # Let NetworkManager manage all devices on this system
network: version: 2 renderer: NetworkManager ethernets: wlp2s0: dhcp4: false addresses: [192.168.1.128/24] gateway4: 192.168.1.254 nameservers: addresses: [1.1.1.1, 1.0.0.1]
7

2 Answers

First find your connection name you want to change and note the name of it:

nmcli connection

Then use nmcli to change the DNS settings:

nmcli connection modify <interface name> ipv4.dns "<DNS Server>,<DNS Server>"

Check your interface to ensure that it has been updated correctly:

nmcli connection show <interface name>
  1. From the terminal, open up /etc/netplan/01-network-manager-all.yaml, I prefer to use nano: # nano /etc/netplan/01-network-manager-all.yaml. (The file may be named differently, if 01-network-manager-all.yaml doesn't exist use ls /etc/netplan to see what the filename is.)

  2. Find the part that has nameservers and addresses:

nameservers: addresses: [8.8.8.8, 8.8.4.4]
  1. You can add any number of nameservers there, just separate them with commas.

  2. When you're done making changes, save the file and run # netplan apply.

  3. (Optional) To confirm that your changes were made, run $ systemd-resolve --status | grep 'DNS Servers' -A2. The nameservers you selected should be displayed.

8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like