{"id":368,"date":"2016-12-29T23:06:00","date_gmt":"2016-12-29T21:06:00","guid":{"rendered":"http:\/\/itsimple.info\/?p=368"},"modified":"2017-01-04T10:31:08","modified_gmt":"2017-01-04T08:31:08","slug":"how-to-stop-ddos-attack-on-you-linux","status":"publish","type":"post","link":"https:\/\/itsimple.info\/?p=368","title":{"rendered":"How to stop DDos Attack on linux"},"content":{"rendered":"<h3>To find out if <strong>your server is under attack<\/strong> or not. You can also <strong>list abusive IP address<\/strong> using this method.<\/h3>\n<pre><code><span style=\"color: blue;\"># netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n<\/span>\r\n\r\n<\/code><\/pre>\n<p>Output:<\/p>\n<pre>      1 CLOSE_WAIT\r\n      1 established)\r\n      1 Foreign\r\n      3 FIN_WAIT1\r\n      3 LAST_ACK\r\n     13 ESTABLISHED\r\n     17 LISTEN\r\n    154 FIN_WAIT2\r\n    327 TIME_WAIT<\/pre>\n<pre><code>\u00a0<\/code><\/pre>\n<p>Dig out more information about a specific ip address:<br \/>\n<code><span style=\"color: blue;\"># netstat -nat |grep {IP-address} | awk '{print $6}' | sort | uniq -c | sort -n<\/span><\/code><\/p>\n<pre>      2 LAST_ACK\r\n      2 LISTEN\r\n      4 FIN_WAIT1\r\n     14 ESTABLISHED\r\n     91 TIME_WAIT\r\n    130 FIN_WAIT2<\/pre>\n<p>Busy server can give out more information:<br \/>\n<code><span style=\"color: blue;\"># netstat -nat |grep 202.54.1.10 | awk '{print $6}' | sort | uniq -c | sort -n<\/span><\/code><br \/>\nOutput:<\/p>\n<pre>  15 CLOSE_WAIT\r\n  37 LAST_ACK\r\n  64 FIN_WAIT_1\r\n  65 FIN_WAIT_2\r\n1251 TIME_WAIT\r\n3597 SYN_SENT\r\n5124 ESTABLISHED<\/pre>\n<h4>Get List Of All Unique IP Address<\/h4>\n<p>To print list of all unique IP address connected to server, enter:<br \/>\n<code><span style=\"color: blue;\"># netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '\/^$\/d' | uniq<\/span><\/code><br \/>\nTo print total of all unique IP address, enter:<br \/>\n<code># netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '\/^$\/d' | uniq | wc -l<\/code><br \/>\nOutput:<\/p>\n<pre>449<\/pre>\n<h4>Find Out If Box is Under DoS Attack or Not<\/h4>\n<p>If you think your Linux box is under attack, print out a list of open connections on your box and sorts them by according to IP address, enter:<br \/>\n<code><span style=\"color: blue;\"># netstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '\/^$\/d' |sort | uniq -c | sort -n<\/span><\/code><br \/>\nOutput:<\/p>\n<pre>    1 10.0.77.52\r\n      2 10.1.11.3\r\n      4 12.109.42.21\r\n      6 12.191.136.3\r\n.....\r\n...\r\n....\r\n    13 202.155.209.202\r\n     18 208.67.222.222\r\n     28 0.0.0.0\r\n    233 127.0.0.1\r\n<\/pre>\n<h4>Display Summary Statistics for Each Protocol<\/h4>\n<p>Simply use netstat -s:<br \/>\n<code><span style=\"color: blue;\"># netstat -s | less<br \/>\n# netstat -t -s | less<br \/>\n# netstat -u -s | less<br \/>\n# netstat -w -s | less<br \/>\n# netstat -s<\/span><\/code><\/p>\n<h4>Display Interface Table<\/h4>\n<p>You can easily display dropped and total transmitted packets with netstat for all interfaces:<br \/>\n<code><span style=\"color: blue;\"># netstat --interfaces<\/span><br \/>\n<\/code><\/p>\n<h2><strong><u>Stop the Attack With Null Route IP using route command<\/u><\/strong><\/h2>\n<p>Suppose that bad IP is 65.21.34.4, type the following command at shell:<\/p>\n<pre><span style=\"color: blue;\"># route add 65.21.34.4 gw 127.0.0.1 lo<\/span><\/pre>\n<p>You can verify it with the following command:<\/p>\n<pre><span style=\"color: blue;\"># netstat -nr<\/span><\/pre>\n<p>OR<\/p>\n<pre><span style=\"color: blue;\"># route -n<\/span><\/pre>\n<p>You can also use reject target (a hat tip to Gabriele):<\/p>\n<pre><span style=\"color: blue;\"># route add -host IP-ADDRESS reject\r\n# route add -host 64.1.2.3 reject<\/span><\/pre>\n<p>To confirm the null routing status, use the ip command as follows:<\/p>\n<pre><span style=\"color: blue;\"># ip route get 64.1.2.3<\/span><\/pre>\n<p>Output:<\/p>\n<pre><span style=\"color: blue;\">RTNETLINK answers: Network is unreachable<\/span><\/pre>\n<p>To drop entire subnet 192.67.16.0\/24, type:<\/p>\n<pre><span style=\"color: blue;\"># route add -net 192.67.16.0\/24 gw 127.0.0.1 lo<\/span><\/pre>\n<p>Null routing using ip command<br \/>\nWhile traversing the RPDB, any route lookup which matches a rule with the blackhole rule type will cause the packet to be dropped. No ICMP will be sent and no packet will be forwarded. The syntax is follows for the ip command:<\/p>\n<pre><span style=\"color: blue;\"># ip route add blackhole 202.54.5.2\/29\r\n# ip route add blackhole from 202.54.1.2\r\n# ip rule add blackhole to 10.18.16.1\/29\r\n# ip route<\/span><\/pre>\n<p>How do I remove null routing? How do I remove blocked IP address?<\/p>\n<p>Simple use the route delete command as follows:<\/p>\n<pre><span style=\"color: blue;\"># route delete 65.21.34.4<\/span><\/pre>\n<p>OR<\/p>\n<pre><span style=\"color: blue;\"># route del -host 65.21.34.4 reject<\/span><\/pre>\n<p>Or use NA command to delete route:<\/p>\n<pre><span style=\"color: blue;\"># ip route delete 1.2.3.4\/26 dev eth0<\/span><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To find out if your server is under attack or not. You can also list abusive IP address using this method. # netstat -nat | awk &#8216;{print $6}&#8217; | sort | uniq -c | sort -n Output: 1 CLOSE_WAIT 1 established) 1 Foreign 3 FIN_WAIT1 3 LAST_ACK 13 ESTABLISHED 17 LISTEN 154 FIN_WAIT2 327 TIME_WAIT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,13,22],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-centos","category-linux","category-security"],"_links":{"self":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":0,"href":"https:\/\/itsimple.info\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"wp:attachment":[{"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsimple.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}