I have a Java socket server that was created with ephemeral port (bind with port 0) on "
localhost". However, after it is up and running, the netstat shows that there is another process listening to the same port on any interface.
$ sudo netstat -n -a -p | grep 34797 tcp6 0 0 127.0.0.1:34797 :::* LISTEN 4210/java tcp6 0 0 :::34797 :::* LISTEN -
rpcinfo, I confirm that it is the NFS
nlockmgr. I can reproduce the issue with the socket server binds to the same
34797 port explicitly.
It is only true for ports used by NFS services (
nlockmgr). If I try to do the same with a port already bind on the
:: any interface by an existing application, it will result in bind "
Address already in use" error, which is what I expected.
This is problematic for me as it messes up the service that I am running for receiving requests.
My question is, why the NFS services are so special and why does Linux allow this to happen (by allocating an ephemeral port that is already in use)?