Score:1

DNS cache: systemd-resolve and ping resolve different IP addresses

cn flag

I have changed the IP address in a DNS record (on Google Cloud DNS), associated to a subdomain test.example.com

From my Google Cloud VM:

  • if I ping test.example.com, I get the old IP address
  • if I systemd-resolve test.example.com, I get the new IP address

I have tried to flush the DNS cache using:

sudo systemd-resolve --flush-caches

but ping is still getting the old IP address

What am I doing wrong?

fr flag
What's in /etc/resolve.conf and where is it pointing to (if symlink)? What's in the `hosts:` line in /etc.nsswitch.conf?
cn flag
this is the default for Google Cloud Compute virtual machines: `resolv.conf -> ../run/systemd/resolve/stub-resolv.conf` "hosts:" in nsswitch.conf says "files dns"
cn flag
content of resolv.conf: `nameserver 127.0.0.53` `options edns0 trust-ad` `search c.myproject.internal google.internal`
fr flag
Do you have by any chance this name in /etc/hosts file?
cn flag
Which name do you mean?
Wojtek_B avatar
jp flag
What distribution and version of linux you are running ? Did you restart your VM after obseved difference in IP's ? Did you do any network configuration on your network settings or installed any network related software that may have done this ? Please provide more information about your setup so we can troubleshoot this.
fr flag
@DanieleB, do you have test.example.com in /etc/hosts?
cn flag
I am using the default configuration on the VM, which is Ubuntu 20.04 LTS on Google Cloud. I tried to restart the VM, but nothing changed.
cn flag
tesr.example.con is not in /etc/hosts
cn flag
To clarify, now after many hours, the IP is shown correctly also for ping. But still isn't clear why ping was resolving a different IP than systemd-resolve.
Score:1
jp flag

Behavior you observed comes from a known systemd bug - I dare to say that since you indicated that you have nameserver 127.0.0.53 in your /etc/resolv.conf - systemd adds it due to mentioned bug. Have a look at the answers provided since they may contain a solution that's right for you. Most of them however suggest to "hardcode" DNS.

Ping works in a different way and it was able to resolve the name correctly.

Inner workings related to DNS and systemd-resolve were discussed at length here.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.