Forward TCP connections to port 9000 on bastion.example.test to 127.0.0.1:3000 as seen from the SSH client.
Run a tunnel only; do not execute a remote command.
Which command is appropriate?
ssh -R REMOTE_PORT:DEST_HOST:DEST_PORT listens on the server side and forwards through the tunnel to the client-side destination.
Detailed explanation
ssh -N -R 9000:127.0.0.1:3000 bastion.example.testCorrect. It makes remote port 9000 forward to the client-side destination.
Correct. It makes remote port 9000 forward to the client-side destination.
ssh -N -L 9000:127.0.0.1:3000 bastion.example.testIncorrect. -L makes the client side listen on port 9000.
Incorrect. -L makes the client side listen on port 9000.
ssh -N -D 9000:127.0.0.1:3000 bastion.example.testIncorrect. -D is dynamic forwarding, not a fixed remote listener.
Incorrect. -D is dynamic forwarding, not a fixed remote listener.
ssh -N -W 9000:127.0.0.1:3000 bastion.example.testIncorrect. -W forwards stdio to a host and port; it does not create a listener.
Incorrect. -W forwards stdio to a host and port; it does not create a listener.
Try it yourself
An example you can run in a temporary verification environment.
printf '%s
' '-R=remote forwarding' '9000=remote listen port' '127.0.0.1:3000=client-side destination'Expected result
-R=remote forwarding
9000=remote listen port
127.0.0.1:3000=client-side destinationKey points
- -R listens remotely
- GatewayPorts affects exposure
- Distinguish -L direction
Notes
- Environment: OpenSSH port forwarding構文(接続なし)
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.