How to Always Know Your IP for Remote Connection

Keep track of your IP address to easily connect to your desktop at home.

Guillaume Androz
Geek Culture

--

Photo by casparrubin on unsplash

In the current pandemic days, I’m not the only person on Earth to work remotely. I used to work from home some days, but not on a regular basis, but I can say that I like it. The most enjoyable part is that working remotely allows you to work from home, from your chalet, from your parent’s … well wherever you want ! The only condition though, is that you own a laptop and a good connection.

However, as a datascientist, my two GPU rig does not travel as well as my laptop, but it is far more powerful. Sure I could have setup the equivalent cloud based VM, but hey, how could I game ?!

So, the simple solution is to travel with my laptop and let my desktop at home. The coding part is done on my laptop when I am away from home and let the heavy process happens on my desktop. All I need is to connect to my desktop with a secured SSH connection. Even VSCode allows you to open a SSH connection directly in the IDE which is even more easy. Thanks MSFT !

The only problem for this to happen is to always know your public IP. Unless you pay for a fixed IP, it might change over time, but not too often as your internet provider tries hard to give you the same IP. So you have to track your public IP and have a place to log it.

The solution I found is simply to make a service that checks periodically my public IP and detects any change in it. If my IP changes, an email is then sent to my inbox (I use gmail). I used my favorite language python and the Google API for that (the documentation is very well written):

Not bad ! Just a few lines of code and you’re done. Now all you have to do it to automate the process with a systemd service:

and run this service hourly by defining a timer:

And voila ! You now track your public IP with a linux service that sends you an email when your IP changes so you can let your desktop at home and enjoy working wherever you want !

--

--