转载地址:https://www.cnblogs.com/archoncap/p/5125180.html 利用dsniff的tcpkill杀TCP连接

Linux连接久久不能释放的现象不常见,但偶然也会发生。进程虽不复存在,但是客户端的连接咬定青山不放松,死活也不肯吐出连接,导致重启进程时因操作系统判断监听端口被占用而无法启动。常规手段已经束手无策,这时候不得不想办法杀连接。 一、tcpkill介绍 tcpkill是网络嗅探工具包dsniff其中提供的一个利器,用于杀掉TCP连接。因此事先要安装dsniff。如rhel5中,搜索下载dsniff-2.4-0.1.b1.el5.rf.rpm,rpm -ivh安装后,很容易调出tcpkill命令。

yum -y install dsniff.x86_64

我们可以先看看manual: [root@xxxx ~]# man tcpkill TCPKILL(8) TCPKILL(8) NAME tcpkill - kill TCP connections on a LAN

SYNOPSIS tcpkill [-i interface] [-1...9] expression

DESCRIPTION tcpkill kills specified in-progress TCP connections (useful for libnids-based applications which require a full TCP 3-whs for TCB creation).

OPTIONS -i interface Specify the interface to listen on.

   -1...9 Specify the degree of brute force to use in killing a connection. Fast connections may require a  higher
          number in order to land a RST in the moving receive window. Default is 3.

   expression
          Specify a tcpdump(8) filter expression to select the connections to kill.

SEE ALSO dsniff(8), tcpnice(8)

AUTHOR Dug Song dugsong@monkey.org
TCPKILL(8) 二、tcpkill实战 在该示例中,FIN_WAIT1 的TCP连接一直无法释放,顽强无比。

进程监听端口16000,客户端连接端口43255。

使用tcpkill的效果又是如何呢?

命令如下:tcpkill -9 host 客户端连接ip

tcpkill -9 host 172.16.0.254

可以看到客户端140.4:43255的连接被杀掉后,它又重新尝试新的连接。

亲测 好用 厉害