sodcalculator

10 Tech How-To

Track and Fix High Network Traffic on Linux

Guide 10-58278 · Updated · Step by step

This guide shows you how to identify what is consuming your Linux instance’s bandwidth and how to reduce or stop it. You’ll learn to monitor live traffic, pinpoint the process or connection responsible, and apply fixes ranging from simple service restarts to firewall rules.

What You’ll Need

  • Root or sudo access to your Linux instance
  • SSH access (or a console session)
  • Basic familiarity with the command line
  • Package manager (apt, yum, dnf, etc.) to install tools if needed

Step-by-Step

  1. Check overall traffic with vnstat or iftop
    Install a traffic monitor if you don’t have one. On Debian/Ubuntu: sudo apt install vnstat iftop. On RHEL/CentOS: sudo yum install vnstat iftop. Run vnstat -d to see daily totals, or vnstat -m for monthly. For a live view, run sudo iftop – you’ll see a list of connections and their transfer rates. Press q to quit.
  2. Identify the top bandwidth consumers with nethogs
    Install nethogs (sudo apt install nethogs or sudo yum install nethogs). Run sudo nethogs to see which processes are using the most bandwidth in real time. This is the quickest way to find a rogue process like a misconfigured backup or a compromised script.
  3. List active connections with ss
    Use ss -tup to show TCP/UDP connections with the owning process (requires root). Look for many connections to the same IP or port, or connections to unexpected remote hosts. The State column shows ESTAB for active connections; many in SYN-SENT could indicate a scanning or flooding issue.
  4. Check per-interface traffic with ip or cat /proc/net/dev
    Run ip -s link to see RX/TX bytes and packets per interface. Compare over time to see if traffic is growing. cat /proc/net/dev gives the same raw numbers. If you have multiple interfaces, this helps isolate which one is saturated.
  5. Look for suspicious processes with ps and top
    Run top -o %CPU to sort by CPU usage. A process using high CPU while also sending traffic is a red flag. Use ps aux --sort=-%cpu | head to see the top CPU consumers. Check for unfamiliar process names or paths like /tmp/.
  6. Inspect system logs for clues
    Check /var/log/syslog or /var/log/messages for repeated errors, failed login attempts, or service restarts. Use journalctl -xe on systemd systems. Look for patterns like a service crashing and restarting, which can cause repeated downloads or uploads.
  7. Stop or restart the offending service
    Once you’ve identified the process (e.g., a web server, a sync tool, or a database), restart it with sudo systemctl restart <service>. If it’s a one-off script, kill it with sudo kill <PID>. For a service you don’t need, disable it: sudo systemctl disable --now <service>.
  8. Block unwanted traffic with firewall rules
    Use ufw (Ubuntu) or firewalld (RHEL) to block specific IPs or ports. For example, to block an IP with ufw: sudo ufw deny from 203.0.113.5. To block a port: sudo ufw deny 8080. With firewalld: sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.5" reject' then sudo firewall-cmd --reload.
  9. Rate-limit or throttle bandwidth if needed
    For a service that must run but is using too much, use tc (traffic control) to limit its rate. For example, to limit an IP to 1Mbps: sudo tc qdisc add dev eth0 root handle 1: htb default 10 and then sudo tc class add dev eth0 parent 1: classid 1:10 htb rate 1mbit. This is advanced; test carefully.
  10. Monitor after the fix
    Re-run vnstat -d or iftop to confirm traffic has dropped. Keep an eye on it for a few hours to ensure the issue doesn’t return.

Common Mistakes

  • Ignoring IPv6 – Traffic may be going over IPv6 while you only monitor IPv4. Use ss -6 to see IPv6 connections.
  • Killing the wrong process – Always verify the PID with ps -p <PID> before killing.
  • Blocking your own IP – If you use a firewall rule, make sure you don’t lock yourself out. Test with a rule that allows your IP first.
  • Not checking for malware – High traffic can be a sign of a compromised system. Run a rootkit checker like rkhunter or chkrootkit.
  • Forgetting to save firewall rules – With iptables, rules are lost on reboot unless you save them. Use iptables-save or the distribution’s persistent mechanism.

Tips

  • Use nload for a simple real-time graph of total bandwidth per interface.
  • Set up vnstat to run as a daemon so you have historical data to compare.
  • If you suspect a DDoS, check ss -s for connection stats and consider using a CDN or cloud provider’s DDoS protection.
  • Keep your system updated to patch vulnerabilities that could be exploited to generate traffic.
  • Use lsof -i to list open network files and their owning processes – useful for spotting unexpected listeners.

Troubleshooting

  • Tools not installed? If you can’t install packages due to no internet, use built-in commands: ss, ip, ps, and cat /proc/net/dev are always available.
  • Traffic is high but no process shows it? It could be kernel-level (e.g., a network driver issue) or a hardware problem. Check dmesg for errors. Also try tcpdump -i eth0 to see raw packets.
  • Firewall rules not working? Ensure the service is using the port you think. Use ss -tlnp to see listening ports and their processes.
  • Traffic returns after reboot? A service may be set to start at boot. Check systemctl list-unit-files | grep enabled and disable anything you don’t need.
  • Can’t kill a process? Try sudo kill -9 <PID> as a last resort. If it keeps respawning, look for a parent process or a cron job that restarts it.

Frequently Asked Questions

How do I see which IP is using the most bandwidth?

Use sudo iftop -n to show IPs without DNS resolution, sorted by bandwidth. The top entries are the biggest consumers.

What is the difference between iftop and nethogs?

iftop shows traffic per connection (IP and port), while nethogs shows traffic per process. Use both to get a complete picture.

Can I limit bandwidth for a specific user?

Yes, with tc (traffic control) you can shape traffic by IP, port, or even user ID. It’s complex; consider using a tool like wondershaper for simpler setups.

Why is my bandwidth usage high even when I’m not doing anything?

Background services like system updates, package repositories, or cloud agent telemetry can run automatically. Check vnstat -d to see when the traffic occurs and correlate with cron jobs.

Is high outbound traffic always bad?

Not necessarily – if you run a web server or backup service, outbound traffic is normal. The key is to compare against your baseline and investigate sudden spikes.

How do I permanently block an IP address?

Use your firewall’s persistent rules. For ufw: sudo ufw deny from <IP>. For firewalld: sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<IP>" drop' and reload.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →