ssh port forwarding notes

mySQL access using ssh:

  1. open terminal
  2. ssh -L 3306:[username]@[database system]:3306 [username]@[ssh gateway]

Tunneling to an internal system using ssh:

  1. open terminal
  2. ssh -L 7777:[username]@[internal system]:22 [username]@[ssh gateway]
  3. open a second terminal
  4. ssh -p 7777 [username]@localhost

Tunneling to an internal IMAP server through ssh when away from the office:

  1. open terminal
  2. update your /etc/hosts file to override the DNS entry for your internal server with localhost:
    1. 127.0.0.1 imap.example.com
  3. open terminal and execute the following:
  4. sudo ssh -i ~/.ssh/id_dsa -L 993:[internal imap server address]:993 [username]@[ssh gateway]
  5. once logged into the ssh gateway server you may need to keep the connection from timing out by issuing a command such as this:
  6. vmstat 30

Notice that the command is issued as root, this is to allow the forwarding of a privileged port (993 if the connection is SSL encrypted or 143 if not). By forwarding the privileged port there is no need to change any of the settings in you email program since the /etc/hosts file overrides the DNS lookup of your mail server.