{"id":1995,"date":"2023-11-08T15:50:00","date_gmt":"2023-11-08T10:20:00","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=1995"},"modified":"2025-02-17T10:57:41","modified_gmt":"2025-02-17T05:27:41","slug":"how-to-change-dns-server-permanently-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-change-dns-server-permanently-on-ubuntu-20-04\/","title":{"rendered":"How to change DNS server permanently on Ubuntu 20.04?"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design.png\" target=\"_blank\" rel=\"noopener\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"508\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design-1024x508.png\" alt=\"change dns server permanently \" class=\"wp-image-2351\" style=\"width:545px;height:auto\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design-1024x508.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design-300x149.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design-768x381.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design-1536x761.png 1536w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Untitled-design.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>In <a href=\"https:\/\/ubuntu.com\/download\/server\" target=\"_blank\" rel=\"noopener\">Ubuntu 20.04<\/a>, I encountered a common issue with DNS server resolution management. The system component responsible for this, <a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/latest\/systemd-resolved.service.html\" target=\"_blank\" rel=\"noopener\">systemd-resolved<\/a>, dynamically updates the \/etc\/resolv.conf file based on its own configuration, often leading to changes appearing temporary and reverting to systemd-resolved settings. In this article, I will share how I resolved this issue and also  explore the other different methods that can use to effectively manage DNS resolution on Ubuntu 20.04 system.<\/p>\n\n\n\n<p>In this article we will discuss about :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#systemd-resolved\">Understanding  systemd-resolved<\/a><\/li>\n\n\n\n<li><a href=\"#issues\">The Common Issue I encountered<\/a><\/li>\n\n\n\n<li><a href=\"#methods\">5 different methods to change DNS server permanently&nbsp;<\/a><\/li>\n<\/ul>\n\n\n\n<p>             <a href=\"#editing\">a. Editing resolved.conf<\/a><\/p>\n\n\n\n<p>             <a href=\"#resolved.conf\">b. Creating a Custom resolv.conf<\/a><\/p>\n\n\n\n<p>           <a href=\"#locking\">  c. Locking the \/etc\/resolv.conf File<\/a><\/p>\n\n\n\n<p>        <a href=\"#disabling\">    d. Disabling systemd-resolved<\/a><\/p>\n\n\n\n<p>          <a href=\"#utility\">  e. Using &#8220;resolvconf&#8221; utility<\/a><\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"systemd-resolved\"><strong>     Understanding systemd-resolved<\/strong><\/h3>\n\n\n<p>As I started to delve into the issue further, I quickly realized that systemd-resolved is the core component responsible for managing DNS resolution on my Ubuntu 20.04 system. Notably it dynamically updates the \/etc\/resolv.conf file. Consequently the changes I made to appear temporary and subject to reversion.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"issues\">    <strong>The Common Issues I Encountered<\/strong> with DNS server<\/h3>\n\n\n<p>The issue I encountered was that changes I made to the \/etc\/resolv.conf file often seemed to be short-lived. If DNS changes revert to their previous settings shortly after being modified, it can disrupt services that rely on the updated DNS configuration.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"methods\">    Different methods to change DNS server permanently <\/h3>\n\n<h4 class=\"wp-block-heading\" id=\"1-editing-resolvedconf\">1. Editing resolved.conf<\/h4>\n\n\n<p id=\"editing\">Editing \/etc\/systemd\/resolved.conf is a way to configure DNS settings managed by systemd-resolved, which is a system service on Linux that provides network name resolution to local applications. By editing this configuration file, you can customize how DNS resolution works on your system.&nbsp;<\/p>\n\n\n\n<p>Using any text editor, edit the configuration file resolved.conf and add the required DNS server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@ervintest:~# nano \/etc\/systemd\/resolved.conf\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-08-121128.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"954\" height=\"448\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-08-121128.png\" alt=\"resolved.conf\n\" class=\"wp-image-1998\" style=\"aspect-ratio:2.1294642857142856;width:538px;height:auto\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-08-121128.png 954w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-08-121128-300x141.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-08-121128-768x361.png 768w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><\/figure>\n\n\n<h4 class=\"wp-block-heading\" id=\"2creating-a-custom-resolvconf\">2.Creating a Custom resolv.conf<\/h4>\n\n\n<p id=\"resolved.conf\">To maintain control over your DNS configurations and prevent systemd-resolved from overwriting them, you can create your own custom resolv.conf file. This custom file will contain the DNS settings you want to use. Instead of directly editing or replacing the \/etc\/resolv.conf file (which systemd-resolved might overwrite), you create a symbolic link from \/etc\/resolv.conf to your custom resolv.conf file. This link effectively redirects any DNS-related queries from the system to your custom file.&nbsp;<\/p>\n\n\n\n<p>When applications or processes on your system request DNS resolution, they typically read the \/etc\/resolv.conf file. By creating a symbolic link, you&#8217;re ensuring that they read your custom resolv.conf file instead. This approach allows you to maintain your custom DNS configurations without worrying about them being overwritten by system updates or changes made by systemd-resolved.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@ervintest:~# ln -sf \/etc\/resolv.custom.conf \/etc\/resolv.conf\nroot@ervintest:~# nano \/etc\/resolv.custom.conf\n<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\" id=\"3-locking-the-etcresolvconf-file\">3. Locking the \/etc\/resolv.conf File<\/h4>\n\n\n<p id=\"locking\">Using the chattr command, you can lock the \/etc\/resolv.conf file to prevent further modifications:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@ervintest:~# chattr +i \/etc\/resolv.conf<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\" id=\"4-disabling-systemdresolved\">4. Disabling systemd-resolved<\/h4>\n\n\n<p id=\"disabling\">When manual DNS management is preferred, systemd-resolved can be disabled using the following commands.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@ervintest:~# systemctl stop systemd-resolved\nroot@ervintest:~# systemctl disable systemd-resolved\n<\/code><\/pre>\n\n\n<h4 class=\"wp-block-heading\" id=\"5-using-resolvconf-utility\">5. Using &#8220;resolvconf&#8221; utility<\/h4>\n\n\n<p id=\"utility\">To manage DNS configurations and prevent them from being disordered by various programs, additionally you can use the &#8220;resolvconf&#8221; utility. Resolvconf is a tool commonly used on Debian and Ubuntu-based systems to manage the \/etc\/resolv.conf file and moreover ensure that DNS settings are consistent and controlled.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@ervintest:~# apt-get install resolvconf\n<\/code><\/pre>\n\n\n\n<p>You can configure DNS settings by editing the \/etc\/resolvconf\/resolv.conf.d\/base file or creating separate files in the \/etc\/resolvconf\/resolv.conf.d\/ directory.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> root@ervintest:~# nano \/etc\/resolvconf\/resolv.conf.d\/base\n<\/code><\/pre>\n\n\n\n<p>In the file, specify the DNS server IP addresses you want to use, one per line. For example, to use Google&#8217;s public DNS servers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nameserver 8.8.8.8\nnameserver 8.8.4.4\n<\/code><\/pre>\n\n\n\n<p>After configuring the DNS settings, you need to update Resolvconf to apply the changes. Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@ervintest:~# resolvconf -u\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>By using any of these methods we can achieve stable and customized DNS configurations tailored for our specific needs. To upgrade Upgrade Ubuntu to the Latest Version, visit <a href=\"https:\/\/www.veeble.org\/kb\/upgrade-ubuntu-latest-version\/\" target=\"_blank\" rel=\"noopener\">this<\/a>. <\/p>\n<\/blockquote>\n\n\n\n<div style=\"height:40px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-7a7d52d9 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Powering Your Business with Windows VPS<\/h3><p class=\"uagb-cta__desc\">Choose a robust and reliable platform for your critical applications. Experience the difference a high-performance VPS can make.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/vps-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">View Our Plans<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Ubuntu 20.04, I encountered a common issue with DNS server resolution management. The system component responsible for this, systemd-resolved, dynamically updates the \/etc\/resolv.conf [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1995","post","type-post","status-publish","format-standard","hentry","category-linux"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Nayana Nair","author_link":"https:\/\/www.veeble.com\/kb\/author\/nayana\/"},"uagb_comment_info":0,"uagb_excerpt":"In Ubuntu 20.04, I encountered a common issue with DNS server resolution management. The system component responsible for this, systemd-resolved, dynamically updates the \/etc\/resolv.conf [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=1995"}],"version-history":[{"count":11,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1995\/revisions"}],"predecessor-version":[{"id":7202,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1995\/revisions\/7202"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=1995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=1995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=1995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}