Solved

Forward SSH from port x to port y using Apache

Posted on 2014-09-11
10
316 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
 
LVL 61

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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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 61

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now