16

I am using Fedora 13 64bit. My eclipse program starts a server on port 9050 but I shutdown the program, eclipse fails to properly shutdown the server. Restarting eclipse has no effect.

How can I close or unbind a port forcibly from command line?

I know rebooting or log off and back on will clear the ports but this much slower process for me. I am looking for forcibly closing the port in command line.

6

The only way to forcefully close a listening port is to kill the process that is listening on it. Use lsof, netstat, fuser – as root – to find out the process ID. Once the process exits (by itself or by being killed), the kernel will automatically clean up all sockets it had open. (However, there might be cases that programs will be denied listening on the same port for a few minutes; in this case all you can do is wait.)

16
lsof -n -i

Find the process you're looking for and kill it.

From lsof manual:

-n This option inhibits the conversion of network numbers to host names for network files. Inhibiting conversion may make lsof run faster. It is also useful when host name lookup is not working properly.

-i [i] This option selects the listing of files any of whose Internet address matches the address specified in i. If no address is specified, this option selects the listing of all Internet and x.25 (HP-UX) network files.

Same answer to this question I think.

  • 4
    Throw on | grep ":9050" (or whatever port number) to easily filter the output – isaacparrot Jun 10 '14 at 0:28
4

You can user the fuser command with the -k switch.

For example, to close port 111, you can do the following: fuser -k 111/tcp (this also saves you the hassle of find the ID of the process to kill it as fuser does in implicitly)

Note that some processes restart automatically once closed. For that, you need to check each process's config file to come up with an appropriate workaround.

-3

I had the same issue, just look for the process whicj is listening that port using cmd command on windows

netstat -a -b

then you can shut it down with tasks manager

  • 2
    Sorry, I downvoted. You mention "on Windows". The "-b" parameter to netstat, which shows executable names, is specific to Microsoft Windows. (Unix netstat variations may have similar functionality, but is typically not using that same parameter.) However, the question said "Fedora", so the asker of this question was looking for information about Fedora 13 64bit, a different operating system. netstat's man page for Fedora indicates that using -p shows the PID (which can be used to identify the executable's name). – TOOGAM Jul 2 '16 at 11:14
  • 1
    There are several mistakes in this answer. The answer contains a grammatical error which could have been avoided. The answer also is not applicable to Fedora, which is clearly mentioned, in the first sentence of the question. It isn't like the question didn't contain this information when this answer was submitted 30 minutes ago, the question has not been edited since July 2011, which nearly 5 years ago. So I am taking this answer for what it is, a "me too" answer, which very rarely actually helpful. – Ramhound Jul 2 '16 at 11:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.