我的autossh witt开始了30秒的轮询时间:
AUTOSSH_POLL=30 AUTOSSH_LOGLEVEL=7 autossh -M 0 -f -S none -f -N -L localhost:34567:localhost:6543 user1@server1
它工作正常:
Sep 5 12:26:44 serverA autossh[20935]: check on child 23084
Sep 5 12:26:44 serverA autossh[20935]: set alarm for 30 secs
但是,如果我物理上拔下了网络电缆,这意味着隧道无法再使用,则autossh不会终止ssh守护程序。为什么?我知道如果链接断开,autossh不能执行任何操作,但是我认为它应该尝试执行以下操作:
- 验证子ssh进程(
check on child ...
) - 验证远端!!!(通过隧道执行的类似ping的操作)
- 意识到隧道已关闭
- 停止ssh进程
- 尝试再次创建隧道
- 意识到它不起作用,并设置了(呈指数增长?)计时器以很快再次检查
这就是为什么我运行autossh的原因:如果隧道发生了任何事情(无论是软件还是硬件问题),它都应尝试重新启动它。相反,它只是在等待ssh进程终止。即使没有希望重新建立连接,它也不应该尝试重新启动它吗?
autossh正在执行哪种检查?只需验证ssh是否已启动并正在运行?它不执行任何远端检查吗?
编辑
根据要求,我添加了ssh配置的相关部分:
# (see http://aaroncrane.co.uk/2008/04/ssh_faster)
# The ServerAliveInterval tells SSH to send a keepalive message every 60 seconds while the connection is open;
# that both helps poor-quality NAT routers understand that the NAT table entry for your connection should
# be kept alive, and helps SSH detect when there’s a network problem between the server and client.
ServerAliveInterval 60
# The ServerAliveCountMax says that after 60 consecutive unanswered keepalive messages, the connection should
# be dropped. At that point, AutoSSH should try to invoke a fresh SSH client. You can tweak those
# specific values if you want, but they seem to work well for me.
ServerAliveCountMax 60
TCPKeepAlive yes
dev tun
,两者都使用,并remote
在客户端配置中进行设置即可。唯一令人讨厌的地方是管理证书。我们使用OpenVPN随附的“ easy-rsa” CA。获得证书后,其余的工作就很容易了。