简体   繁体   中英

How can I ping many hosts (by dns name and resolve it ip addresses) in bash?

I have many server DNS names and I want to resolve it ip addreses. How can I do that in bash?

You csn not do this in bash directly. bash does not have builtin support for resolving ip addresses. You do need a proramm that will do it.

You could use dig . Eg if you have your names in a file hostnamelist you could use the following script:

while read x; do echo  "$x "`dig +short $x A`; done < hostnamelist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM