SSH server bastion.example.test側のTCP port 9000への接続を、SSH clientから見える127.0.0.1:3000へ転送する。
remote commandは実行しない。
適切なコマンドはどれか。
ssh -R REMOTE_PORT:DEST_HOST:DEST_PORTはserver側でlistenし、tunnelを通してclient側からdestinationへ接続する。
詳細解説
ssh -N -R 9000:127.0.0.1:3000 bastion.example.testremote 9000をclient側destination 127.0.0.1:3000へ転送する。
正しい。bastion側9000へのconnectionをtunnel経由でclient側127.0.0.1:3000へ渡す。
ssh -N -L 9000:127.0.0.1:3000 bastion.example.testclient側port 9000をlistenするlocal forwardingである。
誤り。-Lはclient側9000をlistenするため要求したremote listenerにならない。
ssh -N -D 9000:127.0.0.1:3000 bastion.example.testdynamic forwardingで固定destinationのremote listenerではない。
誤り。-Dはdynamic SOCKS forwardingで、server側固定portを公開しない。
ssh -N -W 9000:127.0.0.1:3000 bastion.example.test-Wはstdioをhost:portへforwardするoptionでlisten port指定ではない。
誤り。-Wはstdio forwarding用でlisten endpointの方向を指定する-Rではない。
実際に確かめる
一時的な検証環境で実行できる例です。
printf '%s
' '-R=remote forwarding' '9000=remote listen port' '127.0.0.1:3000=client-side destination'期待される結果
-R=remote forwarding
9000=remote listen port
127.0.0.1:3000=client-side destination理解のポイント
- -Rはremote側listen
- GatewayPortsで公開範囲が変わる
- -Lと方向を区別
確認時の注意
- 確認環境: OpenSSH port forwarding構文(接続なし)
- 実SSH connectionやlistenerは作成しない。
基礎のおさらい
GatewayPorts
remote forwarding listenerがloopbackだけか外部addressへbind可能かはserverのGatewayPorts等で制御される。
公開risk
remote tunnelはclient側serviceをserver networkへ露出し得るため、bind addressとauthorizationを厳密にする。