Koozali.org: home of the SME Server

Blocking of IP addresses and Mail Flood Howto

Offline besterl

  • ****
  • 78
  • +0/-0
Blocking of IP addresses and Mail Flood Howto
« on: September 16, 2008, 04:33:35 PM »
I know I will probably get rapped over the fingers for this crude howto or the methods used, but if it helps at least one person it is worth it.

This is aimed at noobs like myself that does not have 200 collective years of linux experience......

My problem was as follows:

I have a SME server in an extremely remote location (via a very slow link) and the domain got compromised, due to user ignorance.

The SPAM filter was doing it's job, but the amount of time and traffic spent killed the link.

The incoming server was continously sitting at 40/40 connections and because it took a long time to query the RHSBL servers, the speed become inoperable.

I decided to crudely block these guys with iptables, but I do not have the skills to create a full blown contrib for this.

So here is my two cents worth of effort - hope it helps.

Log into the server via putty

In the /root create a file called dropip.sh as follows:

vi dropip.sh

In the window that follows - press the Ins (Insert) key and paste the following into the window (Paste by pressing the right mouse key)

/sbin/iptables -I INPUT -s 115.84.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 116.23.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 116.252.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 119.118.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 12.202.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 121.129.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 121.157.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 121.204.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 121.88.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 122.161.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 122.254.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 125.129.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 125.143.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 125.209.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 125.44.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 125.89.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 128.103.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 141.152.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 151.47.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 151.53.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 151.57.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 157.105.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 163.212.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 164.77.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.100.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.102.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.105.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.13.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.24.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.25.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.3.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.32.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.33.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.47.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.5.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.6.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 189.92.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.139.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.158.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.176.48.0/24 -j DROP
/sbin/iptables -I INPUT -s 190.201.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.24.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.245.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.3.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.48.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.51.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 190.66.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 193.111.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 194.187.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 195.241.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 195.3.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.104.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.114.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.118.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.155.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.171.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.203.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.222.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.50.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 200.67.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.211.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.220.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.223.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.231.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.239.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.250.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.254.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.3.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.42.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.51.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.6.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.63.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.74.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.77.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 201.9.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 203.110.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 203.172.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 203.237.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 203.97.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 204.14.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 204.210.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 204.8.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 207.30.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 208.101.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 209.42.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 210.219.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 210.4.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 211.44.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 212.220.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 212.58.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 212.60.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 212.72.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 213.153.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 213.254.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 213.37.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 216.221.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 216.67.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 217.156.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 217.216.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 217.217.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 217.65.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 217.76.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 217.91.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 218.108.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 218.16.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 218.232.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 218.248.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 220.126.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 220.71.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 222.185.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 222.246.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 222.251.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 24.103.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 24.15.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 24.154.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 24.217.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 41.207.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.141.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.17.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.182.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 59.21.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.251.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.252.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.63.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.68.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 58.8.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 59.92.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 59.98.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 61.231.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 61.98.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 62.10.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 62.194.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 62.245.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 62.57.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 62.85.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 63.251.135.0/24 -j DROP
/sbin/iptables -I INPUT -s 64.105.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 64.34.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 64.46.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 65.29.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 66.189.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 66.26.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 66.44.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 66.98.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 67.76.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 68.121.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 68.187.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 68.239.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 68.253.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 69.70.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.109.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.11.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.127.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.143.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.223.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.236.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.240.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 71.85.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 72.141.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 72.147.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 72.86.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 72.94.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 74.232.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 75.150.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 76.195.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 76.21.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 76.25.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 77.100.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 77.179.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 77.228.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 77.31.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 77.47.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.15.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.160.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.36.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.37.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.49.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.6.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.86.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 78.97.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.1.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.13.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.134.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.150.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.184.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.185.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.3.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.30.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.33.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.36.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.39.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.4.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.65.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.79.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.86.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 79.94.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 80.179.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 80.31.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 81.216.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 82.41.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 82.59.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 83.5.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 84.121.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 84.57.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 85.137.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 85.178.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 85.52.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 85.60.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 85.90.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 86.22.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 87.205.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 87.6.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 87.21.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 87.211.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 88.224.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 88.235.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 88.247.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 88.84.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 89.140.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 89.178.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 89.33.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 90.194.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.122.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.124.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.151.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.172.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.76.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.77.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.82.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 91.96.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 92.101.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 92.112.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 92.124.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 92.46.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 92.80.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 93.102.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 93.187.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 96.254.0.0/16 -j DROP
/sbin/iptables -I INPUT -s 98.213.0.0/16 -j DROP



