Hi! You're correct — when using a custom DNS provider like NextDNS, changes to filtering rules (like which IPs are allowed or blocked) may not take effect immediately if there's cached DNS data on your system.
Let’s walk through how to clear DNS cache on Ubuntu 24.04, and also clarify a few things depending on what DNS resolver you’re actually using locally.
🔍 Step 1: Understand What DNS Resolver You're Using
Ubuntu 24.04 doesn't use a built-in DNS caching service by default (like systemd-resolved is often used in earlier versions, but it can be disabled). You might be using:
systemd-resolved
dnsmasq
unbound
NextDNS CLI (nextdns run)
- A local DNS caching proxy like
nscd, stubby, etc.
- Or nothing — just resolving directly via NextDNS
So first, let's check what DNS server you're actually querying locally.
✅ Check your current DNS cache setup:
Run:
resolvectl status
If you see output mentioning systemd-resolved, then it's managing DNS resolution and possibly caching.
Alternatively, try:
systemd-resolve --statistics
If that says "command not found", systemd-resolved might be disabled or not installed.
Another way:
cat /etc/resolv.conf
If it points to 127.0.0.53, that’s systemd-resolved.
If it points to 127.0.0.1, you may be running a local DNS forwarder like dnsmasq, unbound, or the NextDNS CLI.
🔄 Step 2: Clear DNS Cache Based on What You're Using
🔹 A) If using systemd-resolved:
Clear the cache with:
sudo systemd-resolve --flush-caches
⚠️ Note: In newer versions of systemd (v247+), the command changed:
sudo resolvectl flush-caches
To verify it worked:
resolvectl statistics
You should see the cache hits drop to zero.
🔹 B) If using dnsmasq:
Stop and restart the dnsmasq service:
sudo systemctl restart dnsmasq
To clear its cache (depending on config, sometimes restarting is enough).
🔹 C) If using unbound:
Flush the Unbound cache:
sudo unbound-control flush
Make sure unbound-control is enabled and configured properly.
🔹 D) If using nscd (Name Service Cache Daemon):
Clear its DNS cache:
sudo nscd -i hosts
Or restart the service:
sudo systemctl restart nscd
🔹 E) If using NextDNS CLI (nextdns run):
The NextDNS CLI does not cache DNS entries locally by default. It forwards queries directly to NextDNS servers. So if you're using the CLI, there's no local cache to clear — but:
- Your browser or application may cache DNS entries.
- Your router or ISP might also cache DNS.
So in this case, try:
Flush your app/browser cache
- Restart browsers
- Or hard-refresh (
Ctrl+Shift+R / Cmd+Shift+R)
- Or use private/incognito windows to bypass local cache
Or restart networking:
sudo systemctl restart systemd-networkd
# or
sudo nmcli networking off && sudo nmcli networking on # if using NetworkManager
🕒 Still Seeing Blocked IPs?
If you've allowed certain IPs in your NextDNS dashboard but they're still blocked:
- Double-check the allow rule is active and correctly configured.
- Changes can take a few minutes to propagate on their side too.
- Make sure you're not seeing cached results from somewhere else (like a browser or router).
You can test DNS resolution directly against NextDNS using dig:
dig @your-nextdns-ip example.com
Replace your-nextdns-ip with the IP address of your NextDNS endpoint (visible in your NextDNS settings).
✅ Summary
| DNS Resolver | How to Clear Cache |
|---|
systemd-resolved | sudo resolvectl flush-caches |
dnsmasq | sudo systemctl restart dnsmasq |
unbound | sudo unbound-control flush |
nscd | sudo nscd -i hosts or restart service |
NextDNS CLI | No local cache; restart apps/networking instead |
Let me know how you're running NextDNS (via CLI, Docker, NetworkManager plugin, etc.), and I can give you more targeted help!