netstat -tulnap
shows me what ports are in use. How to free up a port in Linux?
To check all ports:
netstat -lnp
To close an open port:
fuser -k port_no/tcp
Example:
fuser -k 8080/tcp
In both cases you can use the sudo
command if needed.
You can use tcpkill
(part of the dsniff
package) to kill the connection that's on the port you need:
sudo tcpkill -9 port PORT_NUMBER
In terminal type :
netstat -anp|grep "port_number"
It will show the port details. Go to last column. It will be in this format . For example :- PID/java
then execute :
kill -9 PID. Worked on Centos5
For MAC:
lsof -n -i :'port-number' | grep LISTEN
Sample Response :
java 4744 (PID) test 364u IP0 asdasdasda 0t0 TCP *:port-number (LISTEN)
and then execute :
kill -9 PID
Worked on Macbook
Shutting down the computer always kills the process for me.
Kill the process that is listening to the port in question. I believe netstat shows you process ids.