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

本文共 2250 字,大约阅读时间需要 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/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

2. host 命令

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

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

4. fping 命令

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

5. ping 命令

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/

你可能感兴趣的文章
python出现 unknown encoding: idna 的处理方法
查看>>
Python出现 RuntimeError: dictionary changed size during iteration 的解决方法
查看>>
Python-numpy(2)数组的操作
查看>>
Python-Numpy的tile函数用法
查看>>
python-open函数
查看>>
Python-Pandas-将特定函数应用于给定级别-多索引数据框架
查看>>
python-queue队列通信
查看>>
python-ros No module named PyKDL
查看>>
python-social-auth 是否需要会话
查看>>
Python再获年度编程语言,微软或成最大赢家
查看>>
python-week5
查看>>
Python写表情包搜索工具(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Python-【1】配置
查看>>
Python-从子文件夹执行绝对导入
查看>>
Python-刷新页面,直到元素可单击
查看>>
PYTHON-唤醒+VOSK+DEEPSEEK+离线合成-实现纯离线大模型问答
查看>>
Python-在Dash回调中重用函数
查看>>
PYTHON-基本数据类型-元祖类型,字典类型,集合类型
查看>>
python-外观模式
查看>>
Python-如何使用FastAPI和uvicorn.run而不阻塞线程?
查看>>