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.
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 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.