利用dsniff的tcpkill殺TCP連接
Linux連接久久不能釋放的現象不常見,但偶然也會發生。進程雖不復存在,但是客戶端的連接咬定青山不放松,死活也不肯吐出連接,導致重啟進程時因操作系統判斷監聽端口被占用而無法啟動。常規手段已經束手無策,這時候不得不想辦法殺連接。
一、tcpkill介紹
tcpkill是網絡嗅探工具包dsniff其中提供的一個利器,用於殺掉TCP連接。因此事先要安裝dsniff。如rhel5中,搜索下載dsniff-2.4-0.1.b1.el5.rf.rpm,rpm -ivh安裝后,很容易調出tcpkill命令。我們可以先看看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連接一直無法釋放,頑強無比。