How to Fix Persistent DNS Reset Issue in Kubuntu 24.04


Introduction
If you are using Kubuntu 24.04 and facing a persistent issue where your DNS settings reset after every reboot, you are not alone. This problem can cause issues like:
DNS resolution failures (e.g.,
ping
github.com
results inName or service not known
)Inability to connect to websites or repositories
Frequent loss of internet connection
In this guide, we will cover the root cause of the problem, temporary workarounds, and a permanent solution to ensure your DNS settings persist across reboots.
Understanding the Problem
Symptoms
You may encounter the following errors when trying to access a website or clone a repository using Git:
ping github.com
ping: github.com: Name or service not known
Or when using Git:
git clone git@github.com:username/repository.git
ssh: Could not resolve hostname github.com: Name or service not known
fatal: Could not read from remote repository.
After restarting your network or system, the issue temporarily disappears but returns on the next reboot.
Why This Happens?
In Kubuntu 24.04, the system automatically manages DNS settings using systemd-resolved
. It dynamically creates the /etc/resolv.conf
file and overwrites any manual changes.
By default, /etc/resolv.conf
is a symbolic link (symlink) pointing to /run/systemd/resolve/stub-resolv.conf
, meaning it does not persist across reboots:
ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Mar 26 10:00 /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf
This is why even if you manually update DNS settings, they revert back once the system reboots.
Temporary Fixes
If you need a quick solution without modifying system files permanently, try the following:
Method 1: Restart Network Services
Restarting systemd-resolved
can temporarily resolve DNS resolution issues:
sudo systemctl restart systemd-resolved
Method 2: Manually Update resolv.conf (But It Will Reset After Reboot)
echo -e "nameserver 8.8.8.8\nnameserver 1.1.1.1" | sudo tee /etc/resolv.conf
These methods work temporarily but will not survive a reboot.
Permanent Fix: Prevent Systemd from Overwriting DNS Settings
To make the DNS changes permanent, follow these steps:
Step 1: Remove the Symlink for resolv.conf
Since /etc/resolv.conf
is a symlink, we must first remove it:
sudo rm /etc/resolv.conf
Step 2: Create a Static resolv.conf File
Now, create a new DNS configuration file manually:
sudo nano /etc/resolv.conf
Add the following lines (using Google and Cloudflare DNS servers):
nameserver 8.8.8.8
nameserver 1.1.1.1
Save the file (CTRL + X
, then Y
, then ENTER
).
Step 3: Prevent Systemd from Modifying resolv.conf
To protect the file from being overwritten, make it immutable using the chattr
command:
sudo chattr +i /etc/resolv.conf
To verify the file is now immutable:
lsattr /etc/resolv.conf
You should see:
----i--------- /etc/resolv.conf
This confirms the file cannot be modified by systemd or any other process.
Step 4: Restart Systemd-Resolved
Restart the DNS resolver service to apply the changes:
sudo systemctl restart systemd-resolved
Step 5: Verify the Fix
Try pinging a domain to ensure that DNS is now working correctly:
ping github.com
If you get a response, your DNS settings are now permanently fixed!
Why This Solution Works?
Removing the symlink ensures that systemd-resolved no longer controls the resolv.conf file.
Creating a static
/etc/resolv.conf
lets you define your own persistent DNS settings.Making the file immutable (
chattr +i
) prevents systemd or other processes from modifying it.
Pros and Cons of This Fix
✅ Pros
✔️ Permanent fix for DNS resetting issue ✔️ No need to restart services after reboot ✔️ Works across all networks, including Wi-Fi and Ethernet
❌ Cons
❌ You will need to manually update /etc/resolv.conf
if you ever need to change DNS settings again. ❌ If your network uses dynamic DNS (DHCP), this fix may cause issues in environments that rely on automatic DNS resolution.
(If needed, you can make the file editable again by running sudo chattr -i /etc/resolv.conf
.)
Conclusion
The DNS resetting issue in Kubuntu 24.04 is caused by systemd-resolved automatically managing /etc/resolv.conf
. While temporary solutions exist, the best way to permanently fix the issue is to:
Remove the symlink
Create a static
/etc/resolv.conf
fileMake it immutable with
chattr +i
By following this guide, your DNS settings will persist across reboots, ensuring a stable and uninterrupted internet connection. 🚀
Subscribe to my newsletter
Read articles from J.A. Shezan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

J.A. Shezan
J.A. Shezan
Shezan loves technology who is currently studying Computer Science and Engineering. He codes frontend & backend of a website. He also does penetration testing on web apps.