博客
关于我
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 virtualenv
查看>>
python vue3实现大文件分段续传(断点续传)--带暂停和继续功能
查看>>
Python WebDriver如何打印整个页面源(html)
查看>>
Python WebSocket自动化测试:构建高效接口测试框架
查看>>
Python Web开发
查看>>
Redis 配置文件杂项。
查看>>
Python web自动化测试 —— 文件上传
查看>>
Python web自动化测试 —— 文件上传!
查看>>
Python Web自动化测试开发环境搭建(附安装包与虚拟机环境)
查看>>
python win32api键盘_Python win32api.keybd_event模拟键盘输入
查看>>
python Windows显示当前鼠标坐标
查看>>
python Workbook 表格宽度
查看>>
python | flanker,一个神奇的 Python 库!
查看>>
python | flower,一个强大的 Python 库!
查看>>
python | funcy,一个超强的 提供函数式编程工具 Python 库!
查看>>
python | ggplot,一个超强的 Python 库!
查看>>
python | grab,一个强大的 Python 库!
查看>>
python | rich,一个无敌的 Python 库!
查看>>
python | rq,一个无敌的 关于Redis 的Python 库!
查看>>
python | unoconv,一个超厉害的 Python 库!
查看>>