I have a multi-homed Windows 10 and I want my application to open a Server Socket on a specific IP given by its hostname.
My machine hostname is MY-PC
and it has a public IP 192.0.0.2/24
and a "direct" IP 192.2.2.2/24
(directly connected to another computer). Both are configured in the Windows Network Adapter page in the Control Panel.
No DNS is configured. My hosts file looks like:
127.0.0.1 localhost
192.2.2.2 MY-PC
192.2.2.1 DIRECT-PC
When I try to ping my hostname (after fully disabling IPv6):
> ping MY-PC
Pinging MY-PC [192.0.0.2] with 32 bytes of data:
Reply from 192.0.0.2: time<1ms
...
A strange thing is that the same setup (hosts file/network adapter configuration) works as expected on another computer (but just one out of six).
How can I force listening on a specific IP from a hostname? (which is a global parameter from a configuration received by the program).
I have already checked a related question but the answer is about fully disabling IPv6.