linux change dns server code example

Example 1: change dns linux

sudo vim /etc/resolvconf/resolv.conf.d/base

# add nameserver(s) like this.
nameserver 8.8.8.8
nameserver 8.8.4.4

$ sudo resolvconf -u

Example 2: resolvconf set dns

sudo systemctl disable systemd-resolved.service
sudo gedit /etc/resolvconf/resolv.conf.d/head 
# add
nameserver 8.8.8.8
nameserver 8.8.4.4

sudo resolvconf --enable-updates
sudo resolvconf -u

Example 3: change dns resolver linux

$ sudo vim /etc/resolvconf/resolv.conf.d/base

Example 4: resolvconf set dns

$ sudo apt update
$ sudo apt install resolvconf