[HOWTO] - SSH Port Forwarding of Mail due to a blocked port 25

DanInSFBay

Registered
This explains how to use SSH Port Forwarding of Mail, thru an ISP who blocks port 25 (e.g. sending from a hotel)

REASON:
Sometimes a remote location (hotel etc.) will block outgoing mail.
They do this by blocking outbound traffic destined for port 25.
By using SSH port forwarding, you can connect a remote MAC to your home or office MAC, forward mail traffic to it and then back out to your ISP as if you were sending mail from your home or office.


I looked for a simple answer to this problem and finding none, I decided to post my humble solution. There may be a better way, so gurus, please elucidate I and others.

I'm a new to SSH and also MACs, but this works on 10.3. Please feel free to add improvements to these instructions. I use a static IP address at home so I'm not sure how to do this with a dynamic IP.



First check to see that your home MAC firewall permits SSH:
1) Open "Sharing" in "Applications / System Preferences"
2) In the "Services" tab, Check "Remote Login" This opens SSH (port 22)
The SSH payload is encrypted and I'm sure you don't have any easy to guess user names or passwords, do you?


At your remote MAC, use TERMINAL in the Applications / Utilities folder:
1) Launch terminal.
(you will see)
MyRemoteMac:~ My-Remote-Mac-Login-Name$

2) Modify below (per instructions further below) and then copy and paste into Terminal at the command prompt.

ssh -l My-Home-Mac-Login-Name MyMacAtHomeIPAddress -L2500:MySendMail.MyISP.com:25


3) press return

(next you will see)
My-Home-Mac-Login-Name@MyMacAtHomeIPAddress's password:

4) type in the password for My-Home-Mac-Login-Name as prompted above

(next you will see)
Last login: Mon Aug 9 12:29:13 2004
Welcome to Darwin!
MyHomeMAC:~ My-Home-Mac-Login-Name$

5) Look for the confirmation that it worked (above "Welcome...")

6) Send mail using the special email account setup for ssh (see Mail Account Setup below for details)

7) When done emailing type "exit" in the same Terminal window as above.

(you will see)
MyHomeMAC:~ My-Home-Mac-Login-Name$ exit
logout
Connection to MyMacAtHomeIPAddress closed.
MyRemoteMac:~ My-Remote-Mac-Login-Name$

8) close Terminal (terminate)


NOTE:
The first time you use the command on a remote Mac you will need to accept a key as follows:
(note: there are other authentication methods, but this one is automatic and easy)

"The authenticity of host 'MyMacAtHomeHostName (MyMacAtHomeIPAddress)' can't be established.
RSA key fingerprint is Many:Hex:Bytes:For:The:Key
Are you sure you want to continue connecting (yes/no)?"

(you type)
yes

"Warning: Permanently added 'MyMacAtHomeIPAddress' (RSA) to the list of known hosts."

(back to step 4) type in the password for My-Home-Mac-Login-Name when prompted

My-Home-Mac-Login-Name@MyMacAtHomeIPAddress's password:

Last login: Mon Aug 9 12:29:13 2004
Welcome to Darwin!
MyHomeMAC:~ My-Home-Mac-Login-Name$

You are now logged into your home mac. (try typing ls -l)


You can make a TERMINAL SHORTCUT (filename.term) so you won't have to cut and paste.
Launch Terminal
1) Click menu File->Save
2) "Save As:" (give it a name)
3) select "Execute this command..."
4) paste your ssh command into the box
5) check "execute this command in a shell"
Now when you launch this icon, it will run the SSH command.


SSH COMMAND SETUP:

Change the ISP mail send settings (smtp) for different mail services as required (see below).

The localhost port 2500 (your remote MAC) was selected because:
1) it is typically unused
2) it won't conflict with other mail account setups because you *must* use a special email account setup.
(You could use 25 instead of 2500, but you will still need to modify the accounts and use sudo ssh...)

This requires a special mail account to be setup which uses 2500 for SMTP.
Your remote MAC sends mail on port 2500 which is forwarded to port 25 (SMTP) at MySendMail.MyISP.com via MyHomeMAC

The ssh command is configured as follows:

ssh -l login_name hostname
ssh login name on MyHomeMAC
ssh -l MyName My.Home.IP.Add

-L port : host : hostport
Use port 2500 : Forward mail to MyISP :at port
-L 2500 : smtp.MyISP.com : 25

(e.g.)
ssh -l Me 4.3.2.1 -L2500:smpt.MyISP.com:25


Help From MAN SSH
(type man ssh in Terminal for complete instructions)

-L port:host:hostport
Specifies that the given port on the local (client) host is to be
forwarded to the given host and port on the remote side. This
works by allocating a socket to listen to port on the local side,
and whenever a connection is made to this port, the connection is
forwarded over the secure channel, and a connection is made to
host port hostport from the remote machine. Port forwardings
can also be specified in the configuration file. Only root can for-
ward privileged ports. IPv6 addresses can be specified with an
alternative syntax: port/host/hostport

-l login_name
Specifies the user to log in as on the remote machine. This also
may be specified on a per-host basis in the configuration file.

For more info search on "ssh port forwarding"



MAIL ACCOUT SETUP Receiving mail:

MAC MAIL:

Description: Fwd Port 25 to MyISP (or whatever you like)
Email addr: (Same as your usual mail setup)
Full name: (Same as your usual mail setup)
Incoming Mail server: (Same as your usual mail setup)
User name: (Same as your usual mail setup)
Password: (Same as your usual mail setup)
Outgoing Mail server: 127.0.0.1 (this is also called "localhost")

"click SERVER SETUP"
Outgoing Mail server: 127.0.0.1
Server port: 2500
Authentication: (Same as your usual mail setup)



ENTOURAGE SETUP:

Account Name: Fwd Port 25 to MyISP (or whatever you like)
Name: (Same as your usual mail setup)
Email addr: (Same as your usual mail setup)
Account ID: (Same as your usual mail setup)
POP server: (Same as your usual mail setup)
PW: (Same as your usual mail setup)
SMTP server: 127.0.0.1

"CLICK HERE for ADVANCE SENDING OPTIONS"
Override default SMTP Port: 2500
Authentication: (Same as your usual mail setup)


Pseudo key words for search engines so others can find this forum post.
blocked outgoing mail, can't email from hotel, can't email from remote location, can't send email from hotel, can't send email from remote location, no outbound email, outbound email blocked.

DanInSanJose
 
Back
Top