{"id":3039,"date":"2024-05-20T13:14:25","date_gmt":"2024-05-20T13:14:25","guid":{"rendered":"https:\/\/bigboxhost.com\/blog\/?p=3039"},"modified":"2024-05-20T13:14:27","modified_gmt":"2024-05-20T13:14:27","slug":"understanding-and-mitigating-ddos-attacks-a-comprehensive-guide","status":"publish","type":"post","link":"https:\/\/bigboxhost.com\/blog\/understanding-and-mitigating-ddos-attacks-a-comprehensive-guide\/","title":{"rendered":"Understanding and Mitigating DDoS Attacks: A Comprehensive Guide"},"content":{"rendered":"\n<p>In today&#8217;s internet-driven world, having a robust website is crucial for success, whether you are a blogger, an eCommerce shop owner, or a local service provider. As businesses increasingly rely on search engines and web traffic to drive sales, the threat from malicious online actors has become more significant. One common and growing threat is the Distributed Denial of Service (DDoS) attack.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is a DDoS Attack?<\/h3>\n\n\n\n<p>A DDoS, or Distributed Denial of Service attack, is a coordinated effort to disable a website by overwhelming its server with traffic from multiple IP addresses. This surge in traffic depletes the server\u2019s resources, making it inaccessible to legitimate users. Similar to a traffic jam, where too many cars slow down the commute, a server flooded with excessive connections can&#8217;t process genuine requests efficiently. Even the most robust servers can succumb to the high volume of connections that a DDoS attack brings.<\/p>\n\n\n\n<p>DDoS attacks can be executed in various ways, such as HTTP floods or Slowloris\u2019 lingering connections, but they all require live connections to the server. Fortunately, these live connections allow you to detect and mitigate an attack in progress.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to Identify a DDoS Attack<\/h3>\n\n\n\n<p>To determine if your server is under a DDoS attack, you need to monitor the server load. Simple commands like <code>uptime<\/code> or <code>top<\/code> can provide an overview of the current load.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Checking Server Load<\/h5>\n\n\n\n<p>The acceptable server load depends on your CPU resources or available threads. Generally, the rule is one load point per thread. Use the following command to find the number of logical processors (threads):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>grep processor \/proc\/cpuinfo | wc -l<\/code><\/code><\/pre>\n\n\n\n<p>To check the server load, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>uptime<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/uSlW7bxQ_ZWY9vSf8o9-Xf8UiXmEg4-r9mDnZv8rwHUSY1FXQcsauUeJuX5KxNBKvk4gEJFxF5D4e_CUvr1V4u5Lxw3XCFNAZ7zwvSXAK4LOOTHSwjLBZ3I-HATQLUs2iamavsip\" alt=\"Terminal window showing current uptime and load average of 0.10, 0.05, and 0.06 \" title=\"load average displays\"\/><\/figure>\n\n\n\n<p>A load average significantly higher than the number of threads may indicate a DDoS attack.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Monitoring Network Traffic<\/h5>\n\n\n\n<p>If your server responds well over backend connections but is slow over the public interface, check your network traffic using tools like <code>nload<\/code>, <code>bmon<\/code>, <code>iftop<\/code>, <code>vnstat<\/code>, or <code>ifstat<\/code>. These tools can be installed via your package manager (apt, yum, etc.).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Identifying Malicious IPs<\/h4>\n\n\n\n<p>Since DDoS attacks involve multiple connections to your server, identifying the IP addresses involved is crucial. Use the <code>netstat<\/code> command to list IP addresses and their connection counts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r<\/code><\/code><\/pre>\n\n\n\n<p>This command will display a descending list of IPs and the number of connections each has. Unusually high numbers of connections from single IPs may indicate an attack.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/JTNVeRsWddkAJomW66D8E0Lkm-bieujQGozsaUjfo7F7kF1P8qptS-IPGZzXY8v3sJtHMx2hiWRHkxfyz8HiHu7Ucn73IOlgxkw0OF9E_eusXisGSWvWkbKpTuXwGaxPIrbCCTNl\" alt=\"Terminal window showing a list of IPs currently connected to the server\" title=\"results\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Mitigating a DDoS Attack<\/h4>\n\n\n\n<p>Once you identify the offending IPs, you can block them using the following commands:<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Blocking IPs Using Route<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code><code>route add ipaddress reject\nroute -n |grep ipaddress<\/code><\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Blocking IPs Using iptables<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code><code>iptables -A INPUT 1 -s IPADDRESS -j DROP\/REJECT\nservice iptables restart\nservice iptables save\n<\/code><\/code><\/pre>\n\n\n\n<p>After blocking the IPs, restart the HTTP service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>killall -KILL httpd\nservice httpd start<\/code><\/code><\/pre>\n\n\n\n<p>Repeat these steps for multiple offending IPs if necessary.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dealing with Multiple IP Attacks<\/h3>\n\n\n\n<p>DDoS attacks using fewer connections spread across many IPs can be harder to diagnose. These attacks often leverage botnets, networks of compromised devices, to generate traffic.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Identifying Common Subnets<\/h5>\n\n\n\n<p>To identify if many connections are from common subnets, use the following commands:<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Finding IPs from the Same \/16 Subnet<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code><code>netstat -ntu|awk '{print $5}'|cut -d: -f1 -s |cut -f1,2 -d'.'|sed 's\/$\/.0.0\/'|sort|uniq -c|sort -nk1 -r<span style=\"background-color: initial; font-family: inherit; font-size: inherit; color: initial;\"><\/span><\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/o3lNT_4Q9egNduQCYa1dz-f9LYBf875haf6M5GWY1SaNXaCWNSetsP6rmUO8ZQEZJmJm7ATPKUnHhh1XaoiKD6OCVHdbBJI_OskjMGzeIB4yf4Ul59aqlbLJY8bZX8hpNWEt1ktk\" alt=\"Terminal window listing IPs starting with the same two octets\" title=\"IP with two octets\"\/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">Finding IPs from the Same \/24 Subnet<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code><code>netstat -ntu|awk '{print $5}'|cut -d: -f1 -s |cut -f1,2,3 -d'.'|sed 's\/$\/.0\/'|sort|uniq -c|sort -nk1 -r<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/ugF6gkfHYhdOx9BifM6QUUxM5US206nXEibhOatvSEH0Ux3aEhOoMxoKS64KrXJdcC7r9JAm-Jd00godbj-yGfedcrPBX7wUgAE3DVM02CEcSGkSt6_bQEzYuCE7-B1EvDGIs3sL\" alt=\"Terminal window listing IPs starting with the same three octets\" title=\"3 octets\"\/><\/figure>\n\n\n\n<p>If a significant number of connections come from the same subnet, it might indicate a coordinated DDoS attack. Mitigate these attacks using the same steps as for single IP attacks, replicated for many IPs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>These techniques offer quick and effective ways to check for and mitigate DDoS attacks. While more advanced tools are available, familiarizing yourself with these methods can strengthen your defenses and provide valuable insights even when not under attack. Protecting your website from DDoS attacks is crucial to maintaining its availability and ensuring the success of your online presence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In today&#8217;s internet-driven world, having a robust website is crucial for success, whether you are a blogger, an eCommerce shop owner, or a local service provider. As businesses increasingly rely on search engines and web traffic to drive sales, the threat from malicious online actors has become more significant. One common and growing threat is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3042,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"Understanding and Mitigating DDoS Attacks: A Comprehensive Guide","_seopress_titles_desc":"DDoS attacks can be executed in various ways, such as HTTP floods or Slowloris\u2019 lingering connections, but they all require live connections to the server. Fortunately, these live connections allow you to detect and mitigate an attack in progress.","_seopress_robots_index":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[2],"tags":[64,62,63,66,68,67,58],"class_list":["post-3039","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kb","tag-attach","tag-ddos","tag-mitigation","tag-netstat","tag-protection","tag-security","tag-server"],"_links":{"self":[{"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/posts\/3039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/comments?post=3039"}],"version-history":[{"count":3,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/posts\/3039\/revisions"}],"predecessor-version":[{"id":3051,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/posts\/3039\/revisions\/3051"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/media\/3042"}],"wp:attachment":[{"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/media?parent=3039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/categories?post=3039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bigboxhost.com\/blog\/wp-json\/wp\/v2\/tags?post=3039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}