nginx-logresolver is a Bash script that processes Nginx access logs and resolves IP addresses to hostnames in real time. It improves the readability of logs by replacing IPs with their corresponding hostnames using system DNS resolution. The script optionally colorizes the output and checks if dnsmasq is installed to improve performance via local DNS caching.
By default, Nginx logs contain raw IP addresses instead of hostnames. This is intentional: resolving hostnames requires DNS lookups, which are relatively slow and can degrade performance under high traffic.
However, hostnames can be helpful for:
- Identify traffic from known domains or bots
- Spot patterns in abuse or suspicious activity
- Debug or audit logs with more context
This script reads logs after they are written, performing DNS resolution on-the-fly without changing Nginx’s configuration or degrading its performance.
- Resolves IP addresses to hostnames in real time as logs are written.
- Checks if
dnsmasqis installed and suggests using it for faster local DNS caching. - Optional colored output via the
-c/--colorflag (requiresgrc). - Skips confirmation prompts using the
-y/--yesflag. - Lightweight and minimal — pure Bash with no caching layer.
bashgetentfor DNS resolutiongrc(optional, for colored output)taildnsmasq(Not required in the script. It's optional but adds dns caching. you can use any other dns forwarder/resolver that enables query caching as well)- Access to your Nginx logs (default:
/var/log/nginx/access.log— can be customized)
git clone https://github.com/spithash/nginx-logresolver.git
cd nginx-logresolver
chmod +x nginx-logresolver.sh./nginx-logresolver.sh./nginx-logresolver.sh -c./nginx-logresolver.sh -y- Tails logs in real time: Watches
/var/log/nginx/access.logand processes new entries as they appear. - Resolves IPs to hostnames: Uses
getent hoststo replace the IP address in each log line with its corresponding hostname. - Suggests dnsmasq: If
dnsmasqis not found in common system paths, warns the user that enabling it will improve performance by caching DNS queries. - Adds color: If
-cis specified andgrcis installed, applies syntax highlighting to logs usinggrc.
host.example.com - - [07/May/2025:10:42:31 +0000] "GET /index.html HTTP/1.1" 200 1024 "-" "Mozilla/5.0"