How to ssh to my machine at home, when the IP address of router might change?

6

4

I often find I want a file on my home machine when I'm out and about, so I would like to set up ssh server on my home machine to be able to login securely over the internet. It's my understanding that this requires to set up some port forwarding on my ADSL router at home, and then I can ssh in (using the ADSL router's IP address) and it should be secure using a public/private key pair I can make with ssh-keygen.

My question is, doesn't it require my router's IP address to be static or known beforehand? As far as I know my ISP might change my IP address dynamically, so I might find I can't log in some days without going home and googling for "What's my IP address?". Is there a usual way around this, and how frequently do consumer ISPs change your IP address typically anyway?

As well as a massive amount of files, I also want access to processes and devices, so I'm not interested in cloud or dropbox like answers.

wim

Posted 2012-01-10T03:23:21.730

Reputation: 2 523

1I have had the same IP here at this house for 5 years. Obviously it's not going to be the same for everyone but they don't just up and change it unless your modem is offline when your lease expires and even then you'll get it back unless someone else gets it instead. So low chance it will change. – Paperlantern – 2012-01-10T03:30:42.587

Where I am at, if I turn off my router for 12 hours or more, many times I will get a new IP. Less than 12 hours, and I'll always get my old IP address back. I have also tried this by changing the router MAC address, and then change it back after 12 to 24 hours. The longer I go past 12 hours, the more likely I can't get the original IP back. – Kevin Fegan – 2012-11-13T06:04:50.763

Answers

11

Easiest way to deal with this is to use a dynamic DNS service... I use Dyndns. They are more into premium services these days, but you can still get a free domain from them... http://www.dyndns.com/services/upgrades/freevspro.html

Google Dynamic DNS and you will find lots of others.

Many routers have a hook into these services built in.

Kendor

Posted 2012-01-10T03:23:21.730

Reputation: 751

no-ip.org is what I've been using for a few months. The client works well to keep your IP up to date, but it's pretty much the same as dyndns – Rob – 2012-01-30T15:18:26.817

couldn't ssh home yesterday, and it turned out to be due to my ip address having changed. so now i am going to look into a free dynamic dns, thanks. – wim – 2012-02-16T11:20:19.710

4

Hear me out, you don't want to use dropbox for all your files but how about using it to keep your IP address handy? I use a bash script to find my IP every hour and record it in a folder in Dropbox. Then I always have my IP address handy because Dropbox is available for my smart phone. Then I just look up my IP and login to my server through ssh using key pairs from my netbook. I have blogged about this here: http://www.datarookery.com/w/2012/02/22/whats-my-ip-dropbox-style/

Andy Richardson

Posted 2012-01-10T03:23:21.730

Reputation: 41

neat idea. a bit more stuffing around than dynamic DNS, but I can see how that would work. – wim – 2012-02-27T23:03:36.867

1

If you do have access to a public IP that you can SSH into, you can set up a reverse tunnel from your local computer using ssh -R 20000:localhost:22 user@publicipaddress. You'll have to do a little work to keep it persisting through network disconnects, but otherwise it works and is already built in. Look up ssh reverse tunneling.

You should also take a look at pagekite for a reliable way to punch through various subnets.

Ehtesh Choudhury

Posted 2012-01-10T03:23:21.730

Reputation: 1 330