post

Keeping My SSH Connections Alive on Verizon 4G LTE

Today I switched back to Verizon for my personal mobile Internet needs, and I’m pretty sure I’m going to stick with this change. I like my experience so far.

I did come up with a problem, though. It seems that Verizon 4G provides me with an internal (10.x.x.x) IP address instead of a public IP address, and that their NAT router has a pretty short timeout for connections that have no traffic. This means that when I connect to a server via SSH and I don’t touch the connection for about 5 minutes, my connection gets dropped.

My workflow has a lot of 5 minute breaks from SSH, too. After some searching the ‘net, I found a reference to setup SSH so that it transmits a keepalive packet to keep my connection alive. That got me searching for instructions that are specific to Mac OS X, and I found a great writeup here.

Bottom line: I edited my ~/.ssh/config file and added the following two lines:

ServerAliveInterval 120
ServerAliveCountMax 3

This will send a packet to my server every 120 seconds (every 2 minutes), and then disconnect if I don’t hear back from the server for 3 cycles (6 minutes).