Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
net: unable to bind the specified network card to establish a TCP connection #39293
Failure to bind to the specified network card will occur on some machines. I wanted to connect from 192.168.1.101, but actually went to the 126.96.36.199 network card, but the source address of the packet was 192.168.1.101. Very strange.
golang version : go1.14
You don't bind a socket to a network card, you bind it to a local IP address (and port). The routing system (using the routing table) determines where the traffic goes. So, it is not strange that the source address for outgoing packets is the address you bound the socket to. That is always the case. Now, Windows by default uses the strong host model, which means that outgoing packets must have a source address that is assigned to the outgoing network interface. This rule is also used to make the routing decision, so if you force the local IP address by binding a socket to an address, then for an outgoing packet a route will be selected that satisfies the requirement. So if the routing table contains several possible routes to a destination, for example Wi-Fi and Ethernet both with a default route, then if you bind a socket to the Wi-Fi address, then packets will be routed using the default route on the Wi-Fi interface even if the Ethernet interface has a default route with a lower metric. This is because the strong host model does not allow packets going out on the Ethernet interface with the source address assigned to the Wi-Fi interface. If I interpret @caleb-letsgo 's issue correctly, this behavior was what was expected. Now for the Windows devices where it doesn't work this way, these devices probably are configured to use the weak send model instead. Note that most other systems such as Linux do not support the strong host model at all, so they always work as your two problematic Windows systems.