views:

693

answers:

1

How to do it? Like in windows, we have ForceBindIP see website

+1  A: 

Usually you bind your listening socket to INADDR_ANY (in C -- other variations based on language), which is basically 0.0.0.0. This means that a connection will occur if directed at any of the machine's configured addresses, including localhost (127.0.0.1). If you bind your listening socket to a specific address instead (in C you build this data structure the same way as you would for the remote end of a client-end socket), then the socket will be bound to that specific address. If your host has more than one address (not including localhost), then you can have multiple listening sockets bound to the same port number, as long as they're bound to different IP addresses, and none of them are bound to INADDR_ANY.

As a side note, if you bind to localhost, then only connections from the local machine will be accepted, because no other machine can communicate to that machine using that address.

Rob F