How to Force NetworkManager to Update /etc/resolv.conf Without Restarting Services


2 views

When modifying DNS settings via nmcli commands like:

nmcli connection modify eth0 +ipv4.dns 8.8.8.8
nmcli connection up eth0

You'll often find that /etc/resolv.conf doesn't immediately reflect these changes. This happens because NetworkManager uses its own internal caching mechanism and may not write to resolv.conf immediately after changes.

Method 1: Using nmcli to Trigger Update

The cleanest approach is to use NetworkManager's own tools:

nmcli connection reload
nmcli networking off && nmcli networking on

This sequence forces NetworkManager to re-evaluate all connection settings.

Method 2: Direct resolv.conf Management

If you're using the resolvconf utility:

sudo resolvconf -u

For systems without resolvconf, you can manually symlink:

sudo ln -sf /run/NetworkManager/resolv.conf /etc/resolv.conf

Method 3: Restarting Just the DNS Component

Instead of full network restart, target the DNS subsystem:

sudo systemctl restart NetworkManager.service
sudo systemctl restart systemd-resolved.service  # For systems using resolved

To prevent future issues, configure NetworkManager to always update resolv.conf:

echo "[main]
dns=none
rc-manager=resolvconf" | sudo tee /etc/NetworkManager/conf.d/dns.conf
sudo systemctl restart NetworkManager

After applying any method, verify with:

cat /etc/resolv.conf
nmcli device show eth0 | grep DNS

When modifying DNS settings via NetworkManager's nmcli, many admins notice that /etc/resolv.conf isn't immediately updated. This happens because NetworkManager typically manages this file through hooks or symlinks (often to /run/NetworkManager/resolv.conf), and changes require explicit triggering.

Restarting the entire network service (systemctl restart NetworkManager) works but is overkill. For production systems, this disrupts existing connections. Here's what actually happens under the hood:


1. NetworkManager writes new configs to /run/NetworkManager/resolv.conf
2. The symlink at /etc/resolv.conf needs refreshing
3. The local resolver (stubby, systemd-resolved, etc.) may need reloading

Method 1: Connection Reapply

nmcli connection up eth0

This reactivates the connection without full restart.

Method 2: DNS Update Trigger

nmcli general reload

For RHEL/CentOS 8+ and Fedora, this reloads all configurations.

Method 3: Manual Symlink Update
When using resolv.conf symlinks:


sudo rm /etc/resolv.conf
sudo ln -s /run/NetworkManager/resolv.conf /etc/resolv.conf

To ensure automatic updates, check your NetworkManager config:


# /etc/NetworkManager/NetworkManager.conf
[main]
dns=default
rc-manager=resolvconf

Check current DNS handling method:

nmcli dev show | grep DNS

Verify resolv.conf source:

ls -l /etc/resolv.conf