20110114

Fake Dynamic DNS, SSH, BASH, and Dropbox

I recently wanted to set up remote access to my home computer, which doesn't have a stable IP address. Rather than do the sane thing and set up dynamic DNS, I decided to experiment with an ad-hoc solution involving drop box.

In brief : the home computer writes its current IP address to a drop-box folder, and scripts on remote computers reference this information to log in remotely.

My computer was behind a router, so I had to set up port forwarding and set up SSH access to my machine. These steps are the same as if I were using dynamic DNS.

Then, I added a chron job to periodically run the following script, every hour or so. This script uses whatismyip.org to retrieve the IP address of the home machine and save it as a script in dropbox.
#!/bin/bash
__IP__=`curl whatismyip.org`
__TT__=`date +%Y%m%d%H%M%S`
echo $__IP__ > ~/Desktop/Dropbox/public/some/dropbox/location/__IP__
echo -e "#!/bin/bash\n#updated at $__TT__\nssh -CXY username@$__IP__\n"\
>~/Desktop/Dropbox/some/dropbox/location/ssh_mymachine
You may want to change some/dropbox/location and username details to match your machine. This script, when run, will generate a scrip in your DropBox that looks something like :
#!/bin/bash
#last updated at 20110114173001
ssh -CXY username@###.###.###.###
It will also save a small file __IP__ containing only the IP address. Dropbox will then synch these files across all of your computers, in my case my laptop and work machine. You can then use this script to log in from your remote machine. Various options, including adding the script to PATH, hard linking a copy of the script to /usr/bin, or aliasing the script in ~/.yourfavoriteshellconfig, can be used to make the remote login more succinct.

I had trouble with the re-written script losing executable privileges every time it was updated. So, a single script that you write once that just reads the IP information is possibly a better solution :
#!/bin/bash
__IP__=`cat ~/Desktop/Dropbox/some/dropbox/location/__IP__`
ssh -CXY username@$__IP__
If you are daring and want to expose your machine to even more potential security violations, you could announce your IP in a public dropbox folder, which will have a mostly stable URL associated with it. Then, any remote machine regardless of whether it is synched with your Dropbox could use this information like so :
#!/bin/bash
__IP__=`curl http://dl.dropbox.com/u/##YOURUSERID##/public_folder_name/__IP__`
ssh -CXY username@$__IP__
As another trick, you could achieve quasi-stable DNS for a webserver by publishing a html page in your public dropbox, which contains a redirect to your announced IP address. Visiting this page will send visitors to your home webserver. But, I imagine if you've reached this point you really should have gone with a free dynamic-DNS service.

No comments:

Post a Comment