Ubuntu – How to change the DNS on the terminal

dns

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]

Best Answer

    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.

  • Related Question