-
MINT > résoudre l’écrasement des DNS lors du reboot
-
Didn’t work on Ubuntu 18.04 :(
/etc/resolv.conf
was overwritten after reboot. – Dan Dascalescu Oct 21 at 4:50 -
Unfortunately this didn’t work on Ubuntu 18.04. After rebooting,
/etc/resolv.conf
was overwritten with 127.0.0.53. – Dan Dascalescu Oct 21 at 4:52 -
-
-
That directory doesn’t exist by default on Ubuntu 18.04. Do you need to install a service that creates it? – Dan Dascalescu Oct 21 at 4:55
-
I believe that the user in the question actually tried
chattr
, but obverved that this had no effect. – Kusalananda♦ Oct 15 at 21:25 -
This will work for sure , The option user tried is for editing the file not for making it immutable – Ashish Jain Oct 16 at 13:09
-
Please run the command with sudo chattr -V +i filename e.g sudo chattr -V +i /etc/resolv.conf – Ashish Jain Oct 16 at 13:16
UPDATE2 AND SOLUTION:I commented the part out (#Start to #End), that seemingly overwrites the/etc/resolv.conf
file and sure enough. That was the culprit. So an obscure script caused all this trouble.I changed the question to reflect, what actually needed to be known to solve my problem, so it would be easier to find for people with the same problem and so I could accept an answer.
Thanks for the help here in figuring things out.
Setting the immutable flag on resolv.conf doesn’t work as you expected as the file was not changed. The directory entry in /etc was changed when the file was renamed. You’d have to set /etc to be immutable - something you really don’t want to do.
@DougO’Neal I see. Thanks for the heads up.
8 Answers
1) You shouldn’t manually update your resolv.conf, because all changes will be overwritten by data that your local DHCP server provides. If you want it to be static, run
sudo dpkg-reconfigure resolvconf
and answer "no" to dynamic updates. If you want to add new entries there, edit/etc/resolvconf/resolv.conf.d/base
and runsudo resolvconf -u
, it will append your entries and DHCP server’s entries.2) Try to edit your /etc/network/interfaces and add your entries there, like
auto eth0 iface eth0 inet dhcp dns-search google.com dns-nameservers dnsserverip
and then restart
/etc/init.d/networking restart
orsudo ifdown -a
andsudo ifup -a
3) Your system uses udhcp which is a very small DHCP client program. The udhcp client negotiates a lease with the DHCP server and notifies a set of scripts when a leases is obtained or lost. You can read about it’s usage here or just edit this script (as you did).
2,29011 gold badge1111 silver badges2121 bronze badges
I ran into this too. Commenting out
domain-name-server
didn’t fix it for me either.Also, I’m not using
resolvconf
, just plain/etc/resolv.conf
.I didn’t try using
chattr +i
to lock downresolv.conf
because it seems too hacky. Also, I want Puppet to be able to modifyresolv.conf
when necessary.The best solution I found overrides the default behavior of
dhclient
using its documented hooks.Create a new file at
/etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
with the following contents:#!/bin/sh make_resolv_conf() { : }
Then make the file executable:
chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
Now when dhclient runs -- either on reboot or when you manually run
sudo ifdown -a ; sudo ifup -a
-- it loads this scriptnodnsupdate
. This script overrides an internal function calledmake_resolv_conf()
that would normally overwriteresolv.conf
and instead does nothing.This worked for me on Ubuntu 12.04.
Ubuntu 16.04
If the network interfaces for your server instance is controlled by DHCP, the dhclient program will overwrite your/etc/resolv.conf
file whenever the networking service is restarted.You can fix the issue by editing the
/etc/dhcp/dhclient.conf
file and adding “supersede” statements for domain-name, domain-search and domain-name-servers as follows:supersede domain-name "local.com"; supersede domain-search "local.com"; supersede domain-name-servers 192.168.56.103;
In this particular case the name server is located at "192.168.56.103″ and the domain name is "local.com"
Note that each line is terminated by a semi-colon and the domain name is enclosed in double quotes.
go to this directory:
cd /etc/resolvconf/resolv.conf.d
Open the file named head and put the DNS IPs or names in there. Open the file named tail and put the domain in there. Reboot.
0In Azure VMs /etc/resolv.conf is not directly editable.
Try adding the DNS entiries in your network configuration files /etc/sysconfig/network-scripts/ifcfg-eth0 and so on like below:
DOMAIN=example.com
DNS1=10...*
DNS2=10...*
DNS3=10...*and restart the network service after saving the files. you will see the configuration will then be added into the resolve.conf as well.
To make the DNS related changes in
resolv.conf
permanent, you need to change the DHCP configuration file nameddhclient.conf
. You can find the file in/etc/dhcp/dhclient.conf
.Open the file for editing (don’t forget to use sudo). You’ll see lines like these:
#supersede domain-name "fugue.com home.vix.com"; #prepend domain-name-servers 127.0.0.1;
Remove the preceding “#” and use the domain-name and/or domain-name-servers which you want. Save it. Now the DNS related changes will be permanent.
Credits goes to: https://itsfoss.com/resolvconf-permanent-ubuntu/
Use the below command to prevent the resolv.conf or any file from overwriting after reboot
chattr -V +i filename e.g chattr -V +i /etc/resolv.conf
To Revert Back the Change Use the below Command :
chattr -i filename - to re-enable insert to the file
chattr (Change Attribute) is a command line Linux utility that is used to set/unset certain attributes to a file in Linux system to secure accidental deletion or modification of important files and folders, even though you are logged in as a root user.
On ubuntu 18.04 using NetworkManager. You need to remove the ‘resolv.conf’ file and let NetworkManager generate one for you.
To remove the file in terminal type
sudo rm -f /etc/resolv.conf
; this will delete the file for you.Reboot the system and NetworkManager will generate a resolv.conf file for you.
-
/etc/resolvconf/resolv.conf.d/base
and ranresolvconf -u
. It didn’t work, unfortunately.dpkg-reconfigure resolvconf
. The entries were not in there. And I have entries with bothnameserver ip
andsearch domain
.dpkg-reconfigure resolvconf
won’t add entries, but you can disable automatic updates. If you disable updates, you can edit resolv.conf manually and it shouldn’t be overwritten.resolvconf -u
the entries were not added.