博客
关于我
5 个用于在 Linux 终端中查找域名 IP 地址的命令
阅读量:188 次
发布时间:2019-02-28

本文共 2270 字,大约阅读时间需要 7 分钟。

在 Linux 终端中查找域名 IP 地址的 5 个命令

作为 Linux 系统管理员或网络操作员,了解如何快速查找域名对应的 IP 地址是非常重要的。以下是 5 个常用的命令,帮助你轻松完成任务。


1. dig 命令

dig 是一个强大的 DNS 查询工具,可以用来查找域名的 IP 地址。它支持批处理模式,适合处理多个域名。

示例

dig 2daygeek.com | awk '{print $1,$5}'

输出:

104.27.157.177 104.27.156.177

批量查询脚本

#!/bin/bash
for domain in $(cat /opt/scripts/domains-list.txt); do
echo -e "\n$domain -"
dig $domain +short
done | paste -d " " -

将脚本保存为 dig-command.sh 并设置可执行权限:

chmod +x /opt/scripts/dig-command.sh

运行脚本:

sh /opt/scripts/dig-command.sh

2. host 命令

host 是一个简单的 DNS 查询工具,适合快速查找域名的 IP 地址。

示例

host 2daygeek.com | grep "has address" | sed 's/has address/-/g'

输出:

2daygeek.com - 104.27.157.177
2daygeek.com - 104.27.156.177

批量查询脚本

#!/bin/bash
for 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

3. nslookup 命令

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.177
104.27.156.177

批量查询脚本

#!/bin/bash
for 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 -n1
done | paste -d " " -

将脚本保存为 nslookup-command.sh 并设置可执行权限:

chmod +x /opt/scripts/nslookup-command.sh

运行脚本:

sh /opt/scripts/nslookup-command.sh

4. fping 命令

fping 是一个类似 ping 的工具,支持并行发送 ICMP 请求,适合批量检查多个主机的网络状态。

示例

fping -A -d 2daygeek.com magesh.co.in linuxtechnews.com

输出:

104.27.157.177 (104.27.157.177) is alive
104.18.35.52 (104.18.35.52) is alive
104.27.144.3 (104.27.144.3) is alive

5. ping 命令

ping 是一个经典的网络工具,用于测试主机的网络连通性。

示例

ping -c 2 2daygeek.com | head -2 | tail -1 | awk '{print $5}' | sed 's/[😃]//g'

输出:

104.27.157.177

批量查询脚本

#!/bin/bash
for 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/

你可能感兴趣的文章
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty相关
查看>>
Netty遇到TCP发送缓冲区满了 写半包操作该如何处理
查看>>
Netty:ChannelPipeline和ChannelHandler为什么会鬼混在一起?
查看>>
Netty:原理架构解析
查看>>
Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
查看>>
Network Sniffer and Connection Analyzer
查看>>
Network 灰鸽宝典【目录】
查看>>
NetworkX系列教程(11)-graph和其他数据格式转换
查看>>
Networkx读取军械调查-ITN综合传输网络?/读取GML文件
查看>>
network小学习
查看>>
Netwox网络工具使用详解
查看>>
Net与Flex入门
查看>>