Ale*_*ysh 18 linux dns bash ubuntu hosts-file
Ubuntu 10.10+
在我的脚本中,我需要查找给定主机名的 IP。
如果该名称在 中列出/etc/hosts
,则命令应该打印来自 的 IP /etc/hosts
,而不是来自 DNS 服务器。
我尝试过的命令 ( nslookup
, dig
, host
) 完全忽略/etc/hosts
- 至少对于 DNS 服务器不知道的名称。
注意:我更喜欢不需要我/etc/hosts
手动grep的解决方案。
Ign*_*ams 24
getent
使用低级 glibc 信息函数来查询所有配置的源。
$ getent ahosts amd.com
163.181.249.32 STREAM amd.com
163.181.249.32 DGRAM
163.181.249.32 RAW
$ getent ahosts ipv6.google.com
2001:4860:b009::69 STREAM ipv6.l.google.com
2001:4860:b009::69 DGRAM
2001:4860:b009::69 RAW
Run Code Online (Sandbox Code Playgroud)
$ gethostip localhost
localhost 127.0.0.1 7F000001
$ gethostip -d example.org
192.0.43.10
Run Code Online (Sandbox Code Playgroud)
从syslinux
包中,至少在 Ubuntu 12.04 中。
归档时间: |
|
查看次数: |
22590 次 |
最近记录: |