How to Set Permanent resolv.conf on Ubuntu

The file */etc/resolv.conf* is a file containing the DNS resolver or IP address of the DNS server (nameserver) which functions to translate from domain names to IP addresses.

In Ubuntu 20.04, the default nameserver is 127.0.0.53.

[INPUT]

1 2 3 4 5 6 7 cat /etc/resolv.conf   # 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 # 127.0.0.53 is the systemd-resolved stub resolver. # run “systemd-resolve –status” to see details about the actual nameservers. nameserver 127.0.0.53

For example, if you want to use Cloudflare’s (1.1.1.1) and Google’s (8.8.8.8) DNS servers as primary and secondary nameservers, put the IP address in the first and second lines.

[INPUT]

1 sudo nano /etc/resolv.conf

Update to be like below.

[INPUT]

1 2 3 4 5 6 7 8 # 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 # 127.0.0.53 is the systemd-resolved stub resolver. # run “systemd-resolve –status” to see details about the actual nameservers.   nameserver 1.1.1.1 nameserver 8.8.8.8 nameserver 127.0.0.53

*Problem*

The problem that occurs is the resolv.conf file will change back to how it was after the computer is restarted, which only contains the IP address 127.0.0.53. In the resolv.conf file there is also a comment * DO NOT EDIT THIS FILE BY HAND – YOUR CHANGES WILL BE OVERWRITTEN *, which means don’t change this file manually because the configuration will be overwritten again.

*Solution*

To solve the above problem is to use *resolvconf service*.

Install the resolvconf package.

[INPUT]

1 sudo apt install resolvconf

Then activate and run the resolvconf service.

[INPUT]

1 2 3 sudo systemctl enable resolvconf sudo systemctl start resolvconf sudo systemctl status resolvconf

The results are as below.

[INPUT]

1 2 3 4 5 6 “— resolvconf.service – Nameserver information manager      Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor preset: enabled)      Active: active (exited) since Sun 2020-07-26 18:08:17 WIB; 14h ago        Docs: man:resolvconf(8)     Process: 329 ExecStart=/sbin/resolvconf –enable-updates (code=exited, status=/SUCCESS)    Main PID: 329 (code=exited, status=/SUCCESS)

Then enter the nameserver IP address in the *head* resolvconf configuration file.

[INPUT]

1 sudo nano /etc/resolvconf/resolv.conf.d/head

Enter the nameservers under the comments.

[INPUT]

1 2 nameserver 1.1.1.1 nameserver 8.8.8.8

Then run the resolv.conf update.

[INPUT]

1 2 sudo resolvconf –enable-updates sudo resolvconf -u

Verify by displaying the contents of the resolv.conf file.

[INPUT]

1 2 3 4 5 6 7 8 9 10 cat /etc/resolv.conf   # 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 # 127.0.0.53 is the systemd-resolved stub resolver. # run “systemd-resolve –status” to see details about the actual nameservers.   nameserver 1.1.1.1 nameserver 8.8.8.8 nameserver 127.0.0.53

If you want to change or add other nameserver IP addresses, change the *head* file again, and run the resolvconf update.

[INPUT]

1 sudo resolvconf -u

Good luck 🙂

Leave a Reply

Your email address will not be published.