Solved

Forward SSH from port x to port y using Apache

Posted on 2014-09-11
10
346 Views
Last Modified: 2014-09-12
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.

Thanks!
0
Comment
Question by:Daniel Wilson
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:Kent W
ID: 40317940
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.

http://www.inlab.de/balance.html
0
 
LVL 32

Author Comment

by:Daniel Wilson
ID: 40317963
I'm checking that out, mugojava.  I need something simple!
0
 
LVL 12

Accepted Solution

by:
Kent W earned 300 total points
ID: 40318018
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 "balancing.sh" 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.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 62

Assisted Solution

by:gheist
gheist earned 100 total points
ID: 40318095
SSHd on port 22 can do all port forwarding you need.
0
 
LVL 23

Assisted Solution

by:savone
savone earned 100 total points
ID: 40318172
You can use iptables to redirect the port.

iptables -t nat -A PREROUTING -p tcp --dport 2222 -j REDIRECT --to-port 2222
0
 
LVL 12

Expert Comment

by:Kent W
ID: 40318298
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.
0
 
LVL 62

Expert Comment

by:gheist
ID: 40318299
~.(enter)
R 2222 127.0.0.1:22222 <enter>
0
 
LVL 23

Expert Comment

by:savone
ID: 40318314
Apt-get is a Debian package manage not available on centos without work.
0
 
LVL 12

Expert Comment

by:Kent W
ID: 40318381
OP is using Ubuntu. It's Debian.
0
 
LVL 32

Author Closing Comment

by:Daniel Wilson
ID: 40320425
Thanks to all of you!  I got started with balance, so I think I'm OK with that.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question