SSH Port Forwarding Through a Proxy ServerTerry Labach, January, 2005 A common use of SSH is port forwarding (tunneling). This use causes traffic directed to a particular port to be sent to a specified port on another computer. Because traffic is sent through SSH, the traffic is encrypted, allowing the transmission of sensitive data through arbitrary services.
Example: Tunneling Connections From a Local Host on Port 8080 to Port 80 on a Web ServerThe following command is an example that would tunnel connections from a local host on port 8080 to port 80 on the web server ssh -N -L 8080:localhost:80 www.my-domain.com In the preceding command:
Example: Accessing a Corporate Network Web Server That Allows Logins Through a Proxy ServerIt follows that one could create a sequence of secure tunnels, linking one computer to another through intermediate computers. The most likely use for this scenario would be to enter a private network that requires external logins to be performed through a proxy server. Suppose you wanted to access a web server in a corporate network that allowed logins through a proxy server. This could be done in two steps: 1. Log in to the proxy server using SSH, while simultaneously creating a tunnel. Use the following command: ssh -l proxyuser -L 8080:localhost:8181 proxy.my-domain.com This command logs the user 2. Once logged in, create a second tunnel from the proxy server to the internal server: ssh -l internaluser -L 8181:internalserver:80 internalserver However, SSH can be used to run arbitrary commands on a remote machine. This capability allows you to create the tunnel in one step, with a single command line: ssh -t -l proxyuser -L 8080:localhost:8181 proxy.my-domain.com \ ssh -l internaluser -L 8181:internalserver:80 internalserver The After you run the command, a user has a login session on the internal machine, and local port 8080 is forwarded to port 80 on the internal machine. When the user logs out of the internal machine, the port forwarding stops. A Practical Application: Allowing Remote Access to the Perforce Master Source RepositoryAn example of a practical application of this technique comes from a solution I created for a client. Software developers using the Perforce source-code management system wanted remote access to the master source repository. Their corporate firewall software did not support Linux-based VPNs. For those developers using laptops or developers whose ISPs did not provide static IP addresses, access could not be provided through the firewall based on IPs. To allow remote use of Perforce under these restrictions, I decided to tunnel the connections. To create a tunnel for Perforce through SSH, clients run the following command, entering pass phrases or passwords as prompted: ssh -P -t -l proxyuser -L 1616:localhost:2468 proxy.my-domain.com \ ssh -l internaluser -L 2468:internalserver:1616 internalserver The ConclusionSSH tunneling through a proxy server can be done quickly and simply using a single command line, providing transparent, secure access to network services. Note
About the AuthorTerry Labach has been a system administrator since the last century, supporting the Solaris OS and other versions of UNIX. He holds university degrees in Physics and Computer Science.
The information and links on this page have been provided by a BigAdmin user. The submitter is solely responsible for such information and links. Sun is not responsible for the availability of external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. Sun will not be responsible or liable, directly or indirectly, for any actual or alleged damage or loss caused by or in connection with use of or reliance on the information posted here, or goods or services available on or through any external site or resource. Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
| |||