この記事は Linux コマンド 全部オレ Advent Calendar 2017 の9日目の記事です。
nslookup
NAME
nslookup - query Internet name servers interactively
SYNOPSIS
nslookup [-option] [name | -] [server]
DESCRIPTION
Nslookup is a program to query Internet domain name servers. Nslookup has two modes:
interactive and non-interactive. Interactive mode allows the user to query name servers
for information about various hosts and domains or to print a list of hosts in a domain.
Non-interactive mode is used to print just the name and requested information for a host
or domain.
ドメイン、IPアドレスに対して正引き(ドメイン -> IP アドレス)・逆引き(IP アドレス -> ドメイン)を行う。
よく使いそうな使い方
[sinsengumi ~]$ nslookup sinsengumi.net
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: sinsengumi.net
Address: 202.172.28.163
[sinsengumi ~]$ nslookup 202.172.28.163
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
163.28.172.202.in-addr.arpa name = s162.coreserver.jp.
Authoritative answers can be found from:
これで sinsengumi.net というドメインは 202.172.28.163 であるということがわかる。
8.8.8.8(Google の Public DNS)が回答している。
dig
NAME
dig - DNS lookup utility
SYNOPSIS
dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-m] [-p port#]
[-q name] [-t type] [-x addr] [-y [hmac:]name:key] [-4] [-6] [name] [type] [class]
[queryopt...]
dig [-h]
dig [global-queryopt...] [query...]
DESCRIPTION
dig (domain information groper) is a flexible tool for interrogating DNS name servers. It
performs DNS lookups and displays the answers that are returned from the name server(s)
that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of
its flexibility, ease of use and clarity of output. Other lookup tools tend to have less
functionality than dig.
Although dig is normally used with command-line arguments, it also has a batch mode of
operation for reading lookup requests from a file. A brief summary of its command-line
arguments and options is printed when the -h option is given. Unlike earlier versions, the
BIND 9 implementation of dig allows multiple lookups to be issued from the command line.
Unless it is told to query a specific name server, dig will try each of the servers listed
in /etc/resolv.conf. If no usable server addreses are found, dig will send the query to
the local host.
When no command line arguments or options are given, dig will perform an NS query for "."
(the root).
It is possible to set per-user defaults for dig via ${HOME}/.digrc. This file is read and
any options in it are applied before the command line arguments.
The IN and CH class names overlap with the IN and CH top level domains names. Either use
the -t and -c options to specify the type and class, use the -q the specify the domain
name, or use "IN." and "CH." when looking up these top level domains.
nslookup は無くなるかもしれないので、dig コマンド使えとのこと。
よく使いそうな使い方
[sinsengumi ~]$ dig sinsengumi.net
; <<>> DiG 9.8.3-P1 <<>> sinsengumi.net
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15507
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;sinsengumi.net. IN A
;; ANSWER SECTION:
sinsengumi.net. 6621 IN A 202.172.28.163
;; Query time: 84 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Dec 10 14:10:54 2017
;; MSG SIZE rcvd: 48
[sinsengumi ~]$ dig -x 202.172.28.163
; <<>> DiG 9.8.3-P1 <<>> -x 202.172.28.163
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41281
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;163.28.172.202.in-addr.arpa. IN PTR
;; ANSWER SECTION:
163.28.172.202.in-addr.arpa. 12385 IN PTR s162.coreserver.jp.
;; Query time: 93 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Dec 10 14:10:56 2017
;; MSG SIZE rcvd: 77
参考
/etc/resolv.conf
そのマシンが使用する DNS サーバを指定しているファイル。