Save the file by pressing Esc (Escape) and the :wq (Enter)

Execute the file as follows

sh dropip.sh

To automate this - you can make it execute on startup


Please note - this is very broad blocking - The proper way to do this would be to block individual ip addresses as follows

/sbin/iptables -I INPUT -s xxx.xxx.xxx.xxx -j DROP

where xxx.xxx.xxx.xxx is the IP address you want to block


Now - I am not saying that you should use the list above - it is a sample I've compiled today by watching the output from my smtpfront/current logfile
In SME 7 this would be the qpsmtpd/current logfile.

To watch the activity realtime - open another putty session to your firewall and type the following

tail -F /var/log/smtpfont-qmail/current

Watch the pid's closely as this will point you to the offending IP's

Add the IP's you want to block to the script


Offline pfloor

  • *****
  • 889
  • +1/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #1 on: September 16, 2008, 11:18:34 PM »
Quote
I know I will probably get rapped over the fingers for this...

The amount of pain endured will be directly proportionate to who actually answers your post. 

I have 2 thing to point out to you.

#1-I don't know whether the directives in your script work or not (I'm not too savvy in iptables commands) but your implementation does not follow the SME template schema.

Quote
To automate this - you can make it execute on startup

This is only half true and not the right way to do it.  It may work upon start-up but you will soon find your added directives removed during some (if not most) reconfigurations through the server-manager, an IP change, a new vpn connection, etc.

You need to template this for it to be successful and if templated properly, it will automatically load (and reload) at the right times.

#2-Placing How-To's in the forums is futile.  A few people will see it then it will get lost and buried with time.  How-To's belong in the wiki.

No rapping intended (just some education) so sorry if it hurt too badly :-)
In life, you must either "Push, Pull or Get out of the way!"

Offline mercyh

  • *
  • 824
  • +0/-0
    • http://mercyh.org
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #2 on: September 16, 2008, 11:29:13 PM »
I think I understand why you did it this way, (your slow connection) but I think in most cases this is painting with a brush that is too wide. This is one of those things that works good in the short term but after X# of years when you or your replacement is trying to figure out why this server will not accept mail from a user, it may cause some pain. (And I am not talking about rapped fingers :smile:)

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #3 on: September 17, 2008, 12:04:15 AM »
besterl

This technique is already included in the FAQ, so you did not need to create anything if you had looked first.

http://wiki.contribs.org/SME_Server:Documentation:FAQ#Block_incoming_IP_address
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline pfloor

  • *****
  • 889
  • +1/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #4 on: September 17, 2008, 12:29:30 AM »
The amount of pain endured will be directly proportionate to who actually answers your post. 

I have 2 thing to point out to you.

#1-I don't know whether the directives in your script work or not (I'm not too savvy in iptables commands) but your implementation does not follow the SME template schema.

This is only half true and not the right way to do it.  It may work upon start-up but you will soon find your added directives removed during some (if not most) reconfigurations through the server-manager, an IP change, a new vpn connection, etc.

You need to template this for it to be successful and if templated properly, it will automatically load (and reload) at the right times.

#2-Placing How-To's in the forums is futile.  A few people will see it then it will get lost and buried with time.  How-To's belong in the wiki.

No rapping intended (just some education) so sorry if it hurt too badly :-)

Better yet, just follows Ray's instructions here (they are MUCH, MUCH better than mine.):

besterl

This technique is already included in the FAQ, so you did not need to create anything if you had looked first.

http://wiki.contribs.org/SME_Server:Documentation:FAQ#Block_incoming_IP_address


