If you really want to kill a connection on a newer kernel Ubuntu, there is a
ss command. For example, to kill connection toward
192.168.1.1 with dynamic remote port
40000 you can use the following:
ss -K dst 192.168.1.1 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”
This is really simple and quick.