{"id":1836,"date":"2021-08-20T12:22:05","date_gmt":"2021-08-20T06:52:05","guid":{"rendered":"https:\/\/coimbatorewebhosting.com\/blog\/?p=1836"},"modified":"2021-08-19T12:30:19","modified_gmt":"2021-08-19T07:00:19","slug":"how-to-verify-ddos-attack-with-netstat-command-on-linux","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/how-to-verify-ddos-attack-with-netstat-command-on-linux\/","title":{"rendered":"How to verify DDOS attack with \u2018netstat\u2019 command on Linux"},"content":{"rendered":"<h4 class=\"fittexted_for_content_h4\"><span>How to verify DDOS attack with netstat command on Linux<\/span><\/h4>\n<p>Your server appearing pretty slow could be many things from wrong configs, scripts and dodgy hardware, but sometimes it could be a cause someone is flooding your server with traffic known as DoS ( Denial of Service ) or DDoS ( Distributed Denial of Service ).<\/p>\n<p>Denial-of-service attack (DoS attack) or Distributed Denial-of-service attack (DDoS attack) is an attempt to make a machine or network resource unavailable to its intended users. This attack generally target sites or services hosted on high-profile web servers such as banks, credit card payment gateways, and even root name servers.<\/p>\n<p><a href=\"https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg\" rel=\"nofollow noopener\" target=\"_blank\"><img decoding=\"async\" data-attachment-id=\"1159\" data-permalink=\"https:\/\/www.webhostingchennai.co.in\/blog\/how-to-verify-ddos-attack\/ddos\/\" data-orig-file=\"https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?fit=788%2C433&amp;ssl=1\" data-orig-size=\"788,433\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"ddos\" data-image-description=\"\" data-medium-file=\"https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?fit=300%2C165&amp;ssl=1\" data-large-file=\"https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?fit=788%2C433&amp;ssl=1\" loading=\"lazy\" class=\"aligncenter wp-image-1159\" src=\"https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?resize=564%2C310\" alt=\"how to verify ddos attack\" srcset=\"https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?w=788&amp;ssl=1 788w, https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?resize=300%2C165&amp;ssl=1 300w, https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?resize=768%2C422&amp;ssl=1 768w, https:\/\/i1.wp.com\/www.webhostingchennai.co.in\/blog\/wp-content\/uploads\/2018\/06\/ddos.jpg?resize=109%2C60&amp;ssl=1 109w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" data-recalc-dims=\"1\" width=\"564\" height=\"310\" \/><\/a><\/p>\n<p>DoS attacks are implemented by either forcing the targeted computer to reset, or consuming its resources so that it can no longer provide its services or obstructs the communication media between the users and the victim so that they can no longer communicate adequately.<\/p>\n<p>In this article you\u2019ll see How to verify DDOS attack with \u2018netstat\u2019 command on Linux<\/p>\n<p><strong>Some of the commands with explanation<\/strong><\/p>\n<pre>netstat -na<\/pre>\n<p>This display all <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-check-memory-usage-on-centos-server\/\" title=\"active Internet\" alt=\"active Internet\">active Internet<\/a> connections to the server and only established connections are included.<\/p>\n<pre>netstat -an | grep :80 | sort<\/pre>\n<p>Show only active Internet connections to the server on port 80, this is the http port and so it\u2019s useful if you have a <a href=\"https:\/\/www.squarebrothers.com\/vps-web-hosting-india\/\" target=\"_blank\" rel=\"noopener nofollow\">web server<\/a>, and sort the results and useful in detecting a single flood by allowing you to recognize many connections coming from one IP.<\/p>\n<pre>netstat -n -p|grep SYN_REC | wc -l<\/pre>\n<p>This command is useful to find out how many active SYNC_REC are occurring on the server. The number should be pretty low, preferably less than 5. On DoS attack incidents or mail bombs, the number can jump to pretty high. However, the value always depends on <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/easy-steps-to-install-and-configure-lamp-in-centos-7\/\" title=\"system\" alt=\"system\">system<\/a>, so a high value may be average on another <a href=\"http:\/\/chennaihosting.net\/\" target=\"_blank\" rel=\"noopener nofollow\">server<\/a>.<\/p>\n<pre>netstat -n -p | grep SYN_REC | sort -u<\/pre>\n<p>List out the all IP addresses involved instead of just count.<\/p>\n<pre>netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'<\/pre>\n<p>List all the unique IP <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/install-latest-python-version3-6\/\" title=\"addresses\" alt=\"addresses\">addresses<\/a> of the node that are sending SYN_REC connection status.<\/p>\n<pre>netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n<\/pre>\n<p>Use netstat command to calculate and count the number of connections each IP address makes to the server.<\/p>\n<pre>netstat -anp |grep 'tcp|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n<\/pre>\n<p>List count of number of connections the IPs are connected to the server using TCP or UDP protocol.<\/p>\n<pre>netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr<\/pre>\n<p>Check on ESTABLISHED connections instead of all connections, and displays the connections count for each IP.<\/p>\n<pre>netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1<\/pre>\n<p>Show and list IP address and its connection count that connect to port 80 on the server. Port 80 is used mainly by HTTP web page request.<\/p>\n<p><strong>How to mitigate a DOS attack<\/strong><\/p>\n<p>Once that you have found the IP that are attacking your server you can use the following commands to block their connection to your server:<\/p>\n<pre>iptables -A INPUT 1 -s $IPADRESS -j DROP\/REJECT<\/pre>\n<p>you have to replace $IPADRESS with the IP numbers that you have found with netstat.<br \/>\nOr<br \/>\nIf you have installed CSF, you can use the below command to block the ip address<\/p>\n<pre>csf -d &lt;ip address&gt;<\/pre>\n<p>After firing the above command, KILL all httpd connections to clean your system and than restart httpd service by<br \/>\nusing the following commands:<\/p>\n<pre>killall -KILL httpd\r\nservice httpd restart\r\n\r\n<\/pre>\n<p>Hope, this article helps your need. Please share your valuable comments to improve us.<\/p>\n<p>To find, How to Find and Kill All Zombie Processes in Linux : <a href=\"https:\/\/coimbatorewebhosting.com\/blog\/how-to-find-and-kill-all-zombie-processes-in-linux\/\">Click here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to verify DDOS attack with netstat command on Linux Your server appearing pretty slow could be many things from wrong configs, scripts and dodgy hardware, but sometimes it could be a cause someone is flooding your server with traffic known as DoS ( Denial of Service ) or DDoS [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1845,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[153,154,17,3,1,14],"tags":[],"class_list":["post-1836","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos-7-rhel-7","category-cpanel-whm","category-general","category-linux","category-latest","category-trouble-shootrepair"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2021\/08\/DDOS-attack.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-tC","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1836"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1836\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/1845"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}