DRYな備忘録

Don't Repeat Yourself.

sshトンネリング(ポートフォワード)とか多段ポートフォワード

localhostの9999番ポートを、リモートホストmyremotehost.comの7777番に、myproxyを使ってポートフォワードしたい。

ssh -L 9999:myremotehost.com:7777 myproxy

で、myremotehost.com:7777で動いてる何かし(アプリケーションや、MySQLなどのデーモン)へアクセスしたいとき、localhost:9999番を全く同じインターフェースとして叩けばよい。

つまずくポイント

  • localhostからmyproxyへのssh (port 20) は開いているか
  • myproxyからmyremotehost.comの名前は見えるか
  • myproxyからmyremotehost.comへのport 7777番は開いているか

あと、多段ポートフォワード

.ssh/config

Host myproxy
    HostName yy.yy.yy.yy # in VPN
    User ochiai
    IdentityFile hoge.pem
    ProxyCommand ssh mygateway nc %h %p

Host mygateway
    HostName  xx.xx.xx.xx # in Internet
    User otiai10
    IdentityFile foo.pem
    ForwardAgent yes