Port redirection on outgoing connections

I have a remote server that I SSH into, which uses a nonstandard port. Is it possible to redirect outgoing connections directly to that port?

Diagram:


Me -> connect to server1 port 22 -> PF rewrite port 22 to port XXX -> connect to server on port XXX.
 
Sure.

Something like:

Code:
rdr pass on $ext_if inet proto tcp from $somehost to $someserver port 22 -> $someserver port 22332

or you can try the rdr statement on the $int_if if it doesn't work. You may also need additional pass rules depending on what and how you are already filtering. Make sure you check your pflog0 with tcpdump.
 
While that's doable, wouldn't it be simpler/cleaner to just add a host entry into your ~/.ssh/config file to set the port in there? Then you can just SSH to it via $ ssh someserver.org and OpenSSH will handle setting the port correctly.

I'm guessing the impetus for this thread is the OP doesn't like adding -P 12345 everytime they connect.
 
Or you can just write a simple connect script ('go_server') that makes the ssh connection to the desired port.

There's always more than one way ..
 
Heh, I forgot I posted this. Glad I remembered.

The following worked:

Code:
rdr on $int_if inet proto tcp from any to $srv port 22 tag SOMETAG -> $srv port xxx

I prefer this method because it saves reconfiguring every client machine for the change.
 
Back
Top