7

I want to create ssh tunnels between 2 clients and 1 server. Can I use the same port numbers for both but binding one of them to 127.0.0.1:N and the other to 127.0.0.2:N ? Are these ports same or can I use them separately ?

  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could post and accept your own answer. – Ron Maupin Jan 04 '21 at 01:37

3 Answers3

4

Can I use the same port numbers for both but binding one of them to 127.0.0.1:N and the other to 127.0.0.2:N ?

Yes, you can use the same port number on two different 127.X.X.X addresses.

Are these ports same or can I use them separately ?

You can use them separately.

See illustration below.

lab@ubu10:~$ nc -l 127.0.0.1 2000 &
[1] 1035
lab@ubu10:~$ nc -l 127.0.0.2 2000 &
[2] 1036
lab@ubu10:~$ netstat -l -n
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.2:2000          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:2000          0.0.0.0:*               LISTEN
Everton
  • 1,636
  • 12
  • 24
1

It's not clear in your question whether you are tunnelling between both clients via the server, or tunnelling from each client to the server.

In either case on the client side, you can bind locally to the same IP/port on both sides e.g.:

ssh -f client@server.com -L 2000:server.com:22 -N

This will map 127.0.0.1:2000 on each client to the tunnel which terminates on the server.

On the server side, you will simply see the public IP address of each client, which will have (possibly) unique source IPs bound to unique source ports.

Benjamin Dale
  • 9,296
  • 17
  • 46
0

if you bind to port+ip you can use them separately.

  • Can you explain how can I do that ? I tried "ssh -N -R [127.0.0.2]:2222:host:port user@host" but it didn't work. – Bünyamin Sarıgül Sep 09 '15 at 10:43
  • openssh should have -L [bind_address:]port:host:hostport – Stefano Sasso Sep 09 '15 at 14:08
  • @StefanoSasso are you actually trying to use 127.0.0.0/8 addresses? That won't work since those are the loopback addresses that will immediately loop the traffic back inside the sender. A loopback address is only useful internal to a host. For multiple hosts, you need to use a different address range. – Ron Maupin Oct 09 '15 at 14:23
  • @BünyaminSarıgül Perhaps you need 2 tunnels: tunnel1: ssh -R 127.0.0.1:3000:127.0.0.1:2000 user@remotehost --> will forward 127.0.0.1:3000(at remotehost) to 127.0.0.1:2000 tunnel2: ssh -R 127.0.0.2:3000:127.0.0.2:2000 user@remotehost --> will forward 127.0.0.2:3000(at remotehost) to 127.0.0.2:2000 – Everton Jan 07 '16 at 12:05