Software & AppsOperating SystemLinux

How To Save /etc/resolv.conf Configuration Permanently on Ubuntu

Ubuntu 19

In this article, we will discuss how to permanently save the /etc/resolv.conf configuration on Ubuntu. This file is crucial for DNS resolution, which is the process of converting domain names into IP addresses. However, on modern systems, this file is dynamically generated and not intended to be edited directly. Instead, we will need to modify the configuration file that generates it.

Quick Answer

To save the /etc/resolv.conf configuration permanently on Ubuntu, you need to edit the /etc/systemd/resolved.conf file. This is the configuration file for the systemd-resolved service, which generates the /etc/resolv.conf file. After making your desired changes, save the file and restart the systemd-resolved service for the changes to take effect.

Understanding /etc/resolv.conf

The /etc/resolv.conf file contains information that allows a computer to convert alpha-numeric domain names into the numeric IP addresses. This file is dynamically generated by the systemd-resolved service in Ubuntu.

If you open the /etc/resolv.conf file, you may see a comment at the top that reads # This file is managed by man:systemd-resolved(8). Do not edit. This means that any changes you make to this file will be overwritten the next time the systemd-resolved service restarts.

Editing the Correct File

To make permanent changes to your DNS configuration, you need to edit the /etc/systemd/resolved.conf file. This is the configuration file for the systemd-resolved service, which generates the /etc/resolv.conf file.

To edit this file, you can use any text editor of your choice. For example, to open the file with the nano text editor, you would use the following command:

sudo nano /etc/systemd/resolved.conf

In the resolved.conf file, you can specify your DNS servers and other related settings. For more information about the syntax and available options, refer to the man page with the command man resolved.conf.

Making Changes

After opening the resolved.conf file, you can make your desired changes. For example, to set Google’s DNS servers as your primary DNS servers, you would add the following lines:

DNS=8.8.8.8 8.8.4.4
FallbackDNS=8.8.8.8 8.8.4.4

The DNS parameter sets the primary DNS servers, and the FallbackDNS parameter sets the backup DNS servers to be used if the primary servers are unavailable.

Saving and Applying Changes

Once you have made your changes, save the file and exit the text editor. If you are using nano, you can do this by pressing Ctrl + X, then Y to confirm that you want to save the changes, and then Enter to confirm the file name.

After saving the file, you need to restart the systemd-resolved service for the changes to take effect. You can do this with the following command:

sudo systemctl restart systemd-resolved

Verifying the Changes

After restarting the systemd-resolved service, you can verify that the /etc/resolv.conf file has been updated with your new configuration. To do this, use the cat command to display the contents of the file:

cat /etc/resolv.conf

You should see your new DNS servers listed in the output.

Conclusion

In this article, we have explained how to make permanent changes to the /etc/resolv.conf file on Ubuntu. By editing the /etc/systemd/resolved.conf file and restarting the systemd-resolved service, you can ensure that your DNS configuration is preserved across system reboots.

What is the purpose of the `/etc/resolv.conf` file?

The /etc/resolv.conf file is used for DNS resolution, which is the process of converting domain names into IP addresses.

Why can’t I edit the `/etc/resolv.conf` file directly?

The /etc/resolv.conf file is dynamically generated by the systemd-resolved service in Ubuntu, and any changes made to it will be overwritten the next time the service restarts.

Which file should I edit to make permanent changes to my DNS configuration?

To make permanent changes to your DNS configuration, you need to edit the /etc/systemd/resolved.conf file.

How can I open the `/etc/systemd/resolved.conf` file for editing?

You can use any text editor of your choice to open the /etc/systemd/resolved.conf file. For example, you can use the nano text editor with the command sudo nano /etc/systemd/resolved.conf.

What are some examples of changes I can make in the `resolved.conf` file?

In the resolved.conf file, you can specify your DNS servers and other related settings. For example, you can set primary and fallback DNS servers by using the DNS and FallbackDNS parameters respectively.

How can I save and apply my changes in the `resolved.conf` file?

After making your changes, save the resolved.conf file and exit the text editor. Then, restart the systemd-resolved service with the command sudo systemctl restart systemd-resolved to apply the changes.

How can I verify if my changes in the `resolved.conf` file have been applied?

After restarting the systemd-resolved service, you can use the cat command to display the contents of the /etc/resolv.conf file and verify that your new DNS configuration has been updated.

Will my DNS configuration changes be preserved across system reboots?

Yes, by editing the /etc/systemd/resolved.conf file and restarting the systemd-resolved service, your DNS configuration changes will be preserved across system reboots.

Leave a Comment

Your email address will not be published. Required fields are marked *