SSH server bastion.example.testを経由し、local TCP port 8080への接続をinternal.example.test:80へ転送する。
remote commandは実行せずtunnelだけを維持する。
適切なコマンドはどれか。
ssh -L LOCAL_PORT:DEST_HOST:DEST_PORTはclient側でlistenし、SSH server側からdestinationへ接続する。-Nはremote commandを実行しない。
詳細解説
ssh -N -R 8080:internal.example.test:80 bastion.example.testremote側port 8080をlistenするreverse forwardingである。
誤り。-Rはserver側port 8080をlistenするため、local 8080という要件と方向が逆である。
ssh -N -D 8080:internal.example.test:80 bastion.example.test-Dはdynamic SOCKS forwardingでhost:port destinationをこの形で固定しない。
誤り。-Dはlocal SOCKS listenerを作り、固定destinationをargumentへこの形で指定しない。
ssh -N -X 8080:internal.example.test:80 bastion.example.test-XはX11 forwardingで一般TCP local tunnelではない。
誤り。-XはX11 protocol forwardingで、任意TCP local port mappingではない。
ssh -N -L 8080:internal.example.test:80 bastion.example.testlocal 8080をdestination host:80へforwardする。
正しい。local 8080からtunnelを通し、SSH server側からinternal.example.test:80へ接続する。
実際に確かめる
一時的な検証環境で実行できる例です。
printf '%s
' '-L=local forwarding' '8080=local listen port' 'internal.example.test:80=destination' '-N=no remote command'期待される結果
-L=local forwarding
8080=local listen port
internal.example.test:80=destination
-N=no remote command理解のポイント
- -Lはlocal側listen
- destinationはserver側から到達
- -Nでtunnel専用
確認時の注意
- 確認環境: OpenSSH port forwarding構文(接続なし)
- 実SSH connectionやlistenerは作成しない。
基礎のおさらい
destination視点
-Lのdestination host名は通常SSH server側で解決・接続されるため、clientから直接見えなくてもよい。
bind範囲
local listenerのbind addressを限定し、不要に他hostへtunnelを公開しない。