Right now, my /etc/resolv.conf looks like this:

# Generated by NetworkManager

The first two nameservers are automatically configured through DHCP; the last one is the one I added manually, in NetworkManager. It's also the most important one, since it resolves our internal domain names (e.g. build-server-17.our-company-domain.com).

The trouble is, NetworkManager adds it to the bottom of /etc/resolv.conf, so when accessing an intranet URL, my browser tries to resolve it using the first two servers, and it takes ages.

How do I make NetworkManager add the manually-configured DNS server before the automatically-configured ones?

  • 3
    In general, all DNS servers in your resolv.conf should return the same results. Having mixed servers in there is a recipe for intermittent failures and lots of pain. Commented Nov 15, 2016 at 18:08

3 Answers 3


I accidentally created a duplicate question here. The answer is there, but essentially, you need to create:


if it doesn't already exist, and add:

prepend domain-name-servers [ip address of server];

Don't forget the semicolon at the end!

After that, simply rebooting automagically moved the 'nameserver [ip address of server]' line in the '/etc/resolv.conf' up to the top!

  • 1
    Marvelous ! That's the backend used by NetworkManager, and the only way to get this working with all wifi connections (not static). thanks !
    – Adrien M.
    Commented Apr 9, 2018 at 21:20
  • Modifying dhclient doesn't make changes on Rocky8, it uses NetworkManager Commented Nov 25, 2021 at 4:19

I don't see which system to address specifically, but if yours is using resolvconf, try the following as root (su - or sudo -i):

echo 'nameserver' >> /etc/resolvconf/resolv.conf.d/head
resolvconf -u

There is a warning in that file which states that manual changes will be overwritten; but, in context, the message applies to /etc/resolv.conf, not /etc/resolvconf/resolv.conf.d/head.

This should place the desired name server first in the list. Of course, if this works on your operating system, then can be removed from NetworkManager.

The local resolver, dnsmasq, is also an excellent path forward. Using dnsmasq, one can utilize much more control over DNS and DHCP. For example, in this scenario, dnsmasq can query a specific name server based on a specified domain name with its server option. See a snippet from dnsmasq.conf that might pertain to your objective below.

# Add other name servers here, with domain specs if they are for
# non-public domains.


Thanks for mentioning the operating system. On CentOS 7, there are many methods. In the GUI, click Applications > System Tools > Settings > Network. Select a connection to configure.

CentOS 7 NetworkManager - Configure Connection

Turn off Automatic DNS and supply name servers. Apply the configuration.

CentOS 7 NetworkManager - Apply Static DNS Settings

Next time NetworkManager starts that connection, it writes the custom values. (While testing, I turned the network off and then on again because I had two network connections.)

According to documentation,

  1. A simple curses-based text user interface (TUI) for NetworkManager, nmtui, is available.
  2. A command-line tool, nmcli, is provided to allow users and scripts to interact with NetworkManager. Note that nmcli can be used on GUI-less systems like servers to control all aspects of NetworkManager. It is on an equal footing with the GUI tools.

In particular, the nmcli documentation looked very good.

  • 1
    Sorry, it's CentOS, which doesn't have a resolvconf package. dnsmasq seems like a good solution, though. Commented Nov 17, 2016 at 12:00

There is another way, no need to turn off NetworkManager.service. Just set ifcfg-idevice:


You don't need to set /etc/NetworkManager/NetworkManager.conf settings, like:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .