The private IP address of my machine is If I started a process using

nc -l localhost 20000

Then this process won't handle requests sent to

Since the process listening to localhost:20000 does run on the physical machine with LAN IP being, I'm trying to know how the process ignores the requests to

Is it true that these requests are ignored by the process, or such requests are not delivered to the network interface of at all? Is this a network-layer mechanism, or link-layer mechanism?

  • 1
    The process doesn't ignore those requests - the process won't even notice the request. Dec 3, 2012 at 19:09

2 Answers 2


When you set up a listening socket, you can pick which local address it is bound to. This is done with the bind(2) system call. (You can also choose to bind it to, which means listen on all local addresses).

You told netcat to listen on localhost. So it called bind(2) with (or similar) as the socket address. So the kernel bound the listening socket to only that address.

When a connection request came in to the kernel looked at the list of listening sockets, and found none. So the kernel refused the connection.

When a request comes in to, the kernel will find the listening socket, and the accept(2) syscall will tell netcat about it.

To have netcat listen on all interfaces, omit the host: nc -l -p 20000 or alternatively specify nc -l -p 20000. You can also specify the specific IP address you want it to listen on as well (, but then of course nc localhost 20000 will be rejected.

(Binding to localhost is often done when you only want to allow connections from the same machine, e.g., for security reasons.)


Every socket has 2 characteristics associated with it. Address and port. Socket listening on every interface actually listens on an address INADDR_ANY, which is, so since you tell the socket it's listening on it will ignore all requests to other addresses of the machine.

  • On most unixes, you can also have an interface bound to the socket. But very few programs support the option, as it is not portable, especially on non-unix systems.
    – BatchyX
    Dec 3, 2012 at 20:09
  • @BatchyX True but that is a topic advanced beyond the scope of this question.
    – Karlson
    Dec 3, 2012 at 20:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .