- Why Use Port Forwarding?
- What You Need to Use Port Forwarding
- Using Port Forwarding Under Mac OS X
- Additional Port Forwarding Information and Resources
Using Port Forwarding Under Mac OS X
Establishing a port forwarding SSH connection is almost as simple as establishing an SSH connection. To establish a basic SSH connection from the Terminal, you enter the command ssh followed by the DNS name or IP address of the computer that you want to connect to (you can find the appropriate address from the Sharing pane in System Preferences when you enable Remote Login). For example:
SSH will attempt to connect using the same username that you used to log in to your local computer and, if successful, will prompt you for a password that allows you to log in to the remote computer. If the username is different, you should specify it in the ssh command and specify that the account resides on the computer you are connecting to. (You might specify an alternate computer if you are in an environment in which user accounts reside on directory servers, such as Mac OS X Server’s Open Directory, but that’s beyond the scope of this article). For example:
Once you log in, you see a command prompt for the remote computer and you can do anything that you could from the command line as if you were sitting at that computer.
To enable port forwarding, you need to add –L to the command as well as port number to use for forwarding through the secure connection and the IP address or DNS name of the server to forward requests for the standard port for the chosen protocol. You need to format the command as "ssh –L" followed by the port number to use, a colon, the DNS name or IP address of the remote computer, a colon, and the traditional port number for the protocol. Finally, you need to include the computer that will handle the forwarding (that is, the one to which you are issuing the SSH commands), which can be done in the same manner as specifying a user account on that computer.
For example, if I want to forward all file sharing requests through an SSH connection to a Mac for a remote network, I enter the command as follows:
ssh –L 9099:remotefileserver.com : 548 email@example.com
If you want to establish a connection solely for the purpose of port forwarding and have no intention of managing the remote computer from the command line, you can also add –N to the command to specify to SSH that you don’t want to establish a shell login. You can also bundle several port forwarding instructions into a single command.
In addition to telling your local computer to forward requests of certain types to a remote computer, you can also use port forwarding to specify that a remote computer should send any requests it has to your local computer (or even another remote computer). The process is the same thing, except in this case you will substitute –R for –L in the command. This process is known as remote port forwarding. Remote port forwarding can be used to tell a computer acting as a router to forward certain types of traffic out for the network.
If all this talk of managing port forwarding from the command line seems too confusing and you wish that there were a graphical tool for using port forwarding, you’re in luck. Tynsone.org provides a tool called SSH Tunnel Manager that can make the process a little simpler.