2
I backup my laptop (macOS) to a desktop (Linux) at home. Naturally, my laptop is sometimes at home, on the same local network as my desktop, and sometimes it isn't. For quite a while I've had the laptop refer to the desktop with a public URL since it's convenient and works no matter where the laptop is. The downside is that my backup system accesses the desktop over the internet even when it would be faster to access it over the LAN. (I would have thought that while at home, my router or something on my ISP's end would immediately notice that I'm accessing my own IP and take a shortcut, but traceroute shows 12+ hops so I guess not.)
How can I automatically have my laptop access my desktop over the LAN when possible, and over the internet otherwise?
The best I can think of is a shell script that checks if I'm at home and modifies my hosts file. That's a bit clunky and would become burdensome if I wanted to do this with more than one device, especially mobile devices. I can't be the only person who has ever had this problem so I'd like to know if there are better methods. Ideally, there exists some way to customize the behavior of url resolution with executable programs or small scripts that I don't know about.
This might seem like excessive tweaking, but my backups sometimes take quite a while, even on my home network, and can become very inconvenient.
My router is an Archer C7.
I have residential internet service so my IP probably changes occasionally but it seems to be very infrequent.
I'm able to detect whether the two computers are on the same local network.