Setting a DNS or nameserver

I wanted to set my own DNS server so I followed the instructions at:
https://wiki.manjaro.org/index.php?title=Set_DNS_or_Nameservers

And that works when I run: sudo resolvconf -u

However, when I reboot the settings are lost. This happens whether I edit /etc/resolvconf.conf or /etc/resolv.conf.head

Either way, it only works if I run sudo resolvconf -u manually after each reboot. Is there a way to get the settings to stick?

use nano instead?

sudo nano /etc/resolve.conf

or switch to a proper root account to make the changes instead of trying to run resolvconf with sudo.

changes I made in the GUI with networkmanager (KDE desktop) stuck on both my systems as per the following:

# Generated by NetworkManager
search 9.9.9.9 199.85.126.10
nameserver 9.9.9.9
nameserver 199.85.126.10

I sometimes ran into problems with network changes sticking via the GUI. If you do not feel like manually editing the conf files, install this package:

nm-connection-editor

If the startup item is not automatically added to your start menu, start it via the terminal.

I’ve always found modifications stick with this GUI utility, (or edit manually if you feel so inclined).

I am manually editing the conf files with nano. I’m following the guide here:
https://wiki.manjaro.org/index.php?title=Set_DNS_or_Nameservers
Is the guide out of date?

As I said, it does work, but it doesn’t stick when I reboot. NetworkManager is overwriting my changes.

I locked the file (immutable). It doesn’t change after a reboot.

sudo chattr +i /etc/resolv.conf

Maybe there is a more elegant way, but I am a simple linux user. :cat:

[Note: If you want to edit the file, you have to unset the immutable flag first with chattr -i ]

2 Likes

EDIT:
I didn’t read the post correct as I didn’t grasp that the NetworkManager overwrites the file.

A way of instructing NetworkManager to leave DNS to the user can be found further down in this post

The following is incorrect in relation to the overwrite situation but useful in other scenarios.

You should uninstall keep the resolvconf package and create a file /etc/resolv.conf with your desired servers.

example using google dns

nameserver 8.8.8.8
nameserver 4.4.4.4

example using cencurfridns.dk

nameserver 91.239.100.100
nameserver 89.233.43.71

The search entry is for use if you have a workgroup or a local domain.

For example I run a bind dns and bind dhcp service for my lan. This runs on a raspberry pi.

I have hostnames defined as a lan domain and this is where the search entry is used.

It defines domains to be search - in my case - it searches uex.lan for hosts before it resolves out of lan.

That doesn’t answer the question. This file is overwritten by NetworkManager on every boot.

Sorry - it was not intentional - I am doing a few experiments on how to minimize the dependency of NetworkManager as I think it’s kind of overkill

If you let the resolvconf package handle the resolv.conf file then you can have NetworkManager use the resolvconf to manage DNS. According to Archlinux Wiki you can create a file

/etc/NetworkManager/conf.d/rc-manager.conf

With this content

[main]
rc-manager=resolvconf

This page might be worth a read

https://blogs.gnome.org/dcbw/2015/02/16/networkmanager-for-administrators-part-1/

After some reading I discovered that if you drop a file 99-stayaway-from-my-dns.conf in the above mentioned conf.d folder and put this inside it

[main]
dns=none

It won’t touch your resolv.conf at all - which is what you are looking for - right?

I have updated the wiki with the info from this post.

1 Like

Is there a difference between creating a new file in conf.d versus just editing /etc/NetworkManager/NetworkManager.conf directly ?

Just make the file unwritable with the command @korealinux suggested. I use that as well and it is simple and effective. And it’s super easy to reverse that state if you want to edit the file again.

Probably not - but it is best practice to use the conf.d folder for those small changes as you makes it difficult for yourself if you change the main config - the main config gets updated and you have to manually merge your changes.

A lot easier to use the conf.d approach.

No and yes.

No, the option will be picked up by NM and for NM is doesn’t matter.

Yes, since the NetworkManager.conf file is provided by the NM package. pacman will create a .pacnew file with the next update of the NetworkManager.conf and you might need to update your config or you might lose a important config change.

You don’t really need at any setup tools like dhcpcd dhclient modemmanager dnsmasq openresolv

If you use NM, it can handle dhcp and resolv.conf updates. There is no need for a extra tool. If you don’t like NM, you can use networkd with resolved and this time systemd will handle dhcp and resolv.conf updates.

2 Likes

I know - I just like to know the systems - and what to do to achieve the same result with other tools.

That includes a deeper understanding of what is going on when your config is replaced on every boot. That is something to drive a sysadmin insane.

I can see that the NetworkManager approach is relevant in the aspect of making Linux more accessible to others than nerd-people - no offence to the non-nerdy users.

I would never have learned what I just did doing the research on this specific issue. My comment on removing the resolvconf script was based on previous experience and I didn’t expect things had changed as they have since I last dug into the matter.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by Bytemark