LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-17-2018, 03:27 PM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Rep: Reputation: 3
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.
 
Old 05-18-2018, 03:22 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
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/

Last edited by michaelk; 05-18-2018 at 03:24 PM.
 
Old 05-18-2018, 03:25 PM   #3
aristosv
Member
 
Registered: Dec 2014
Posts: 263

Original Poster
Rep: Reputation: 3
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
 
Old 05-18-2018, 03:38 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,680

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] using ssh on remote computer to connect to home computer behind two routers Volofrog Linux - Networking 8 12-25-2012 03:02 PM
Configuring SSH on Ubuntu to connect to remote computer guitarman Linux - Networking 14 11-06-2012 07:07 AM
[SOLVED] Connect to external computer using local address Krzysztow Linux - Networking 5 04-13-2011 09:56 PM
How can get local and remote IP address from TCP connect? yhus Programming 2 09-07-2009 01:34 PM
Opening remote files (during ssh session) with applications on local computer? The_Fed Linux - Newbie 3 05-10-2004 04:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration