[英]How to request IPv4 address from a machine name?
In my linux cluster, I've got a bunch of hostnames, while my network management log shows ip addresses(they changes sometimes according to dns). 在我的linux群集中,我有一堆主机名,而我的网络管理日志中显示了IP地址(有时会根据dns进行更改)。
My question is: how to quickly find out the ipv4 of some hostname, without using "ping xxxxx" to get ip address and Ctrl+c to stop it. 我的问题是:如何快速找出某个主机名的ipv4,而无需使用“ ping xxxxx”获取ip地址和Ctrl + c停止它。 I wish to write a simple script like:
我希望编写一个简单的脚本,例如:
myCommand hostname1
myCommand hostname2
myCommand hostname3
myCommand hostname4
myCommand hostname5
Which will print hostname to ipaddress mapping for me(for hostname1-5) 这将为我打印主机名到ipaddress的映射(对于主机名1-5)
So how to write this "myCommand" command or shell script? 那么如何编写此“ myCommand”命令或Shell脚本? Thanks.
谢谢。
Use host
tool from bind-tools : 使用bind-tools中的
host
工具 :
$ host -4 -t A stackoverflow.com
stackoverflow.com has address 151.101.129.69
stackoverflow.com has address 151.101.1.69
stackoverflow.com has address 151.101.193.69
stackoverflow.com has address 151.101.65.69
Or dig
tool from the same package: 或从同一软件包中
dig
工具:
$ dig -4 -t A stackoverflow.com +short
151.101.129.69
151.101.1.69
151.101.193.69
151.101.65.69
#!/usr/bin/env bash
function get_ip {
echo $1
getent hosts $1 | awk '{ print $1 }' | sed 's/^/ /g'
echo
}
Usage: 用法:
get_ip unix.stackexchange.com
get_ip hostname1
get_ip hostname2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.