Maybe I should practice what I preach so I now sit in the corner hitting myself over head for not using that magical "Search Button" :hammer:
« Last Edit: September 17, 2008, 12:31:21 AM by pfloor »
In life, you must either "Push, Pull or Get out of the way!"

Offline arne

  • *****
  • 1,116
  • +0/-4
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #5 on: September 17, 2008, 02:58:54 AM »
This should normally not work, on a plain and basic iptables firewall, so I am rather surprised if it does:

/sbin/iptables -I INPUT -s 115.84.0.0/16 -j DROP

While this should work (on a plain and basic iptables firewall, but possible not on the SME server.)

/sbin/iptables -A INPUT -s 115.84.0.0/16 -j DROP

Reason the first statement uses -I (insert) that will insert a rule in the bottom of the rule stack, after the rule that open for port 25, so it will (should) have no effect.

If a packet is first validated against the rule that allows port 25 (the ordinary rule) it will newer "see" the rule that says "drop all packets from network 115.84.0.0"

If on the other hand, the variant no 2 with -A (append) is used then the new rule is "appended" at the top of the rulestack where it will have priority before an other existing rule that says "accept traffic to port 25".

After doing improper and irregular modifications of the sme server firewall for years, I know two things can or will happen sooner or later:

1. The not so bad, but bad enough thing: Your "extra rules" will be removed by the server, and from time to time you will notice that they are not there, and you will have to apply them again.

2. The bad variant: The server will lock off completely, the firewall will block all connections, no traffic will be allowed to go in and out and you will not be able to make a ssh logon.

I don't know why this locking of the firewall occur (when doing improper firewalls modifications). It did not use to happen on the earlier versions of the SME server, but it has happened a couple of times for me, doing improper modifications of the 7.x firewall.

The procedure in the FAQ uses -A and not -I that should put the new blocking rule in the right position. Then also a correct procedure, modifying the templates will not have the other side effect like rules that is just disappearing in the thin air, or a locked server/gateway. So "the FAQ way" should definitely be the right way of doing it.

A little question to besterl:

/sbin/iptables -A INPUT -s 115.84.0.0/16 -j DROP

This statement says something like: Drop all packets with ip source addresses in the range from 115.84.1.1 to 115.84.254.254

The FAQ only mention how to block one and one ip but what you mention is to block ranges of 254x254 ip's, one for each line.

For a basic iptables firewall using ranges this way, does work, and I guess it will work for the SME server as well, even though I think that the FAQ does not mention it explicitly.

When you does it like this blocking for 254x254 souce addresses, line by line, you does it quite effectively, and there is a lot of source ip addresses that is locked out, something like 200x254x254

How can you know that those source addresses is the right ones ? Could it be that you are blocking more than the unwanted traffic ?

(I’m curious because I would like to use the list myself, if I knew which ones those IP's are.)

By the way, I am not doing improper and "illegal" modifications of the SME server firewall any more :)
« Last Edit: September 17, 2008, 03:02:56 AM by arne »
......

Offline besterl

  • ****
  • 78
  • +0/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #6 on: September 17, 2008, 10:11:08 AM »
Hi Ladies and Gents

Thanks for all the feedback - and yes I am learning in the process.

OK - a bit more feedback from my side.

I would love to have this templated, but I do not posses the knowledge

The ideal situation would be to have a Server Manager Panel where I can add / remove these IP's

Also - Yes - I did it purely because of the slow line.

In a perfect world - I think if we had a situation where we could either cache (for a certain period) the blacklisted IP's would make this great.

Another potential solution is to create an own internal blacklist from IP's that connect more than X times in X period, with an option to whitelist here as well.

I do understand that I am "painting with too broad a brush" here, but I want to explain my logic.

The guys at this site has a directive that the link is for business only, as it is so slow.

The never deal with anyone in Japan, Hungary or Bulgaria (for instance)

My thinking were along the following lines

 - A lot of the times the mail will come from the same IP range as the offending website.
 - I was looking for a way to stop the websites and mail at the same time.
 - I know I am blocking large blocks of IP's, but I do not want to create a list that is too massive
 - Should mail be blocked, I can always remove that entry or put in an ACCEPT statement.




