{"id":8263,"date":"2021-03-25T00:12:41","date_gmt":"2021-03-24T21:12:41","guid":{"rendered":"https:\/\/kifarunix.com\/?p=8263"},"modified":"2024-03-19T18:29:05","modified_gmt":"2024-03-19T15:29:05","slug":"make-permanent-dns-changes-on-resolv-conf-in-linux","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/make-permanent-dns-changes-on-resolv-conf-in-linux\/","title":{"rendered":"Make Permanent DNS Changes on resolv.conf in Linux"},"content":{"rendered":"\n<p>Follow through this guide to learn how to make DNS permanent changes on resolv.conf in Linux.<\/p>\n\n\n\n<p>According to man <code><strong>resolv.conf<\/strong><\/code>, <em>resolv.conf is a resolver configuration file.  The resolver is a set of routines in the C library that provide access to the Internet Domain Name System (DNS). The resolver configuration file contains information that is read by the resolver routines the first time they are invoked by a process. The file is designed to be human readable and contains a list of keywords with values that provide various types of resolver information. The configuration file is considered a trusted source of DNS information (e.g., DNSSEC AD-bit information will be returned unmodified from this source)<\/em>.<\/p>\n\n\n\n<p><em>If this file does not exist, only the name server on the local machine will be queried, and the search list contains the local domain name determined from the hostname<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Use resolv.conf to Make Permanent DNS Changes in Linux<\/h2>\n\n\n\n<p>Any changes made manually to the <strong><code>\/etc\/resolv.conf<\/code><\/strong> configuration file are bound to be overwritten upon changes in the network or system reboot.<\/p>\n\n\n\n<p>According to the comments made in the file, the file is dynamic. &#8220;<strong>DO NOT EDIT THIS FILE BY HAND &#8212; YOUR CHANGES WILL BE OVERWRITTEN<\/strong>&#8220;.<\/p>\n\n\n\n<p>So take for example, if you want to add a DNS server on your Linux box, you would usually update this file by specifying the IP address of a name server that the resolver should query. See the command below,<code><strong> which updates the resolv.conf file with the public primary DNS server for Google DNS<\/strong><\/code>, by running a command like;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"nameserver 8.8.8.8\" &gt; \/etc\/resolv.conf<\/code><\/pre>\n\n\n\n<p>If you make any changes, like a system reboot, or run the <code><strong>dhclient<\/strong><\/code> command the line added above, will disappear.<\/p>\n\n\n\n<p>So how do you make permanent DNS changes using resolv.conf file?<\/p>\n\n\n\n<p>Well, there are a number of ways:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"#resolvconf\" class=\"rank-math-link\">Use Resolvconf framework<\/a><\/li>\n\n\n\n<li><a href=\"#set-dns-on-interface-settings\" class=\"rank-math-link\">Set the name server IP address on your Interface settings<\/a><\/li>\n\n\n\n<li><a href=\"#dns-in-dhclient.conf\" class=\"rank-math-link\">Update the DNS server settings on dhclient.conf<\/a><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"resolvconf\">Use Resolvconf framework<\/h3>\n\n\n\n<p>Resolvconf is a framework for keeping up to date the system&#8217;s information about name servers. It sets itself up as the intermediary between programs that supply this information (such as ifup and ifdown, DHCP clients, the PPP daemon and local name servers) and programs that use this information such as DNS caches and resolver libraries).<\/p>\n\n\n\n<p>On Ubuntu\/Debian distros, you can install resolvconf framework by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo apt install resolvconf<\/code><\/pre>\n\n\n\n<p>Once the framework is installed, it is started and enabled to run on system boot.<\/p>\n\n\n\n<p>Next, edit the configuration file, <code><strong>\/etc\/resolvconf\/resolv.conf.d\/base<\/strong><\/code>, and enter your DNS settings. See example setting below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo vim \/etc\/resolvconf\/resolv.conf.d\/base<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>domain kifarunix.com\nnameserver 8.8.8.8\nnameserver 8.8.4.4<\/code><\/pre>\n\n\n\n<p>Save and exit the configuration file.<\/p>\n\n\n\n<p>Next, update <code><strong>\/etc\/resolv.conf<\/strong><\/code> file to make permanent DNS changes;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo resolvconf -u<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"dns-in-dhclient.conf\">Update the DNS server settings on dhclient.conf<\/h3>\n\n\n\n<p>If you are using DHCPd for automatic IP address assignment, edit the <strong><code>\/etc\/dhcp\/dhclient.conf<\/code><\/strong> file and add the line; <code><strong>supersede domain-name-servers IP1, IP2;<\/strong><\/code>. Replace IP1 and IP2 with your respective name server IP addresses;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/dhcp\/dhclient.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>supersede domain-name-servers 8.8.8.8, 8.8.4.4;<\/strong><\/code><\/pre>\n\n\n\n<p>Save the file and exit.<\/p>\n\n\n\n<p>Now, if you run dhclient, your <code><strong>\/etc\/resolv.conf<\/strong> <\/code>will be updated with the name servers  defined in the dhclient.conf.<\/p>\n\n\n\n<p>You can use the <strong><code>prepend<\/code><\/strong> option instead of <code><strong>supersede<\/strong><\/code> to add additional IP addresses to the default one provided by the ISP.<\/p>\n\n\n\n<p>Consult;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>man dhclient.conf<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"set-dns-on-interface-settings\">Set the name server IP address on your Interface settings<\/h3>\n\n\n\n<p>Edit your network interface configuration file and add the address of the name server.<\/p>\n\n\n\n<p>In Ubuntu 18.04\/20.04 you would update the Netplan configuration file like;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo vim \/etc\/netplan\/01-network-manager-all.yaml<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>network:\n  version: 2\n  renderer: networkd\n  ethernets:\n          wlp0s20f3:\n                  dhcp4: no\n                  addresses: &#91;192.168.100.80\/24]\n                  gateway4: 192.168.100.1\n                  nameservers:\n                          addresses: &#91;8.8.8.8]<\/code><\/pre>\n\n\n\n<p>We set the DNS to google public DNS server address, 8.8.8.8. It can be different for your case.<\/p>\n\n\n\n<p>Apply the changes;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo netplan apply<\/code><\/pre>\n\n\n\n<p>On Debian and &lt;= Ubuntu 16.04;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/network\/interfaces<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>auto wlp0s20f3\niface wlp0s20f3 inet static\n    address 192.168.100.80\n    netmask 255.255.255.0\n    dns-nameservers 8.8.8.8<\/code><\/pre>\n\n\n\n<p>Restart networking to apply the changes;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart networking<\/code><\/pre>\n\n\n\n<p>On CentOS and similar derivatives, edit the interface in question as follows. Replace INTERFACE with your interface name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>nmcli con mod INTERFACE ipv4.dns 8.8.8.8<\/code><\/pre>\n\n\n\n<p>Also, disable network interface management by the NetworkManager daemon.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>echo \"NM_CONTROLLED=no\" &gt;&gt; \/etc\/sysconfig\/network-scripts\/ifcfg-INTERFACE<\/code><\/pre>\n\n\n\n<p>Apply the changes;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>nmcli con down INTERFACE\nnmcli con up INTERFACE<\/code><\/pre>\n\n\n\n<p>You should now have static DNS set.<\/p>\n\n\n\n<p>And that concludes our guide on how to make DNS permanent changes on resolv.conf in Linux.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Further Reading<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>man resolv.conf<\/strong><\/code><\/pre>\n\n\n\n<pre id=\"block-8c729cf5-5f3a-465e-aacc-535e34bd5cb6\" class=\"wp-block-preformatted\"><strong>man resolvconf<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/check-directory-usage-with-du-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Check directory usage with du Command in Linux<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-use-htop-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">How to use htop Command in Linux<\/a><\/p>\n\n\n\n<p><a aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/example-usage-of-ps-command-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Example Usage of ps Command in Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/example-usage-of-ls-command-in-linux\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Example Usage of ls Command in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Follow through this guide to learn how to make DNS permanent changes on resolv.conf in Linux. According to man resolv.conf, resolv.conf is a resolver configuration<\/p>\n","protected":false},"author":1,"featured_media":8388,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[49,121],"tags":[2622,3313,3310,3312,3314,3311,3315],"class_list":["post-8263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-cheatsheets","category-howtos","tag-etc-resolv-conf","tag-dns-changes-resolv-conf","tag-make-dns-permanent-changes-on-resolv-conf-in-linux","tag-make-permanent-changes-in-resolv-conf-linux","tag-persist-changes-resolv-conf","tag-prevent-etc-resolv-conf-overwrite","tag-resolvconf","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8263"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=8263"}],"version-history":[{"count":4,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8263\/revisions"}],"predecessor-version":[{"id":21887,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8263\/revisions\/21887"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8388"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}