LoginSignup
7
8

More than 5 years have passed since last update.

使えないコマンドがある時の対応方法

Posted at

現象

CentOS(6.x)を"minimal"でインストールすると、以下のようにnslookup、dig、hostを使えません。

[root@kumotori ~]# nslookup www.google.co.jp
-bash: nslookup: コマンドが見つかりません
[root@kumotori ~]# dig www.google.co.jp
-bash: dig: コマンドが見つかりません
[root@kumotori ~]# host www.google.co.jp
-bash: host: コマンドが見つかりません

対応方法

yum providesによる検索

  • yum providesで、あるコマンドを利用するために必要なパッケージ(RPM)を探すことができます。
    • 正確には、"yum provides */[コマンド名]"と入力します。
  • 以下の結果を見ると、「DNS照会用のユーティリティ(Utilities for querying DNS name servers)」と書かれているので、"bind-utils"をインストールすれば良さそうです。
[root@kumotori ~]# yum provides */nslookup
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
base/filelists_db                                                                                                            | 6.4 MB     00:00     
extras/filelists_db                                                                                                          |  24 kB     00:00     
updates/filelists_db                                                                                                         | 2.0 MB     00:00     
zsh-4.3.11-8.el6.centos.x86_64 : A powerful interactive shell
リポジトリー        : base
一致          :
ファイル名    : /usr/share/zsh/4.3.11/functions/nslookup



32:bind-utils-9.8.2-0.68.rc1.el6.x86_64 : Utilities for querying DNS name servers
リポジトリー        : base
一致          :
ファイル名    : /usr/bin/nslookup



zsh-4.3.11-9.el6_10.x86_64 : A powerful interactive shell
リポジトリー        : updates
一致          :
ファイル名    : /usr/share/zsh/4.3.11/functions/nslookup



32:bind-utils-9.8.2-0.68.rc1.el6_10.1.x86_64 : Utilities for querying DNS name servers
リポジトリー        : updates
一致          :
ファイル名    : /usr/bin/nslookup

bind-utilsのインストール

[root@kumotori ~]# yum install bind-utils -y

動作確認

  • nslookup、dig、hostはいずれも"bind-utils"に含まれているため、"bind-utils"をインストールするだけで全てのコマンドを使えるようになります。
[root@kumotori ~]# nslookup www.google.co.jp
Server:         192.168.10.1
Address:        192.168.10.1#53

Non-authoritative answer:
Name:   www.google.co.jp
Address: 216.58.196.227
[root@kumotori ~]# dig www.google.co.jp

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.1 <<>> www.google.co.jp
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62411
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 4, ADDITIONAL: 8

;; QUESTION SECTION:
;www.google.co.jp.              IN      A

;; ANSWER SECTION:
www.google.co.jp.       144     IN      A       172.217.31.131

;; AUTHORITY SECTION:
google.co.jp.           65244   IN      NS      ns3.google.com.
google.co.jp.           65244   IN      NS      ns4.google.com.
google.co.jp.           65244   IN      NS      ns1.google.com.
google.co.jp.           65244   IN      NS      ns2.google.com.

;; ADDITIONAL SECTION:
ns2.google.com.         172556  IN      A       216.239.34.10
ns3.google.com.         197717  IN      A       216.239.36.10
ns4.google.com.         152584  IN      A       216.239.38.10
ns1.google.com.         163790  IN      A       216.239.32.10
ns2.google.com.         144029  IN      AAAA    2001:4860:4802:34::a
ns3.google.com.         161345  IN      AAAA    2001:4860:4802:36::a
ns4.google.com.         152584  IN      AAAA    2001:4860:4802:38::a
ns1.google.com.         145225  IN      AAAA    2001:4860:4802:32::a

;; Query time: 21 msec
;; SERVER: 192.168.10.1#53(192.168.10.1)
;; WHEN: Fri Feb  1 23:28:03 2019
;; MSG SIZE  rcvd: 308
[root@kumotori ~]# host www.google.co.jp
www.google.co.jp has address 216.58.199.227
www.google.co.jp has IPv6 address 2404:6800:400a:80c::2003

まとめ

  • CentOSをminimalでインストールすると、便利なコマンドがインストールされていないことが多いので注意が必要です。
  • "yum provides"はかなり便利です。
    • 「Googleで検索すれば分かるでしょ」と言われればそれまでですが...
7
8
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
8