Home > Linux > SSH Timeouts when going through NAT

SSH Timeouts when going through NAT

Very simple problem:
When connecting to an SSH server outside your localnet when you are behind NAT, no matter what you try the session always times out after about 5 minutes of inactivity.

Very simple solution:
/etc/ssh/ssh_config or ~/.ssh/config :

ServerAliveInterval 20

Alternatively you can specify it on the command line:

$ ssh -o ServerAliveInterval=20 user@host

I don’t know why it took me so long to stumble upon this one. I had tried everything I could think of including TCP keepalives and ClientAliveInterval settings on the server and it just wouldn’t prevent the session timing out even though they really ought to. The solution that definitely works is to set ServerAliveInterval in the client config.

Be Sociable, Share!
  1. slava_dp
    March 29th, 2010 at 10:42 | #1

    I’ve never seen this problem. Been using ssh through two nats (Home Laptop -> NAT on home router -> NAT on provider -> Internet -> NAT in the office -> Office ssh server), and no timeouts whatsoever.

  2. March 29th, 2010 at 12:12 | #2

    Aren’t you lucky…

  1. No trackbacks yet.

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).