Tunnel via a Bastion Host

Recently had an issue where my NAS wasn't accessible via TailScale since docker failed to start at boot, so I had no way to remotely access it. I know you can forward ports via SSH, but I can never remember how to do it.

ssh -L <LOCAL_PORT>:<TARGET_IP>:<SERVICE_PORT> -N <USERNAME>@<BASTION_IP>

Luckily there was another device on the same network accessible via TailScale, so I just used that to access the NAS.

Example

This will forward port 9999 on your local machine to port 80 on the NAS via 100.42.103.21.

ssh -L 9999:192.168.51.100:80 -N example@100.42.103.21

Now that I've written this down, hopefully I dont forget 😅



Updated 225 days ago (7 Mar 2025)