0

I have an interesting problem right now. On a Windows Server 2012 R2 I have two IP addresses, say 192.0.2.1 and 192.0.2.2. On one address e.g. 192.0.2.1 a web server runs on port 80, which is implemented in C# using HttpListener. At the other address e.g. 192.0.2.2 I try to open port 80 using a Go program and http.server{}. The Go program receives an error message that the port cannot be opened. The C# program is started first. I start the Go program with administrator permissions.

When I use netstat to check which ports are in use on which addresses, the second address 192.0.2.2 is completely unused. Port 80 is only opened by the C# program at the first address i.e. 192.0.2.1.

It makes no sense at all. Am I missing something?

I had a similar scenario two weeks ago with Ubuntu and two Go programs, both using port 443 on different IP addresses. That was no problem at all and ran immediately.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122

1 Answers1

1

The web server needs to be configured to bind to the intended IP address only. If its configured to bind to any address you can't use the same port with any other address.

Plain netstat only displays connected sockets. You need to use -a to display the listening, possibly unconnected ports. Any port that is allocated for listening cannot be used in another way. Using -ao is also handy as it'll display the PID alongside the port.

Zac67
  • 8,639
  • 2
  • 10
  • 28