Killing a Connection on Ubuntu Server 20.04

If you really want to kill a connection on a newer kernel Ubuntu, there is a ss command. For example, to kill connection toward with dynamic remote port 40000 you can use the following:

ss -K dst dport = 40000

Nice, quick, and it definitelly beats messing with routes and waiting for a timeout. This is assuming your kernel was compiled with CONFIG_INET_DIAG_DESTROY (true on Ubuntu).

To get a quick list of established connections for given port, one can use netstat with a quick'n'dirty grep:

netstat -nap | grep ESTABLISHED | grep <port>

One thought to “Killing a Connection on Ubuntu Server 20.04”

Leave a Reply

Your email address will not be published. Required fields are marked *