Ubuntu – SSH tunnel works through localhost but not by IP address or DNS lookup

domain-name-systemsshssh-tunnelUbuntu

There are two computers at my work – one which has a public IP address and another computer which has an Apache server running a browser-based application on port 80. Port 80 of the computer with the public IP address receives traffic with the DNS public.domain.edu. Port 80 of the computer with the Apache server is not public, but can be accessed on the local network through private.domain.edu.

I want to create a local SSH tunnel from the public computer's port 80 to the computer with the Apache server implemented. So far, I have tried this command from the computer with the public IP address:

    sudo ssh admin1@private.domain.edu -L 80:private.domain.edu:80  

When I run this particular command, I can access the web application on private.domain.edu by running a browser on public.domain.edu and typing "localhost" in the address bar. However, when I type in public.domain.edu's IP address in the address bar, it does not tunnel to private.domain.edu's application but instead says that the URL could not be found. Moreover, when I type the DNS lookup for public.domain.edu on the address bar, it still does not work.

How do I fix the SSH tunnel it so that, when I type public.domain.edu (or its IP address) on the address bar, I access private.domain.edu's web application?

Best Answer

Try sudo ssh admin1@private.domain.edu -g -L 80:private.domain.edu:80. As the man page notes:

-g Allows remote hosts to connect to local forwarded ports.

Note, though, that this probably isn't the best way of accomplishing what you're trying to do. If you want to enable access to an internal web application from outside, but just for yourself, a VPN of some kind would be less subject to abuse; if you want to enable it for all, talk to your local network admin and get a port punched through the firewall.