本文共 2270 字,大约阅读时间需要 7 分钟。
作为 Linux 系统管理员或网络操作员,了解如何快速查找域名对应的 IP 地址是非常重要的。以下是 5 个常用的命令,帮助你轻松完成任务。
dig 是一个强大的 DNS 查询工具,可以用来查找域名的 IP 地址。它支持批处理模式,适合处理多个域名。
dig 2daygeek.com | awk '{print $1,$5}' 输出:
104.27.157.177 104.27.156.177
#!/bin/bashfor domain in $(cat /opt/scripts/domains-list.txt); do echo -e "\n$domain -" dig $domain +shortdone | paste -d " " -
将脚本保存为 dig-command.sh 并设置可执行权限:
chmod +x /opt/scripts/dig-command.sh
运行脚本:
sh /opt/scripts/dig-command.sh
host 是一个简单的 DNS 查询工具,适合快速查找域名的 IP 地址。
host 2daygeek.com | grep "has address" | sed 's/has address/-/g'
输出:
2daygeek.com - 104.27.157.1772daygeek.com - 104.27.156.177
#!/bin/bashfor domain in $(cat /opt/scripts/domains-list.txt); do echo -e "\n$domain -" host $domain | grep "has address" | sed 's/has address/-/g'done | paste -d " " -
将脚本保存为 host-command.sh 并设置可执行权限:
chmod +x /opt/scripts/host-command.sh
运行脚本:
sh /opt/scripts/host-command.sh
nslookup 是一个用于查询 DNS 名称服务器的工具,可以帮助你获取域名的 IP 地址。
nslookup -q=A 2daygeek.com | tail -n+4 | sed -e '/^\n/d' -e 's/Address://g' | grep -v 'Name|answer' | xargs -n1
输出:
104.27.157.177104.27.156.177
#!/bin/bashfor domain in $(cat /opt/scripts/domains-list.txt); do echo -e "\n$domain -" nslookup -q=A $domain | tail -n+4 | sed -e '/^\n/d' -e 's/Address://g' | grep -v 'Name|answer' | xargs -n1done | paste -d " " -
将脚本保存为 nslookup-command.sh 并设置可执行权限:
chmod +x /opt/scripts/nslookup-command.sh
运行脚本:
sh /opt/scripts/nslookup-command.sh
fping 是一个类似 ping 的工具,支持并行发送 ICMP 请求,适合批量检查多个主机的网络状态。
fping -A -d 2daygeek.com magesh.co.in linuxtechnews.com
输出:
104.27.157.177 (104.27.157.177) is alive104.18.35.52 (104.18.35.52) is alive104.27.144.3 (104.27.144.3) is alive
ping 是一个经典的网络工具,用于测试主机的网络连通性。
ping -c 2 2daygeek.com | head -2 | tail -1 | awk '{print $5}' | sed 's/[😃]//g' 输出:
104.27.157.177
#!/bin/bashfor domain in $(cat /opt/scripts/domains-list.txt); do echo -e "\n$domain -" ping -c 2 $domain | head -2 | tail -1 | awk '{print $5}' | sed 's/[😃]//g'done | paste -d " " - 将脚本保存为 ping-command.sh 并设置可执行权限:
chmod +x /opt/scripts/ping-command.sh
运行脚本:
sh /opt/scripts/ping-command.sh
这些命令为你提供了查找域名 IP 地址的灵活选择,根据具体需求选择最适合的工具。
转载地址:http://onti.baihongyu.com/