When your server’s bandwidth cap is nearly exhausted, you need to stop or throttle access before your provider cuts you off or charges overage fees. This guide covers practical steps to limit incoming traffic, prioritize critical services, and communicate with users—using tools you likely already have on Linux servers, plus a few common tricks for shared hosting.
What You’ll Need
- SSH or terminal access to your server (root or sudo privileges recommended)
- Knowledge of your web server software (Apache, Nginx, or LiteSpeed)
- If using shared hosting, access to cPanel or similar control panel
- A list of your critical services (e.g., website, API, email) and their typical ports
- Optional: a bandwidth monitoring tool like vnstat or iftop (install if not present)
Step-by-Step
- Confirm the bandwidth situation. Log in via SSH and run
vnstat -doriftopto see current usage. On shared hosting, check your control panel’s bandwidth stats. This tells you how much you’ve used and if you’re still being hit. - Identify the biggest traffic sources. Use
iftop -nto see which IPs or interfaces are consuming the most. If you see a single IP hammering you, it might be a bot or a scraper. If it’s normal user traffic, you’ll need broader measures. - Block or throttle specific IPs (if applicable). If one or a few IPs are the problem, block them with iptables:
iptables -A INPUT -s 192.0.2.10 -j DROP. To throttle instead of block, usetc(traffic control) but that’s more complex; for most cases, blocking is simpler. - Limit web server connections. For Apache, edit the config (e.g.,
/etc/apache2/apache2.conf) and reduceMaxRequestWorkersandKeepAliveTimeout. For Nginx, adjustworker_connectionsandkeepalive_timeout. This reduces concurrent connections, slowing down overall throughput. - Enable bandwidth throttling in your web server. Nginx has
limit_rate(e.g.,limit_rate 100k;in a location block). Apache uses mod_bandwidth or mod_evasive (if installed). Set a low rate like 50-100 KB/s per client to drastically cut usage. - Block heavy file types or directories. If large downloads are eating bandwidth, deny access to those paths. For Nginx:
location ~ \.(mp4|zip)$ { deny all; }. For Apache:.Require all denied - Serve a temporary maintenance page. If you need to stop all non-essential traffic, replace your site with a simple HTML page (e.g., “We’ll be back shortly”). This stops dynamic requests and large assets, using minimal bandwidth. For Nginx, point your root to a static file; for Apache, use
RedirectMatchor a simple index.html. - Disable bandwidth-heavy features. Turn off RSS feeds, disable image hotlinking (via .htaccess or Nginx config), and block known bots (e.g., using a robots.txt with
Disallow: /for non-essential crawlers). This reduces background traffic. - Consider rate limiting at the firewall level. Use iptables to limit new connections per IP:
iptables -A INPUT -p tcp --dport 80 -m state --state NEW -m recent --setand then a limit rule. This prevents a flood of new connections. - Monitor the effect. After each change, watch
iftoporvnstatto see if bandwidth usage drops. Adjust limits as needed.
Common Mistakes
- Blocking your own IP. Double-check your IP before adding a drop rule. Use
curl ifconfig.meto see your current IP. - Throttling too aggressively. Setting limit_rate to 1 KB/s will make your site unusable. Start with a moderate value and lower it gradually.
- Forgetting about HTTPS. If you use SSL, make sure you’re limiting port 443 as well as port 80. Many sites get most traffic on HTTPS.
- Not testing after changes. Always test with a browser or curl after editing configs. A syntax error can take your site down entirely.
- Ignoring email or other services. Bandwidth isn’t just web traffic. If you run mail, that also counts. Limit SMTP connections if needed.
Tips
- Use a CDN or caching layer. If you have time, put a caching proxy like Varnish or Cloudflare in front. This reduces origin bandwidth significantly for static assets.
- Compress responses. Enable gzip or brotli in your web server. This reduces the actual bytes sent, especially for text-heavy pages.
- Prioritize critical services. If you have an API and a website, keep the API at full speed and throttle the website. Use different server blocks or vhosts with different limits.
- Communicate with users. Put a notice on your site or social media that you’re limiting access due to bandwidth. This sets expectations.
- Set up alerts for next time. Use a monitoring tool to warn you at 80% of your cap so you can act earlier.
Troubleshooting
- Site becomes completely unreachable. Check your web server config syntax (e.g.,
nginx -torapachectl configtest). If you made a mistake, revert the last change. If you blocked all IPs, you may need to access the server via console (e.g., VPS provider’s web terminal) to fix iptables. - Bandwidth still high after blocking IPs. The traffic may be distributed (DDoS). In that case, consider null-routing the attacked IP or using a DDoS protection service. For a legitimate spike, you may need to go to maintenance mode.
- Limits not taking effect. For Nginx, remember to reload:
nginx -s reload. For Apache,systemctl reload apache2. Also ensure you edited the correct server block or location. - Users complain of slow access. That’s expected when throttling. Check if your limit is too low. If you can, selectively allow certain IP ranges (e.g., your office) to bypass limits.
- Iptables rules disappear after reboot. Use
iptables-saveand restore, or use a firewall tool like ufw or firewalld to persist rules.
Frequently Asked Questions
Can I limit bandwidth per user without blocking?
Yes, using web server modules like mod_bandwidth for Apache or limit_rate in Nginx. This throttles each client’s speed, reducing total usage while keeping the site accessible.
What if I’m on shared hosting and don’t have SSH?
Use cPanel’s bandwidth tools to see usage. You can often set a ‘hotlink protection’ to block external images, and you can upload a maintenance page via File Manager. For IP blocking, use .htaccess with ‘deny from’ rules.
Will blocking bots help much?
Often yes. Bots and scrapers can consume a large portion of bandwidth. Blocking known bad bots via .htaccess or Nginx rules can free up significant resources.
How do I know which files are eating bandwidth?
Check your web server access logs. Tools like GoAccess or Webalizer can show top requested files by bytes sent. Look for large videos, PDFs, or images.
Is it better to block or throttle?
Throttling is less disruptive; users can still access content, just slower. Blocking is for emergencies or abusive IPs. If you’re close to the cap, throttling might not reduce usage enough, so blocking may be necessary.
Can I set a daily bandwidth limit?
Not easily with standard web servers. You’d need a script that monitors usage and automatically applies rules, or use a firewall like fail2ban with custom actions. For most, manual monitoring is simpler.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Philips DST7060/20 7000 Series Iron: Specs & Fit
- Coal Fueled Jet Aircraft: Could It Work?675 L
- Remote Desktop on Raspberry Pi: How to Enable It
- Word Select Last Line in Paragraph?
- Google Assistant IFTTT Recipes: 7 Useful Automations
- OLED TVs in Dark Rooms: Why They Look Better and When They Don’t