Sudo Complain: DNS Name Resolution in Ubuntu 22.04

Abstract: Resolve DNS errors in Ubuntu 22.04 by avoiding direct edits to /etc/resolv.conf and using NetworkManager or Netplan instead.

Created: 2026-08-24 by
Editing the /etc/resolv.conf file directly with sudo often triggers DNS resolution errors in Ubuntu 22.04 because the system manages this file dynamically through systemd-resolved. When you overwrite it manually, you break the symlink or configuration expected by the resolver, causing immediate connectivity failures for commands that rely on domain name lookup.

Understanding the Conflict

In modern Ubuntu versions, specifically 22.04 and later, the NetworkManager service integrates closely with systemd-resolved to handle network interfaces and DNS settings automatically. The file /etc/resolv.conf is no longer a static configuration file that users should edit directly. Instead, it is typically a symbolic link pointing to /run/systemd/resolve/stub-resolv.conf or /run/systemd/resolve/resolv.conf. This design ensures that when your network interface changes IP addresses or switches between Wi-Fi and Ethernet, the DNS servers update automatically without requiring manual intervention.

When you use sudo to write to /etc/resolv.conf, you are essentially breaking this automated chain. The system detects that the expected dynamic state has been compromised. Many applications, including package managers and web browsers, will fail to resolve hostnames because they cannot trust the stale or incorrect data in the manually edited file. This results in errors such as "Could not resolve host" or timeouts during software updates, which can be confusing if you were simply trying to add a custom nameserver for testing purposes.

Why Manual Editing Fails

The core issue lies in how systemd-resolved operates. It generates the content of the resolv.conf stub based on the current network configuration provided by NetworkManager. If you force-write to the file, you create a discrepancy between what the resolver expects and what is actually present. Furthermore, systemd-resolved may periodically overwrite or validate the file, leading to race conditions where your manual changes are either lost or cause the resolver to panic due to invalid syntax.

Additionally, some security modules or PAM configurations might flag direct modifications to critical system files like resolv.conf as suspicious, although the primary failure mode here is functional rather than security-related. The error message you see is usually a symptom of the application failing to connect to the DNS server specified in your broken configuration, rather than a complaint about the act of editing itself. However, the terminology "Sudo Complain" suggests that the user perceives the subsequent DNS failures as a direct rebuke from the system for using sudo improperly.

Proper Ways to Configure DNS

To correctly change DNS settings in Ubuntu 22.04, you should avoid touching /etc/resolv.conf entirely. Instead, use the graphical Network Manager settings or command-line tools designed for this purpose. For desktop users, open the Settings application, navigate to the Network section, and select the gear icon next to your active connection. Here, you can switch the IPv4 or IPv6 method to "Automatic (DHCP) addresses only" or "Manual," and then input your desired DNS servers in the designated field.

For server environments or headless systems, you can use the nmtui utility, which provides a text-based interface to modify network configurations safely. Alternatively, advanced users can edit the Netplan configuration files located in /etc/netplan/. By defining DNS servers within the YAML structure of your netplan configuration and applying it with sudo netplan apply, you ensure that systemd-resolved receives the correct instructions and regenerates the resolv.conf symlink properly. This approach maintains system integrity and prevents the resolution errors associated with manual edits.

Recovering from a Broken Configuration

If you have already modified /etc/resolv.conf and are experiencing DNS issues, you need to restore the default behavior. First, remove the manually created file using sudo rm /etc/resolv.conf. Then, recreate it as a symbolic link to the systemd-resolved stub by running sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf. After restoring the link, restart the systemd-resolved service with sudo systemctl restart systemd-resolved to flush any cached errors and re-read the network configuration.

In some cases, restarting the NetworkManager service may also be necessary to trigger a fresh DHCP lease and DNS assignment. You can do this by executing sudo systemctl restart NetworkManager. Once these steps are complete, verify that your DNS resolution is working by pinging a known domain, such as ping google.com. If the ping succeeds, your system has successfully recovered from the broken configuration.

It is important to note that if you are using a specific local DNS cache like dnsmasq, you might need to adjust its configuration separately. However, for most standard Ubuntu installations, relying on systemd-resolved is the recommended path. For more information on fixing interrupted system processes, you might find our guide on Sudo Interrupted: Manually Running sudo dpkg --configure after apt-get upgrade helpful, as similar recovery principles apply to service disruptions.

Frequently Asked Questions

Can I still use /etc/resolv.conf for static DNS?

No, you should not use /etc/resolv.conf for static DNS in Ubuntu 22.04. The system expects this file to be a dynamic symlink managed by systemd-resolved. Writing to it directly breaks the integration with NetworkManager and leads to resolution failures.

How do I check which DNS servers my system is currently using?

You can check the active DNS servers by running the command resolvectl status in the terminal. This tool queries systemd-resolved and displays the DNS servers assigned to each network interface, along with the current search domains.

What if I need to use a custom DNS for a single application?

If you need to override DNS for a specific application, consider using environment variables like DNS_RESOLVER_OPTIONS if supported, or configure the application to use an IP address directly. Some applications support reading from a custom hosts file via /etc/hosts for simple hostname-to-IP mappings without changing global DNS settings.

Will restoring the symlink delete my custom DNS settings?

Restoring the symlink removes your manual edits but does not erase the intended configuration. You should re-apply your desired DNS settings through the Network Manager GUI or Netplan YAML files. These methods will regenerate the appropriate content in the resolved stub, ensuring your settings persist across reboots and network changes.

Is it safe to disable systemd-resolved?

Disabling systemd-resolved is generally not recommended unless you have a specific reason, such as using a different DNS management tool like dnsmasq or unbound. If you disable it, you must manually manage /etc/resolv.conf and ensure your network manager can function without it, which can lead to complex troubleshooting scenarios.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More