Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a linux server, and I want to put it in a home network behind a router. I need to ssh to this server sometime from outside, but I don't want to set up port forwarding because I don't have access to the router, and I don't know the ip of the router either.

What I can do is to put some program in the linux server, so when it is connected to Internet, it will constantly sending data to my other server online so I know the ip address of it. But is there a way to ssh to the server behind the router from outside? something like NAT or socket that maintains the network connection?

Thanks a lot

share|improve this question

migrated from serverfault.com May 15 '13 at 18:58

This question came from our site for professional system and network administrators.

add comment

2 Answers

up vote 3 down vote accepted

What you would want to do is ssh FROM your "linux server" TO something on the outside, such as "my_other_server" or something else both servers can get to.

You would use ssh remote port forwarding.
[user@linux_server]$ ssh -R8022:localhost:22 my_other_server.com
Explaination: Connect to my_other_server and open port 8022 there which will forward back to me on port 22.

From my_other_server.com you will be able to ssh to localhost on port 8022, and have your traffic forwarded to linux_server piggybacking on the linux_server -> my_other_server tunnel [user@linux_server]$ ssh -p8022 localhost
Explaination: Connect to myself on port 8022 which is forwarded to linux_server

If you have problems with the initial linux_server -> my_other_server tunnel dropping out, you could make a script to keep it open, adjust the keepalive settings, or use autossh.

share|improve this answer
    
Thanks, that works great! I want to use script to keep it open. The other question is what if I have like 1000 such 'linux server' and only one 'my_other_server', can I ssh to any of them this way? I assume they all need different port and is there a better way to do so? –  Jiechao Li May 15 '13 at 21:45
    
Well that depends. Now that you are on linux_server, could you just ssh to linux_server2 and linux_server3 from there? That would be the easiest. So yes you could do this several times over, instead of using 8022 you'd use 8023, 8024. If you go that route, build a ~/.ssh/config file on "my_other_server" that contains all of the port numbers, so you just ssh [alias] instead of ssh [port] localhost. That will become cumbersome. –  khaki54 May 16 '13 at 16:12
add comment

You can use a VPN of sorts to get this working, but it would require you to have a server that the inaccessible server can access. Then you can set up OpenVPN on the server, your PC, and the firewalled server, enable client-to-client, and you're done. http://openvpn.net/howto.html

share|improve this answer
    
Thanks. I am looking into this, but it seems a little complicated. If I understand correctly, I need to install OpenVPN on both server so they can communicate without configuring the router, right? –  Jiechao Li May 16 '13 at 2:39
    
Exactly. You configure a server as the "server", then the two clients you want connected together as "clients" in the config. The reverse SSH noted above seems to be easier for you, though. –  Nathan C May 16 '13 at 11:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.