Freeing up a TCP/IP port?

2019-01-16 00:11发布

netstat -tulnap shows me what ports are in use. How to free up a port in Linux?

10条回答
你好瞎i
2楼-- · 2019-01-16 00:46

To a kill a specific port in Linux use below command

sudo fuser -k Port_Number/tcp

replace Port_Number with your occupied port.

查看更多
一夜七次
3楼-- · 2019-01-16 00:51

I think the only way will be to stop the process which has opened the port.

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-16 00:58

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
查看更多
唯我独甜
5楼-- · 2019-01-16 00:59

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

查看更多
成全新的幸福
6楼-- · 2019-01-16 01:02

Kill the process that is listening to the port in question. I believe netstat shows you process ids.

查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-16 01:03

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.

查看更多
登录 后发表回答