In my previous post, I was doing experiment by blocking crawler from Incapsula with NGINX “deny” which actually it’s doesn’t give solution for me. I don’t know if my code is wrong or NGINX can’t doing subnet blocking correctly. Because I was going into NGINX documentation and follow the article but that drive me into some unlikely result.
So, I try with more familiar way called “iptables”. I use debian for this example. So, basically iptables is available for Linux Distros. Just make sure your server have it installed. Then here is the list:
blockips.conf:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | 199.83.132.0/24 199.83.128.0/24 199.83.132.0/24 198.143.34.0/24 198.143.33.0/24 149.126.76.0/24 198.143.32.0/24 149.126.75.0/24 103.28.248.0/24 198.143.32.0/24 149.126.73.0/24 149.126.75.0/24 149.126.76.0/24 149.126.77.0/24 149.126.78.0/24 198.143.32.0/24 198.143.33.0/24 198.83.128.0/24 198.83.132.0/24 198.83.131.0/24 149.126.70.0/24 149.126.71.0/24 149.126.72.0/24 198.143.32.0/24 149.126.70.0/24 149.126.72.0/24 198.143.30.0/24 198.143.31.0/24 198.143.32.0/24 198.143.33.0/24 103.28.248.0/24 149.126.70.0/24 149.126.71.0/24 149.126.72.0/24 198.143.32.0/24 198.143.33.0/24 198.83.128.0/24 198.83.129.0/24 198.83.130.0/24 198.83.132.0/24 212.199.180.0/24 198.143.33.0/24 103.28.248.129 103.28.248.2 149.126.73.231 149.126.73.232 149.126.75.2 149.126.76.193 149.126.78.2 198.143.32.129 198.143.32.161 198.143.32.193 198.143.32.2 198.143.33.129 198.143.33.161 198.143.33.193 198.143.33.2 198.143.34.129 198.143.34.161 198.143.34.193 198.143.34.2 199.83.128.231 199.83.128.232 199.83.132.129 199.83.132.2 149.126.76.193 149.126.76.2 103.28.248.129 103.28.248.2 149.126.73.231 149.126.73.232 149.126.75.2 149.126.76.193 149.126.78.2 198.143.32.129 198.143.32.161 198.143.32.193 198.143.32.2 198.143.33.129 198.143.33.161 198.143.33.193 198.143.33.2 198.143.34.129 198.143.34.161 198.143.34.193 198.143.34.2 199.83.128.231 199.83.128.232 199.83.132.129 199.83.132.2 103.28.248.129 103.28.248.2 149.126.73.231 149.126.73.232 149.126.75.2 149.126.76.129 149.126.76.193 149.126.76.2 149.126.78.2 198.143.32.129 198.143.32.161 198.143.32.193 198.143.32.2 198.143.33.129 198.143.33.161 198.143.33.193 198.143.33.2 198.143.34.129 198.143.34.161 198.143.34.193 198.143.34.2 199.83.128.231 199.83.128.232 199.83.132.129 199.83.132.2 103.28.248.129 103.28.248.2 149.126.73.231 149.126.73.232 149.126.75.2 149.126.76.129 149.126.76.193 149.126.76.2 149.126.78.2 198.143.32.129 198.143.32.161 198.143.32.193 198.143.32.2 198.143.33.129 198.143.33.161 198.143.33.193 198.143.33.2 198.143.34.129 198.143.34.161 198.143.34.193 198.143.34.2 199.83.128.231 199.83.128.232 199.83.132.129 199.83.132.2 103.28.248.129 103.28.248.2 149.126.73.231 149.126.73.232 149.126.75.2 149.126.76.129 149.126.76.193 149.126.76.2 149.126.78.2 198.143.32.129 198.143.32.161 198.143.32.193 198.143.32.2 198.143.33.129 198.143.33.161 198.143.33.193 198.143.33.2 198.143.34.129 198.143.34.161 198.143.34.193 198.143.34.2 199.83.128.231 199.83.128.232 199.83.132.129 199.83.132.2 103.28.248.129 103.28.248.2 149.126.73.231 149.126.73.232 149.126.76.193 149.126.78.2 198.143.32.193 198.143.32.2 198.143.33.161 198.143.34.161 198.143.34.193 199.83.128.231 199.83.128.232 199.83.132.129 199.83.132.2 |
I assume you put this script under “/root/blockips.conf”. So, to execute Iptables to blocking IP by reading from files, create this little script called “block.sh”:
1 2 3 4 5 6 7 8 | #!/bin/sh BLOCKED_IP="/root/blockips.conf" if [ -f $BLOCKED_IP ]; then while read BLOCKED_IP; do iptables -A INPUT -i eth0 -s $BLOCKED_IP -j DROP iptables -A OUTPUT -o eth0 -d $BLOCKED_IP -j DROP done < $BLOCKED_IP fi |
Don’t forget to make it executable by “chmod a+x block.sh”