0

I have a server listening on all interfaces for a port (using go net.Listen("tcp", ":{port}")). I also have backup server with the same code, to start if first server fails. Both machines using the same router which has an external IP address. Router assigns a private IP address to each connected device. A client dials the server using the external IP of the router (and given port).

While switching back from backup server to first server, both will be listening on all interfaces for a short while. There can't be multiple such listeners on the same machine, but can listen from different machines. My question is, what happens if there are multiple listeners listening on all interfaces for a port from different machines (having different private IP addresses) ? Where will the client connection happen ?

1 Answers1

1

No client connection will happen at all as long as you don't have any port forwarding at your router configured, which currently seems to be the case.

Once you have port forwarding configured, then the clients traffic to this port will be passed to the internal system specified as target in the port forwarding - there can only be one for a specific port. This means the internal system you setup in the port forwarding will be the one where the connection will happen.

Steffen Ullrich
  • 13,227
  • 27
  • 39
  • It is already tested with server running on 1 machine on random ports. – Lovish Puri Jul 01 '23 at 13:26
  • 1
    @LovishPuri This is confusing. You say you have port forwarding configured and your internal server is reachable from the outside world. Okay. When you configured your forwarding rule, you must have specified the internal private IP address and the port number that you want to forward. Here you decide which server you want to expose to the intenret. If you want the other sever to be exposed, you have to change the port forward rule to that second server's IP address... There is no interference by other machines listening on the same port as they have different IP addresses... – MoWo Jul 02 '23 at 07:46
  • I'm sorry. It was tested using public IPv6 address which I forgot about. I have configured port forwarding, and accepted the answer. – Lovish Puri Jul 13 '23 at 12:24