T
T
the_bizzon2017-05-24 21:35:11
linux
the_bizzon, 2017-05-24 21:35:11

How to connect via ssh through a third host (to a different subnet) with one command?

There is a server with two network interfaces 192.168.0.1 and 192.168.1.1
We are on the 192.168.0.0 network, on the other side the machine with the address 192.168.1.2
needs to connect to it via ssh.
Now I will ssh to the server and ssh from it to a machine on a different subnet.
The question is how to connect to a machine in another pdnet in "one touch"?
I do not want to configure routes, machines should not know about other subnets.
It looks like it can be done with 1 command.
You can also configure ~/.ssh/config

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
chupasaurus, 2017-05-24
@chupasaurus

For OpenSSH 7.3+
In ~/.ssh/config:

Host target
  Name 192.168.1.2
  ProxyJump gateway

Host gateway
  Name 192.168.0.1

T
the_bizzon, 2017-06-16
@the_bizzon

If necessary, through ~/.ssh/config, then
configure authorization by keys and
Write in the config:
HostName 192.168.0.1
Port 22
User user_name_host_1
Host host_2
HostName 192.168.0.2
port 22
User user_name_host_2
ProxyCommand ssh -A host_1 nc %h %p

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question