BLOGTIMES
2012/09/28

autossh で切れないトンネルを

  ssh  networking 
このエントリーをはてなブックマークに追加

ssh でトンネルを張って放っておくと、ネットワークの関係でいつの間にか接続が切れているというのは珍しくありません。
開発中などであればいちいち張り直してもいいのですが、ssh を簡易 VPN のように使っている場合にはちょっと困ったことになります
そんなときには autossh を使えば接続が切れたときに自動的に再接続してくれることがわかったのでメモ。

autossh

FEATURES
  ・autossh is a program to start a copy of ssh and monitor it, restarting it as necessary should it die or stop passing traffic. The idea is from rstunnel (Reliable SSH Tunnel), but implemented in C.
  ・The author's view is that it is not as fiddly as rstunnel to get to work.
  ・Connection monitoring using a loop of port forwardings or a remote echo service.
  ・Backs off on rate of connection attempts when experiencing rapid failures such as connection refused.
  ・Compiled and tested on OpenBSD, Linux, Solaris, Mac OS X, Cygwin, and AIX; should work on other BSDs.
  ・Freeware.

今回は yum で導入

今回導入したマシンは SL6 だったので rpmforge にあるバイナリを yum でインストールしました。

yum install autossh

簡単な使い方

普段、下記の感じで使っているトンネルの指定があったとします。

ssh -t -N -L80:localhost:80 user@dest.example.com ssh -N -t -D8080 user@dest.example.com

上記を下記のように書き換えてあげれば OK。

autossh -M 20000 -f -t -N -L80:localhost:80 user@dest.example.com autossh -M 20000 -f -N -t -D8080 user@dest.example.com

autossh 自体は ssh を子プロセスとして起動して監視してくれるようです。

2013/12/03 追記

Windows の場合は pfwd.exe を使うのが楽です。


    トラックバックについて
    Trackback URL:
    お気軽にどうぞ。トラックバック前にポリシーをお読みください。[policy]
    このエントリへのTrackbackにはこのURLが必要です→https://blog.cles.jp/item/5249
    Trackbacks
    このエントリにトラックバックはありません
    Comments
    愛のあるツッコミをお気軽にどうぞ。[policy]
    古いエントリについてはコメント制御しているため、即時に反映されないことがあります。
    コメントはありません
    Comments Form

    コメントは承認後の表示となります。
    OpenIDでログインすると、即時に公開されます。

    OpenID を使ってログインすることができます。

    Identity URL: Yahoo! JAPAN IDでログイン