LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   connect from the ssh server to the remote computer using a local ip address (https://www.linuxquestions.org/questions/linux-networking-3/connect-from-the-ssh-server-to-the-remote-computer-using-a-local-ip-address-4175629906/)

aristosv 05-17-2018 03:27 PM

connect from the ssh server to the remote computer using a local ip address
 
I have a remote Linux computer connecting on a local ssh server, creating a reverse ssh tunnel on port 5051. On the ssh server itself I run the following two commands, in order to give the remote computer a local IP address.

Code:

ip addr add 192.168.1.51/24 dev eth0
iptables -t nat -A PREROUTING -d 192.168.1.51 -p tcp --dport 22 -j REDIRECT --to-port 5051

On the ssh server I have also configured GatewayPorts yes in sshd_conf.

From a third computer on my network if I ssh on 192.168.1.51, I connect directly on the remote Linux computer.

But from the ssh server if I ssh 192.168.1.51 I connect on the ssh server itself again. I don't connect on the remote computer. The only way to connect on the remote computer from the ssh server is to use ssh root@localhost -p 5051

But I don't want to do that. I want to be able to ssh 192.168.1.51 from the ssh server, and connect on the remote computer.

michaelk 05-18-2018 03:22 PM

This may not be the answer you are looking for but it is simple. If you create a ~/.ssh/config you can add an alias for your remote computer and no need to specify address or port.

https://www.google.com/amp/s/www.cyb...inux-unix/amp/

aristosv 05-18-2018 03:25 PM

Thanks for the reply. Eventually this did it.

iptables -t nat -A OUTPUT -d 192.168.1.51 -p tcp --dport 22 -j REDIRECT --to-port 5051

michaelk 05-18-2018 03:38 PM

By the way prerouting does not work for localhost which caused your intial problem and just thought of the rule you posted...


All times are GMT -5. The time now is 10:48 PM.