I have a server in my office behind a firewall, a home server behind NAT, and a laptop I carry around. Sometimes I want to reach the office server from home so I did the following setup.
Home router redirects port 2223 to homeserver port 22.
I am running a reverse-tunnel from the office, using autossh and a systemd unit:
[Unit]
Description=Call home using port 2223 and reverse tunnel 22222 into 22
After=network.target
[Service]
User=atilla
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -p 2223 -N -R 22222:localhost:22 atilla@my_home_ip
[Install]
WantedBy=multi-user.target
On my homeserver, I can do ssh -p 22222 localhost and connect to the office server. However, when at home, doing ssh -p 22222 homeserver.local, the connection gets refused. I always have to log into homeserver and do another hop.
The office server uses latest Raspbian, homeserver is on Ubuntu 22.04, all default settings.
0.0.0.0:22222to have it listen on all ports, but then any thing in your home network can connect to it