Ssh – Forward all ports SSH

port-forwardingsshssh-tunnelingtunneling

I have a question about SSH/Port forwarding. I haven't found the solution anywhere and don't know if there is any.

I have a server behind my NAT box at home. I have port forwarding from my NAT box to my server for SSH on port 22. Hence, I connect to my_nat_public_ip:22 when I'm on the go and it works like a charm.

Now I know that I can access any port of my server as well even without configuring my NAT box for it. Indeed, I can just do a dynamic port forwarding like this:

ssh -D 1080 user@my_nat_public_ip

Then connect to port any_port of my server by settings my browser or else to use localhost:1080 as SOCKS proxy, and point to my_local_server_ip:any_port.

What I would like to do, would be a command like

ssh -D --local_alias=local_alias user@my_nat_public_ip

and if I access local_alias:any_port it forwards to my_server:any_port

Would that be possible? Is there any SSH option to do this? It is just plain simpler and makes it possible to have multiple dynamic port forwarding on different servers.

Best Answer

That's a tricky thing to get done. Your best bet is to use some SOCKS redirector like socksify or redsocks, but none will give you what a VPN can, so you'd better set it up. VPN allows you to connect even whole networks, forward your traffic through secure channels, make your computers all appear as in one LAN and so on.

You can use OpenVPN to do that - there's a pretty good documentation on it's site, though it might require some knowledge about networking to decide what and how you want.

However, if you don't wish to use it, but want to stay with SSH instead - you may refer to SSH-BASED VIRTUAL PRIVATE NETWORKS section of man ssh or https://help.ubuntu.com/community/SSH_VPN, which describes the topic pretty well.