How can I cancel all the current communication from particular IP in Ubuntu 12.04?

1,945

The best option I've found is to use tcpkill. When I installed it, it was part of the dsniff package, so I had to install that first. Then, you would use it like this :

$ sudo tcpkill ip host 20.129.11.86 and port 22
tcpkill: listening on eth0 [ip host 20.129.11.86 and port 22]
10.206.22.202:42532 > 20.129.11.86:22: R 1785992582:1785992582(0) win 0
10.206.22.202:42532 > 20.129.11.86:22: R 1785992732:1785992732(0) win 0
10.206.22.202:42532 > 20.129.11.86:22: R 1785993032:1785993032(0) win 0
20.129.11.86:22 > 10.206.22.202:42532: R 4065251855:4065251855(0) win 0
20.129.11.86:22 > 10.206.22.202:42532: R 4065301087:4065301087(0) win 0
20.129.11.86:22 > 10.206.22.202:42532: R 4065399551:4065399551(0) win 0

As soon tcpkill detects matching traffic, it will terminate the connection.

To see where else the IP is hitting your system, you can use netstat -aunt and grep for the IP address. E.g.,

$ netstat -aunt | egrep 115.125.
tcp        0      0 10.20.22.25:56156     115.125.225.67:80        ESTABLISHED
tcp        0      0 10.20.22.25:42360     115.125.225.1:80         ESTABLISHED
tcp        0      0 10.20.22.25:35210     115.125.225.64:80        ESTABLISHED

Create further ufw rules if necessary.

Is restarting ssh an option?

You can use sudo /etc/init.d/sshd stop then sudo /etc/init.d/sshd start, or use the service mechanism:

$ sudo service ssh stop
ssh stop/waiting
$ sudo service ssh start
ssh start/running, process 4427

You could drop the interface temporarily, if that's an option.

There's an app called 'cutter' that should work, taking the IP address and port as arguments. However, I wasn't able to get the package to install correctly from

$ sudo apt-get install cutter

It's supposed to work something like this (assuming standard port 22 for ssh):

$ cutter 10.10.10.10 22

You might also check out something like the denyhosts package.

Share:
1,945

Related videos on Youtube

Mattigins
Author by

Mattigins

Updated on September 18, 2022

Comments

  • Mattigins
    Mattigins over 1 year

    I would like to add a horizontal line (see image) to my listview in between each item.

    I am not sure how i would adapt my current xaml to do this. If possible i would like the line to fade out on both ends line the picture.

    Thanks.

    Current XAML:

    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Foreground" Value="#787f82" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListViewItem}">
                <Border
                     BorderBrush="Transparent"
                     BorderThickness="0"
                     Background="{TemplateBinding Background}">
                    <GridViewRowPresenter HorizontalAlignment="Stretch" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Width="Auto" Margin="0" Content="{TemplateBinding Content}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    

    Example Picture: enter image description here

  • Eliah Kagan
    Eliah Kagan about 11 years
    Please note that, as written, that command is limited to connections to port 22 (which is usually the port on which an SSH server listens). This command could be generalized to block all traffic from that IP address.
  • Panther
    Panther about 11 years
    You should use REJECT rather then DROP See - chiark.greenend.org.uk/~peterb/network/drop-vs-reject
  • Panther
    Panther about 11 years
    There are 2 problems with this answer. First you did not describe how to use and save iptables configuarationg and the other problem is that it is not such a good idea to mix iptables and UFW.
  • Rashid
    Rashid about 11 years
    I tried sudo /etc/init.d/sshd stop but it is not working.. existing ssh connection is still alive..
  • Rashid
    Rashid about 11 years
    Even "ufw reject from IP" is not working.. the existing ssh and connections are still connected
  • Rashid
    Rashid about 11 years
    I tried "cutter IP", but it is also not working
  • belacqua
    belacqua about 11 years
    I added some more options. tcpkill worked best in my tests.
  • Theodosius Von Richthofen
    Theodosius Von Richthofen over 9 years
    can u post the complete xaml for the Listview, cause this doesn't show anything when i bind it. without this it works like normal
  • Theodosius Von Richthofen
    Theodosius Von Richthofen over 9 years
    displays nothing in the ListView, something is obviously being left out in the ListView XAML, which still isn't being shown