NOW - LET ME THROW AN IDEA INTO THE WIND HERE

I am prepared to put some time and effort into creating a list here that can benefit guys with slow links if there is interest.

This was purely done to take back bandwidth that has effectively become useless due to all the unneeded traffic.
Increasing the link speed would not have necessarily solved the problem, just make the spam attempt to come in quicker.



As for the -I and -A, I will give it a bash, but from testing from another IP range I control, the -I seems to have worked, but thanks a lot, I learn something new every day.

Also - I accept the rapping on the fingers for not searching in the right place - I searched in the forums and not the documentation (My Bad)

Offline besterl

  • ****
  • 78
  • +0/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #7 on: September 17, 2008, 10:13:32 AM »
Oh - and one more thing

I we create a list like that - why don't we categorise them in eg.
I think the SME community can be a great help


Country
Exploitable
Dynamic IP's
Temporary
etc etc

JUST A THOUGHT

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #8 on: September 17, 2008, 12:20:49 PM »
besterl

Nothing wrong with creating a list, but keep in mind that things (spam source IPs) change over time, so you are really creating another list to keep updated, when that list effectively already exists in RBL's etc, and is being actively maintained.

Here is another technique for achieving what you want, again using an already existing contrib.
http://wiki.contribs.org/SME_Server:Documentation:FAQ#Email_WBL_server_manager_panel

Just add to the appropriate list in the WBL panel.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #9 on: September 17, 2008, 12:30:52 PM »
besterl

You can also do what you want using db commands, which is also an already existing sme server technique.
eg
db configuration setprop smtpd DenyHosts xxx.xxx.xxx.xxx
signal-event remoteaccess-update

(seperate multiple IPs with a comma)
eg
db configuration setprop smtpd DenyHosts xxx.xxx.xxx.xxx,yyy.yyy.yyy.yyy

For more details (eh blocking http, ssh etc) see
http://forums.contribs.org/index.php?topic=34333.msg147942#msg147942


Quote
The incoming server was continously sitting at 40/40 connections

You can also use db commands to reduce the number of connections, therefore using less bandwidth.
http://wiki.contribs.org/DB_Variables_Configuration#smtpd


You may also want to look at wondershaper (to control outgoing bandwidth)
http://wiki.contribs.org/Wondershaper
« Last Edit: September 17, 2008, 12:39:02 PM by mary »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline mercyh

  • *
  • 824
  • +0/-0
    • http://mercyh.org
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #10 on: September 17, 2008, 03:09:04 PM »
and one more tool that might interest you is here:

http://wiki.contribs.org/GeoIP

usage described a bit in this thread:

http://forums.contribs.org/index.php?topic=41495.0

Offline arne

  • *****
  • 1,116
  • +0/-4
Re: Blocking of IP addresses and Mail Flood Howto
« Reply #11 on: September 17, 2008, 07:42:34 PM »
besterl ->

No, don't give it a bash if bash means a modification using a shellscript. I have done this for years, and I just know that from time to time it will happen, that rules that should be there will fall out, or the firewall will lock completely.

If the mod is done as described in the FAQ, modifying via the template the correct way, will also result in a easy to read and edit text file. It will actually not be much more difficult than doing it from some kind of configuration panel.

http://wiki.contribs.org/SME_Server:Documentation:FAQ#Block_incoming_IP_address

It were mentioned somewhere above that if the rules were to stict, then it can be applyed a new rule for accepting traffic. This will not allways work, because the order of the rules is critical. Applying extra accept rukes is a lot more dangerous because one misstyped rule could bypass the whole firewall. An incorrect aditional deny rule could make it to closed. An incorrect extra aditional accept rule could make the firewall to open by bypassing other existing firewall rules. (When a packet is accepted by a rule it is not validated by the next rule, it jumps right out of the rule stack and stright into the server. A denyed or dropped packet is just lost, so that the damage potensial is a bit less. )

......