Let's say I have a list of IPs coming into a log that I'm tailing:
1.1.1.1
1.1.1.2
1.1.1.3
I'd like to easily resolve them to host names. I'd like to be able to
tail -f access.log | host -
Which fails as host doesn't understand input from stdin in this way. What's the easiest way to do with without having to write a static file or fallback to perl/python/etc.?
The dig (domain information groper) command is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the queried name server(s).
The DIG command works by performing a DNS query from your device to the targeted IP address or hostname. The query will first arrive at your ISP's recursive name servers. If there, it has your answer, it will return it fast. If no, your query will be re-routed in search of the answer.
dig uses the OS resolver libraries. nslookup uses is own internal ones. That is why Internet Systems Consortium (ISC) has been trying to get people to stop using nslookup for some time now.
By default, dig commands will query the name servers listed in /etc/resolv. conf to perform a DNS lookup for you. You can change this default behavior by using the @ symbol followed by a hostname or IP address of the name server along. The following dig command sends the DNS query to Google's name server(8.8.
Use xargs -l
:
tail -f access.log | xargs -l host
You could also use the read builtin:
tail -f access.log | while read line; do host $line; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With