Losing occational remote access to raspberry pi

Hi,
I have a Raspbyerr Pi 4 running Dietpi. I am occationally unable to ssh into the pi outside my network, even if I was able to just a few minutes prior.

I set up a script a few days ago to see if I was able to ping google. When I ran into problems again, I noted the time. During this time, the Pi was still able to reach the outside network, despite me not being able to ssh into it.

Does anyone happen to know why this might be the case?
I appreciate any help!

Hi,

what do you mean by unable to ssh into the pi outside my network. Are you trying to connect to your system using VPN from internet?

One possible explanation is the periodic change of dynamic IP.
A cycle of the wan interface usually takes not more than 5", usually 1" is enough for a down/up.
So the ping from the lan to google will barely be affected. However the change of IP takes longer to be updated in dyndns, so the SSH would take longer.