My company has an intranet web server, only accessible from the LAN, used for web development as an integration server. Users in the LAN set their /etc/hosts to use the same Virtual Hosts defined in the integration server's Apache config, and so be able to connect to it using the standard port 80.

I work remotely sometimes, and can access the server through SSH using a custom port.

If I set my /etc/hosts to the public IP of that server, is there any way I could use the SSH connection with that custom port so that my browser connection is tunneled through it gets pages from that web server?

migrated from stackoverflow.com Sep 9 '11 at 12:08

This question came from our site for professional and enthusiast programmers.


I haven't quite understood your configuration but when you ssh to the company server you should be able to set up a ssh tunnel so that you can use browser to access company webserver.

You do not need to set up /etc/hosts on your local machine. Using the ssh parameter

-L port:host:hostport

All traffic to port on localhost is tunnelled to host/hostport on the remote. So, when you do

 ssh -L 80:web-server:80 user@ssh-server -p 22

http://localhost will be redirected to the web-server:80. Note that the hostport is translated on the remote server, i.e. the ssh server.

-p 22 is not needed if the ssh server uses the default port, but the question does say that the SSH server goes through a custom port. In that case, change 22 for the custom port.

If the system complains that Privileged ports can only be forwarded by root, run it as superuser:

sudo ssh -L 80:web-server:80 user@ssh-server -p 12345

or log as root.

  • The problem is the vhost on server side. It expects the HTTP query to include the correct server statement. Therefore the used hostname must be included in hosts file or the HTTP request must be altered. – Robert Sep 9 '11 at 12:46

SSH command-line version:

ssh -L 90:devserver:80 remotehost.example.com 

Now browse to http://devserver:90/

Remember that /etc/hosts must point to

With PuTTY, under SSH Tunnels:

  1. In Source Port enter 90
  2. In Destination enter devserver:80
  3. Click Add
  4. Remember to go back to session and click save.

Better than all the tunneling would be to get OpenVPN setup at the office.

  • The ssh command syntax is wrong, the -L 90:devserver:80 etc needs to come before remotehost.example.com. Also the /etc/hosts modification is not really necessary, better to not make any change there and use localhost:90 – Miserable Variable Sep 9 '11 at 11:56
  • @Hemal Pandya: Some Windows programs cough cough MSIE cough cough treat the literal value localhost as a special case (fixed in IE9 I think, but still applicable for older versions). – Piskvor Sep 9 '11 at 13:00
  • @Piskvor I don't know what special treatment MSIE give localhost but as others have pointed out the server may also expect to be called by a certain name so I stand corrected on that point. – Miserable Variable Sep 9 '11 at 13:59
  • @Hemal Pandya: IIRC it will always ignore any proxy when given localhost. The expected Host header that you mention is also a good point, haven't though of that. – Piskvor Sep 9 '11 at 14:02

I do the exact opposite. When at a customer I set up a secure ssh tunnel through tunnelier on my laptop to point to an external server with ssh server installed. Then I setup switchy in google chrome to enable forwarded traffic from my browser to the external server routed through ssh.


  1. Install switchy in your chrome browser (You could set up a proxy in ff/ie - switchy lets you easily switch between proxy configurations). Set SOCKS Host to and port to 1080.
  2. Setup Tunnelier client on your remote machine ie. your laptop / home computer and connect it to the company ssh server. Use port 1080 with "SOCKS / HTTP Proxy Forwarding" enabled.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.