Linux Server Monitoring: htop, iftop, vnstat and NetFlow
Linux server monitoring starts with four small tools: htop for CPU and memory, iftop for per-connection traffic, nload for live interface throughput, and vnstat for history. They answer "what is happening on this box right now?" in under a minute. For attack detection across a whole network, you need flow-based monitoring (NetFlow, IPFIX, or sFlow), which shows who is sending what to which prefix, even when the host itself is too saturated to tell you.
This guide covers both layers: quick on-host checks, then a working flow collector setup you can build yourself.
Which tool answers which question
| Question | Tool | Scope |
|---|---|---|
| Which process is eating CPU or RAM? | htop | Host |
| Which remote IP is using my bandwidth? | iftop | Host, live |
| How full is the interface right now? | nload | Host, live |
| How much traffic did I use this week? | vnstat | Host, history |
| Who is attacking which prefix? | NetFlow/IPFIX/sFlow | Network-wide |
Install the basics
On Debian or Ubuntu:
sudo apt update
sudo apt install -y htop iftop nload vnstat
On AlmaLinux or Rocky Linux, enable EPEL first, then use dnf install htop iftop nload vnstat.
Find your interface name before running anything:
ip -br link
ip route get 1.1.1.1
The second command shows the interface that carries default-route traffic. Examples below use eth0; yours may be ens3, enp3s0, or similar.
htop: CPU, memory, and load
Run htop and check these first:
- Load average (top right) compared with your core count. A load of 8 on a 4-vCPU VDS means a queue is building.
- CPU bars colors. Red is kernel time, green is user time. High red with a network spike often means packet processing or conntrack pressure, not an application bug.
- si (softirq) in the CPU meter. Press F2, Setup, Display options, and enable detailed CPU time. Heavy softirq during a traffic spike points at packet-rate load on the NIC.
- MEM bar. Green is used, blue is buffers, yellow/orange is cache. Cache is reclaimable, so do not panic over a full bar.
Useful keys: F6 to sort by a column, F4 to filter by name, t for tree view, u to filter by user.
iftop: who is talking to your server
iftop shows live bandwidth per connection pair. It needs root:
sudo iftop -i eth0 -nNP
-nskips DNS lookups (essential during an incident; resolvers can hang)-Nshows port numbers instead of service names-Pshows ports
Inside iftop, press t to cycle display modes, s or d to hide source or destination, and L to toggle the scale. The three right-hand columns are 2-, 10-, and 40-second averages, so you can tell a burst from sustained load.
To focus on one service:
sudo iftop -i eth0 -nNP -f "dst port 443"
The -f option takes a pcap filter. Keep in mind iftop captures packets in userspace, so on a server at high packet rates it adds load and will drop packets. Use it for diagnosis, not as a permanent monitor.
nload: is the interface saturated?
nload -u M eth0
nload draws incoming and outgoing graphs with current, average, minimum, maximum, and total values. -u M displays in megabytes; use -u m for megabits, which matches how most providers describe port speeds. Compare the peak against your port speed. If outgoing is flat at the ceiling, you are saturated, and the cause might be legitimate load, a misbehaving client, or reflection traffic.
vnstat: history without a database server
vnstat reads kernel interface counters and stores them in a small local database, so it costs almost nothing:
sudo systemctl enable --now vnstat
vnstat --add -i eth0 # only needed on some versions
vnstat -i eth0 -l # live mode
vnstat -i eth0 -h # hourly
vnstat -i eth0 -d # daily
vnstat -i eth0 -m # monthly
Give it a few minutes before expecting data. The hourly view is the one to check after an incident: a sudden 3 AM jump in inbound traffic that no one explains is a strong lead. For graphs, vnstati can render PNGs for a web page.
Quick attack triage on the host
When the server feels slow and the tools above show a spike, a few commands narrow it down:
ss -s # socket summary
ss -ant state syn-recv | wc -l # half-open connections
ss -ant | awk '{print $1}' | sort | uniq -c # connection states
sudo conntrack -C # conntrack entries (if installed)
cat /proc/sys/net/netfilter/nf_conntrack_max
sudo tcpdump -ni eth0 -c 200 'udp' | head -30 # sample UDP sources
Thousands of SYN-RECV entries suggest a SYN flood. Lots of inbound UDP from port 53, 123, or 11211 to random ports suggests reflection/amplification. A conntrack count near its max means new legitimate connections will be dropped.
The limitation is obvious: if the uplink is full, packets are discarded upstream before your host sees them. These tools show what arrives, not what was lost. That is where flow data comes in.
Flow-based monitoring: seeing the whole network
A flow record summarizes a conversation: source and destination IP, ports, protocol, packet and byte counts, TCP flags, and timestamps. Routers and switches export these records to a collector over NetFlow v5/v9, IPFIX, or sFlow. Because the data comes from the network edge, you see traffic toward every IP in your prefixes, not only one host. That makes flow data the standard source for DDoS detection and capacity planning.
If your device cannot export flows (a plain Linux VDS, for example), you can generate them with softflowd.
Build a small collector with nfdump
On the collector (example IP 192.0.2.10):
sudo apt install -y nfdump
sudo mkdir -p /var/cache/nfdump
sudo nfcapd -w -D -p 2055 -l /var/cache/nfdump -T all
sudo ss -ulnp | grep 2055
On a Linux host or router that should export flows:
sudo apt install -y softflowd
sudo softflowd -i eth0 -n 192.0.2.10:2055 -v 9
Allow UDP 2055 from the exporter to the collector in your firewall, and nothing else. Flow data reveals your traffic patterns, so do not expose the collector.
Query the data
After a few minutes, files appear in /var/cache/nfdump. Top destinations by packets in recent files:
nfdump -R /var/cache/nfdump -s dstip/packets -n 10
Top sources hitting one protected address:
nfdump -R /var/cache/nfdump -s srcip/bytes -n 20 'dst ip 198.51.100.25'
Look at UDP reflection by source port:
nfdump -R /var/cache/nfdump -s srcport/bytes -n 10 'proto udp and dst ip 198.51.100.25'
What an attack tends to look like in flow data:
- UDP reflection: many source IPs, one well-known source port (53, 123, 389, 1900, 11211), large average packet size, one destination.
- SYN flood: TCP with only the SYN flag, tiny packets, high packet rate, often spoofed and widely spread sources.
- Carpet bombing: moderate traffic to many addresses in the same /24, which stays under per-IP thresholds but adds up across the prefix. Aggregate by prefix, not just by host.
Tuning flow settings
- Sampling: at high rates, routers sample (for example 1 in 1000 packets). Multiply counts by the sampling rate or your numbers will look far too low.
- Timeouts: long active timeouts delay detection. Set exports to push active flows every 30 to 60 seconds or so.
- Time sync: run chrony or NTP on exporters and collector, or correlating events will be confusing.
Turning flow data into alerts
Querying by hand works during an incident, but attacks rarely wait for business hours. You need baselines and thresholds: packets per second and bits per second per destination IP and per prefix, plus rules for protocol anomalies. When a threshold trips, alert someone, and if you announce your own prefixes, trigger a mitigation step such as filtering or RTBH through your upstream.
You can script this with nfdump and cron, or use a purpose-built system. NixMon is Nixcon's flow-based network monitoring and DDoS detection service. It is built for networks that want that visibility without maintaining their own collector stack. Nixcon operates AS40368 with POPs in Frankfurt and Fremont and a main data center in Izmir, so the same flow-visibility approach applies to the network we run ourselves.
Common mistakes and fixes
- Leaving DNS lookups on in iftop. Always use
-n. Slow reverse DNS makes the tool useless during a flood. - Reading the wrong interface. On servers with bridges, VLANs, or tunnels, check
ip -br link. Traffic inside a GRE or WireGuard tunnel appears on the tunnel interface, noteth0. - Trusting host counters during saturation. If the uplink is full, the loss happens before your server. Compare with provider-side or flow data.
- Forgetting sampling math. Unscaled sampled counters understate the attack.
- Monitoring only by host. Prefix-level aggregation catches carpet bombing.
- No baseline. A graph you never looked at on a quiet day tells you nothing on a bad day. Let vnstat and your collector run for a couple of weeks.
- Collector open to the internet. Restrict UDP 2055 (or your port) to exporter IPs.
A practical routine
- Run vnstat permanently on every server.
- Keep htop, iftop, and nload installed for on-call use.
- Export flows from every edge device to one collector.
- Define per-IP and per-prefix thresholds from your baseline.
- Test alerts and response steps before you need them.
For mitigation after detection, see Nixcon's DDoS protection and firewall options, and use the public looking glass to check how your routes appear from our locations.
Frequently asked questions
What is the difference between iftop and nload?
nload shows total throughput on an interface as a live graph, so it answers whether the link is busy. iftop breaks traffic down by remote host and port, so it answers who is using the bandwidth. Use nload first, then iftop to find the source.
Is vnstat accurate enough for billing or audits?
vnstat reads kernel interface counters, so it is generally close to the real byte counts on that interface. It resets with interface or counter changes and cannot see traffic dropped upstream, so treat it as a strong local reference and not the authoritative record from your provider.
Can I detect a DDoS attack with htop and iftop alone?
You can often notice one on the host, through high softirq load, many SYN-RECV sockets, or a flood of UDP from one source port. But if the uplink is saturated, packets are lost before the server sees them. Flow data from the network edge gives a more complete picture and works for whole prefixes.
What is the difference between NetFlow, IPFIX, and sFlow?
NetFlow v9 and IPFIX export flow records that summarize conversations, and IPFIX is the IETF standard based on NetFlow v9. sFlow samples packets and counters from the device and exports them. All three can feed DDoS detection, but remember to account for sampling rates when reading counts.