'Freeing up a TCP/IP port? [closed]
netstat -tulnap
shows me what ports are in use. How to free up a port in Linux?
Solution 1:[1]
As the others have said, you'll have to kill all processes that are listening on that port. The easiest way to do that would be to use the fuser(1) command. For example, to see all of the processes listening for HTTP requests on port 80 (run as root or use sudo):
# fuser 80/tcp
If you want to kill them, then just add the -k option.
Solution 2:[2]
To kill a specific port in Linux use the below command
sudo fuser -k Port_Number/tcp
replace Port_Number with your occupied port.
Solution 3:[3]
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
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
Solution 4:[4]
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
Solution 5:[5]
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.
Solution 6:[6]
The "netstat --programs" command will give you the process information, assuming you're the root user. Then you will have to kill the "offending" process which may well start up again just to annoy you.
Depending on what you're actually trying to achieve, solutions to that problem will vary based on the processes holding those ports. For example, you may need to disable services (assuming they're unneeded) or configure them to use a different port (if you do need them but you need that port more).
Solution 7:[7]
Kill the process that is listening to the port in question. I believe netstat shows you process ids.
Solution 8:[8]
If you really want to kill a process immediately, you send it a KILL signal instead of a TERM signal (the latter a request to stop, the first will take effect immediately without any cleanup). It is easy to do:
kill -KILL <pid>
Be aware however that depending on the program you are stopping, its state may get badly corrupted when doing so. You normally only want to send a KILL signal when normal termination does not work. I'm wondering what the underlying problem is that you try to solve and whether killing is the right solution.
Solution 9:[9]
I think the only way will be to stop the process which has opened the port.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hmatar |
| Solution 2 | hmatar |
| Solution 3 | alexkr |
| Solution 4 | AlexT |
| Solution 5 | Ferdi |
| Solution 6 | |
| Solution 7 | Gleb |
| Solution 8 | Paul de Vrieze |
| Solution 9 | Tilo Prütz |
