LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to ssh to computers on LAN from a proxy that has public IP (https://www.linuxquestions.org/questions/linux-networking-3/how-to-ssh-to-computers-on-lan-from-a-proxy-that-has-public-ip-801810/)

tkmsr 04-13-2010 02:20 PM

How to ssh to computers on LAN from a proxy that has public IP
 
I have a PC which has a Public IP.It is a webserver but it is not a proxy server.I want to be able to do an ssh to the machines which are behind this webserver on LAN in one step.

Right now I do an SSH to this webserver and then do an SSH to any other machine on my LAN how can I do it in one step.

rweaver 04-13-2010 02:35 PM

You'll likely want to setup some kind of port forwarding pseudo-proxying. Check out this article, its a bit old but generally relevant.

http://tldp.org/HOWTO/IP-Masquerade-...orwarders.html

Skaperen 04-13-2010 04:38 PM

You could make a script that first connects via SSH to the webserver in the background, with port forwarding configured to make connections to the interior machine's SSH port. Then it would start a 2nd SSH towards the forwarded port on the local host, which will get carried through the first SSH's forwarding and connect to the interior machine. If there are many interior machines, this can get more complicated. I have something similar set up, in reverse (connections come out to let me go in), done through cron jobs.

tkmsr 04-14-2010 12:07 AM

Thank you all for your support.I found this article useful
http://www.debian-administration.org/articles/73
Ya portforwarding via IPTABLES is required.
and this post was also helpful after I got a clue to forward ports
http://www.linuxforums.org/forum/lin...orwarding.html

If some one comes for the same problem here
It should be some thing like this
Code:

iptables -A PREROUTING -i eth1 -p tcp -m tcp --dport 3000 -j DNAT --to-destination 192.168.1.9:22
iptables -A INPUT -i eth1 -p tcp -m tcp --dport 3000 -j ACCEPT
iptables -A FORWARD -i eth1 -p tcp -m tcp --dport 3000 -j ACCEPT

The destination and ports will change according to your internal setup.The above IPTABLE rule will be used on the machine that is your router or Gateway.To forward a request coming on port 3000 on router to a machine internal 192.168.1.9 at port 22 where SSH runs.
192.168.1.9 is the IP of internal machine which I want to access from internet via outside.I have used port 3000 you can use any from 1024 onwards.
Suppose you are at a coffee shop outside and you want to access your machine behind the router
you will do
Code:

ssh Public IP of router:3000 -lusername
The following article is also useful
Code:

http://www.hackorama.com/network/portfwd.shtml


All times are GMT -5. The time now is 01:55 AM.