Forward SSH from port x to port y using Apache

One of my Ubuntu servers is running Atlassian Stash which runs an additional SSHD instance on a nonstandard port.  Unfortunately, I need to connect via a DIFFERENT nonstandard port that is in the range I got opened on my ISP's firewall. As far as I can tell, I cannot change what port that uses. :(

Can Apache forward SSH from port x to port y for me?  I really don't want to need to install HAProxy just to do this.

LVL 32
Daniel WilsonAsked:
Who is Participating?
Kent WConnect With a Mentor Sr. Network / Systems AdminCommented:
Once you have it installed, it's quite simply as easy as, say if you want to redirect port 23 to 22 -

balance 23 localhost:22

Open in new window

You can then hit port 23 with ssh

many more options, but that simple.

It does not run as a service, but I just create a "" script, and place it in the rc.local, so it fires up at startup.

BalanceNG ($) will run as a service I believe.  Never tried the paid product.
Kent WSr. Network / Systems AdminCommented:
I'd suggest using "balance", a very simple port redirect / load balancer that simply listens on one port, forward to another.  It doesn't care if it's local, remote, etc.

Works very well, is very easy to admin.
Daniel WilsonAuthor Commented:
I'm checking that out, mugojava.  I need something simple!
A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

gheistConnect With a Mentor Commented:
SSHd on port 22 can do all port forwarding you need.
savoneConnect With a Mentor Commented:
You can use iptables to redirect the port.

iptables -t nat -A PREROUTING -p tcp --dport 2222 -j REDIRECT --to-port 2222
Kent WSr. Network / Systems AdminCommented:
I use more Centos, so just checked and balance is available via apt-get.

Quite simply
sudo apt-get install balance

Then pump in the command I gave above with the appropriate ports, and you are redirecting.
Just make sure your firewall is not blocking your selected port.
R 2222 <enter>
Apt-get is a Debian package manage not available on centos without work.
Kent WSr. Network / Systems AdminCommented:
OP is using Ubuntu. It's Debian.
Daniel WilsonAuthor Commented:
Thanks to all of you!  I got started with balance, so I think I'm OK with that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.