萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

CentOS 安裝 whois 指令:yum search/whatprovides 找套件、jwhois 安裝與使用

CentOS 最小安裝不含 whois 指令,直接 yum install whois 找不到套件。需透過 yum search 或 yum whatprovides 找到提供 /usr/bin/whois 的套件名稱 jwhois。

尋找套件名稱

# 方法 1: search (搜尋名稱/描述)
yum search whois
# 輸出: jwhois.x86_64 : Internet whois/nicname client

# 方法 2: whatprovides (搜尋提供的檔案) - 更精確
yum whatprovides '*/bin/whois'
# 或
yum whatprovides whois
# 輸出: jwhois-4.0-18.el6.x86_64 : Internet whois/nicname client
#       Filename: /usr/bin/whois

安裝 jwhois

sudo yum install -y jwhois
# 完成後 /usr/bin/whois 即可用 (jwhois 提供 whois 符號連結)

驗證與使用

which whois
# /usr/bin/whois

whois google.com
# 輸出域名註冊資訊、DNS 伺服器、到期日等

whois 8.8.8.8
# 輸出 IP 區塊分配資訊

進階用法

# 指定 whois 伺服器
whois -h whois.verisign-grs.com google.com

# 顯示完整回應 (不截斷)
whois -v google.com

# 批次查詢
for domain in google.com github.com linux.org; do
    echo "=== $domain ==="
    whois $domain | head -20
done

whois 安裝示意

替代方案

  • RPM 直接安裝:下載 jwhois-*.rpm → rpm -ivh
  • 原始碼編譯:./configure && make && make install
  • 現代替代:rdap (Registration Data Access Protocol) 客戶端,支援 JSON 輸出

自動化腳本範例

#!/bin/bash
# check_domain_expiry.sh
DOMAIN=$1
EXPIRY=$(whois $DOMAIN | grep -iE 'expir|expire|paid-till' | head -1 | sed 's/.*: //')
echo "$DOMAIN expires: $EXPIRY"
# 整合至監控系統 (Zabbix/Prometheus/Alertmanager)

掌握 yum whatprovides '*/bin/命令' 技巧,可快速解決任何「指令不存在、不知屬於哪個套件」的安裝難題。

copyright © 萬盛學電腦網 all rights reserved