Score:0

Listening on all interfaces, multiple servers

nc flag

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 ?

Score:1
se flag

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.

Lovish Puri avatar
nc flag
It is already tested with server running on 1 machine on random ports.
br flag
@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...
Lovish Puri avatar
nc flag
I'm sorry. It was tested using public IPv6 address which I forgot about. I have configured port forwarding, and accepted the answer.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.