How to unwritable /etc/resolv.conf in linux

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


sudo chattr +i etc/resolv.conf

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