Skip to main content
1 of 2
0xKate
  • 133
  • 6

How to append arguments to the command xargs is executing? (host command for instance)

I am writing a dns tool and require "| xargs host" and this works however the host command is doing the lookups agains the dns servers configured in /etc/resolv.conf.

I was running some tests and read the man page for xargs but cant figure out how to specify the dns server with host + xargs.

ex.

printf "google.com\nyahoo.com\nbing.com\n" > hosts.txt
cat hosts.txt | xargs -n1 host

This will lookup the 3 domains and output, but the dns server doing the lookup is the one configured under /etc/resolv.conf

To specify a dns server with host you typically just append the server at the end of the command:

"host google.com 8.8.8.8"

I am looking for something like this:

Mock up:

server_to_query=8.8.8.8 ; cat hosts.txt | xargs -n1 host <xargs input> $server_to_query

However, this is what is happening:

server_to_query=8.8.8.8 ; cat hosts.txt | xargs -n1 host $server_to_query <xargs input>

Results are $server_to_query is being looked up against and I'm looking for the opposite to happen.

If I cant do it with xargs I suppose I can just use a for loop, or use dig, but would prefer to use xargs and host.

0xKate
  • 133
  • 6