15 October 2026 · One command a day
How do I find the top IP addresses hitting my website on Linux?
This command reads your web server's access log, picks out the IP address from each request, and counts how many requests came from each address. Use it when a site slows down, your bandwidth jumps, or you think a bot is scraping you. Within a few seconds you can see who is sending the most traffic.
I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.
The command
sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | headawk '{print $1}' prints the first field of each line, split on spaces. In nginx's default log format, that field is the client IP address. On Ubuntu the log belongs to www-data and the adm group, so you need sudo to read it. sort puts identical addresses next to each other. uniq -c merges lines that are next to each other and match, and puts a count in front of each one. That is why you need the first sort. sort -rn sorts those counts as numbers, largest first. head shows the top ten. If each site has its own access_log line in its server block, use that site's log file instead.
What you will see
8412 203.0.113.45
1290 198.51.100.17
934 127.0.0.1
611 192.0.2.88
402 203.0.113.9
388 198.51.100.230
291 192.0.2.14
207 203.0.113.120
186 198.51.100.4
151 192.0.2.201The number on the left is how many requests that address made in the log, and the address is on the right. Here, one address made far more requests than all the others, so look at it first. 127.0.0.1 is the server itself, often a health check or a local proxy, and you can usually ignore it. To see what a busy address was asking for, search the log for it with grep.
When to use it
- CPU or bandwidth jumps for no clear reason and you want to know if a single client is causing it.
- You are deciding whether to block an address with ufw or rate-limit it in nginx.
- You want to check that a crawler you allowed is behaving and not hammering the site.
Watch out for
If your site sits behind a proxy or CDN such as Cloudflare, the first field may be the proxy's address instead of the real visitor's. The top of the list will then show a few CDN addresses with huge counts, and blocking them would cut off real users. Check this before you block anything. Either set up nginx's real_ip module so the true client address is logged, or log the X-Forwarded-For header and count that field instead.
Questions people ask
How do I include older, rotated logs?
Run sudo zcat -f /var/log/nginx/access.log* and pipe it into the same awk pipeline. The -f flag lets zcat read both the compressed .gz files and the uncompressed ones.
Can I count the most requested pages instead?
Yes. Change $1 to $7, which is the request path in the default log format. The rest of the pipeline stays the same.
Reading raw access logs like this needs shell access to a server you control, which shared hosting rarely gives you. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.
Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.
Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.
Affiliate link.