Score:0

How to unwritable /etc/resolv.conf in linux

au flag

whenever I suspend the system my changes in /etc/resolv.conf are set by default.

each time system loades changing a file is so tired.

There is each way to save my changes in /etc/resolv.conf ??

terdon avatar
cn flag
Please [edit] your question and explain what you are trying to do. Why are you editing `/etc/resolv.conf`? What are you trying to achieve?
Artur Meinild avatar
vn flag
On Ubuntu, by deafult either systemd-resolved or NetworkManager manages your `resolv.conf`. You have to somehow disable either of those and install another application as DNS resolver to be able to edit it manually. This is one of the minor annoying things you have to be aware of in Ubuntu.
Score:2
us flag

As Artur Meinild pointed out. The resolve.config file will be automatically altered by the installed network manager. (In which "NetworkManager" is one of them)

You can check by looking in your resolve.conf file

$ cat /etc/resolv.conf
Generated by NetworkManager

There can be all sorts of network managers present on your system: Here is an example of the 2 main suspects:

If it's systemd you can manually change the DNS address in the systemd file /etc/systemd/resolved.conf. There you should comment out DNS or and fill in your desired service.

sudo nano /etc/systemd/resolved.conf

If it's NetworkManager, my main network manager, you can show the settings by executing "$ sudo NetworkManager --print-config" in your terminal Any DNS settings can be added in the shown file location:

sudo nano /etc/NetworkManager/NetworkManager.conf

and fill in

[main]
dns=8.8.8.8;

or in case you want it to leave the /etc/resolv.conf file alone

dns=none

In all cases you should restart the service or simply do it the windows way: reboot

sudo systemctl restart NetworkManager

Extra update: Your title suggests you only want a a writing block on the file. This is not common practice as such actions bypasses the Linux flow.

sudo chmod u-w /etc/resolv.conf

.. removes the write options of the file

PooiaFerdowsi avatar
au flag
none of those works :(
Whois_me avatar
us flag
None? very strange. I've seen you've expanded the scope of the question. Maybe you can update your question a bit including the steps you've done so we can respond accordingly. It also seems strange that the only sanction you encounter is a DNS block. Is this really the case?
Score:1
cn flag
sudo chattr +i etc/resolv.conf

better done before making a network connection and I would not trust it too much.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.