How to change DNS in resolv.conf file on Ubuntu


On Ubuntu, to change DNS we must change file /etc/resolv.conf but it will be overwritten after the system reboots. To resolve this problem, we must install the resolvconf package by using these steps below

Step 1

sudo apt-get install resolvconf

Output:

root@tutorialspots:~# sudo apt-get install resolvconf
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  resolvconf
0 upgraded, 1 newly installed, 0 to remove and 42 not upgraded.
Need to get 53.5 kB of archives.
After this operation, 243 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ precise-updates/main resolvconf all 1.63
ubuntu16 [53.5 kB]
Fetched 53.5 kB in 0s (334 kB/s)
Preconfiguring packages ...
Selecting previously unselected package resolvconf.
(Reading database ... 23468 files and directories currently installed.)
Unpacking resolvconf (from .../resolvconf_1.63ubuntu16_all.deb) ...
Processing triggers for man-db ...
Setting up resolvconf (1.63ubuntu16) ...
resolvconf start/running
Processing triggers for resolvconf ...

Step 2:
Now, we change the /etc/resolvconf/resolv.conf.d/base file, instead of /etc/resolv.conf file

vi /etc/resolvconf/resolv.conf.d/base

Add your owner DNS like:

nameserver 2001:4860:4860::8844
nameserver 2001:4860:4860::8888

Step 3: restart system

Done! the /etc/resolv.conf file will be automatically changed.

We can test by using the command:

cat /etc/resolv.conf

Output:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 2001:4860:4860::8844
nameserver 2001:4860:4860::8888


nameserver 208.67.222.222
nameserver 208.67.220.220

Related Post

No comments yet.

Leave a Reply