Automatically access a computer using local IP if it's on my local network or internet IP otherwise

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.

Praxeolitic

Posted 2017-08-30T06:55:15.677

Reputation: 240

Answers

2

One solution would be to have a local DNS server on your LAN: you could add a local entry that would resolve your desktop URL/domain name to a local IP on the LAN. This way:

  • when you are on the LAN: you get your desktop's local IP
  • when you are on the WAN: you get your desktop's public IP

Unfortunately, this will probably require quite a lot of work, as most routers do not include local dns and your router (archer C7) does not seem to provide such feature.

Gohu

Posted 2017-08-30T06:55:15.677

Reputation: 757