how to close an established network connection in linux and osx

3

1

I used to do this in the Windows world with tool called TCPView: just select a established connection (ESTABLISHED), then select "Close Connection". I can't find a way to this on Mac OSX or Linux (I need both). The only way I know of is to kill the process that has the port open.

My main use case is to simulate interruptions in connectivity to test failover, like unplugging a cable or losing a router or middleware situations.

Rodrigo Gonzalez

Posted 2013-02-26T14:21:46.243

Reputation: 33

Killing the process is not good enough? – terdon – 2013-02-26T14:28:34.243

Answers

2

You could attach to your process using gdb and close() the file descriptor corresponding to the connection. You can find out the file descriptor number using lsof -a -i4 -p $PID.

Roman Cheplyaka

Posted 2013-02-26T14:21:46.243

Reputation: 351

works! too bad gdb pauses the program, but I'll look more into that – Rodrigo Gonzalez – 2013-02-26T19:52:59.517

1

  • tcpkill -i eth0 { expression }
    (basic command/options)

  • tcpkill -i eth0 port 21
    (Kill all outgoing ftp (port 21) connection)

  • tcpkill host 192.168.1.2
    or
    tcpkill host hostname.domainname.com
    (Kill all all packets arriving at or departing from host 192.168.1.2)

  • tcpkill ip host 192.168.1.2 and not 192.168.1.111
    (To kill all IP packets between 192.168.1.2 and any host except 192.168.1.111)

Anon

Posted 2013-02-26T14:21:46.243

Reputation: 11