I am using a reverse SSH tunnel to expose a webserver within my network to the internet.
The “inside server” is behind a firewall within a network. The “outside server” is an Ubuntu server with a static IP address. The outside server has GatewayPorts enabled in the
/etc/ssh/sshd_config file. From the inside server I run this command:
ssh -p22 outsideuser@<<outside domain>> -f -i /root/.ssh/id_rsa -R 45000:localhost:80 /home/user/stall.sh $port
After I run this script I can open a terminal on the outside server and run
netstat -nat and see this:
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:45000 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 284 <<outsideip>>:22 <<insideip>>:58313 ESTABLISHED tcp 0 0 <<outsideip>>:80 <<insideip>>:46478 TIME_WAIT tcp 0 0 <<outsideip>>:22 <<insideip>>:35630 ESTABLISHED tcp6 0 0 :::45000 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN
I can then go to:
... and it successfully loads the web content at:
http://<<insideip>>/ (port 80)
The only issue is that it stops working after that initial request. When I run
netstat -nat again on the outside server this line is now missing from the output:
tcp 0 0 0.0.0.0:45000 0.0.0.0:* LISTEN
I am able to telnet to port 45000 multiple times without breaking the connection. So it seems to be something related to making the request from a browser. Also, it seems that I can wget the over this connection as many times as I want but the first time I access it with a browser it breaks the connection.
I’ve been pulling my hair out trying to figure out what I'm doing wrong. Any ideas?