{"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
Follow through this guide to learn how to make DNS permanent changes on resolv.conf in Linux.<\/p>\n\n\n\n
According to man 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 Any changes made manually to the According to the comments made in the file, the file is dynamic. “DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN<\/strong>“.<\/p>\n\n\n\n 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, If you make any changes, like a system reboot, or run the So how do you make permanent DNS changes using resolv.conf file?<\/p>\n\n\n\n Well, there are a number of ways:<\/p>\n\n\n\n Resolvconf is a framework for keeping up to date the system’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 On Ubuntu\/Debian distros, you can install resolvconf framework by running the command below;<\/p>\n\n\n\n Once the framework is installed, it is started and enabled to run on system boot.<\/p>\n\n\n\n Next, edit the configuration file, Save and exit the configuration file.<\/p>\n\n\n\n Next, update If you are using DHCPd for automatic IP address assignment, edit the Save the file and exit.<\/p>\n\n\n\n Now, if you run dhclient, your You can use the Consult;<\/p>\n\n\n\n Edit your network interface configuration file and add the address of the name server.<\/p>\n\n\n\n In Ubuntu 18.04\/20.04 you would update the Netplan configuration file like;<\/p>\n\n\n\n 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 Apply the changes;<\/p>\n\n\n\n On Debian and <= Ubuntu 16.04;<\/p>\n\n\n\n Restart networking to apply the changes;<\/p>\n\n\n\n On CentOS and similar derivatives, edit the interface in question as follows. Replace INTERFACE with your interface name.<\/p>\n\n\n\n Also, disable network interface management by the NetworkManager daemon.<\/p>\n\n\n\n Apply the changes;<\/p>\n\n\n\n You should now have static DNS set.<\/p>\n\n\n\n And that concludes our guide on how to make DNS permanent changes on resolv.conf in Linux.<\/p>\n\n\n\n Check directory usage with du Command in Linux<\/a><\/p>\n\n\n\n How to use htop Command in Linux<\/a><\/p>\n\n\n\nresolv.conf<\/strong><\/code>, 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
Use resolv.conf to Make Permanent DNS Changes in Linux<\/h2>\n\n\n\n
\/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
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
echo \"nameserver 8.8.8.8\" > \/etc\/resolv.conf<\/code><\/pre>\n\n\n\n
dhclient<\/strong><\/code> command the line added above, will disappear.<\/p>\n\n\n\n
\n
Use Resolvconf framework<\/h3>\n\n\n\n
sudo apt install resolvconf<\/code><\/pre>\n\n\n\n
\/etc\/resolvconf\/resolv.conf.d\/base<\/strong><\/code>, and enter your DNS settings. See example setting below;<\/p>\n\n\n\n
sudo vim \/etc\/resolvconf\/resolv.conf.d\/base<\/code><\/pre>\n\n\n\n
domain kifarunix.com\nnameserver 8.8.8.8\nnameserver 8.8.4.4<\/code><\/pre>\n\n\n\n
\/etc\/resolv.conf<\/strong><\/code> file to make permanent DNS changes;<\/p>\n\n\n\n
sudo resolvconf -u<\/code><\/pre>\n\n\n\n
Update the DNS server settings on dhclient.conf<\/h3>\n\n\n\n
\/etc\/dhcp\/dhclient.conf<\/code><\/strong> file and add the line;
supersede domain-name-servers IP1, IP2;<\/strong><\/code>. Replace IP1 and IP2 with your respective name server IP addresses;<\/p>\n\n\n\n
vim \/etc\/dhcp\/dhclient.conf<\/code><\/pre>\n\n\n\n
supersede domain-name-servers 8.8.8.8, 8.8.4.4;<\/strong><\/code><\/pre>\n\n\n\n
\/etc\/resolv.conf<\/strong> <\/code>will be updated with the name servers defined in the dhclient.conf.<\/p>\n\n\n\n
prepend<\/code><\/strong> option instead of
supersede<\/strong><\/code> to add additional IP addresses to the default one provided by the ISP.<\/p>\n\n\n\n
man dhclient.conf<\/strong><\/code><\/pre>\n\n\n\n
Set the name server IP address on your Interface settings<\/h3>\n\n\n\n
sudo vim \/etc\/netplan\/01-network-manager-all.yaml<\/code><\/pre>\n\n\n\n
network:\n version: 2\n renderer: networkd\n ethernets:\n wlp0s20f3:\n dhcp4: no\n addresses: [192.168.100.80\/24]\n gateway4: 192.168.100.1\n nameservers:\n addresses: [8.8.8.8]<\/code><\/pre>\n\n\n\n
sudo netplan apply<\/code><\/pre>\n\n\n\n
vim \/etc\/network\/interfaces<\/code><\/pre>\n\n\n\n
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
systemctl restart networking<\/code><\/pre>\n\n\n\n
nmcli con mod INTERFACE ipv4.dns 8.8.8.8<\/code><\/pre>\n\n\n\n
echo \"NM_CONTROLLED=no\" >> \/etc\/sysconfig\/network-scripts\/ifcfg-INTERFACE<\/code><\/pre>\n\n\n\n
nmcli con down INTERFACE\nnmcli con up INTERFACE<\/code><\/pre>\n\n\n\n
Further Reading<\/h3>\n\n\n\n
man resolv.conf<\/strong><\/code><\/pre>\n\n\n\n
man resolvconf<\/strong><\/code><\/pre>\n\n\n\n
Other Tutorials<\/h3>\n\n\n\n