Closed7

pingとかnslookupとか、よく分からない

techno.kokitechno.koki

hostコマンド
正引きに使うっぽい

boku $ host www.google.com
www.google.com has address 172.217.175.4
www.google.com has IPv6 address 2404:6800:4004:81c::2004

という感じ

techno.kokitechno.koki

digコマンド

DNSサーバーに問い合わせる

主に、以下の通り
HEADER:問い合わせが成功・失敗などの情報
QUESTION SECTION:問い合わせ内容
ANSWER SECTION:問い合わせ結果

色々詳しい解説はこれにあり
https://mochikoastech.hatenablog.com/entry/archives/187

dig www.google.com

; <<>> DiG 9.10.6 <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32038
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;www.google.com.			IN	A

;; ANSWER SECTION:
www.google.com.		204	IN	A	172.217.175.4

;; Query time: 80 msec
;; SERVER: 180.235.96.248#53(180.235.96.248)
;; WHEN: Mon Jun 14 17:33:55 JST 2021
;; MSG SIZE  rcvd: 59
techno.kokitechno.koki

nslookup コマンド
DNSサーバーに問い合わせる
digコマンドと似たような感じだけど、こっちの方は返却結果を見やすいように整形してくれる感じらしい

boku $ nslookup www.google.com
Server:		180.235.96.248
Address:	180.235.96.248#53

Non-authoritative answer:
Name:	www.google.com
Address: 172.217.175.4
techno.kokitechno.koki

ping コマンド
パケットを送って、返ってくるか確認する
簡単に接続可否を判断するのに使える

boku $ ping www.google.com
PING www.google.com (142.250.76.132): 56 data bytes
64 bytes from 142.250.76.132: icmp_seq=0 ttl=53 time=51.599 ms
64 bytes from 142.250.76.132: icmp_seq=1 ttl=53 time=74.899 ms
64 bytes from 142.250.76.132: icmp_seq=2 ttl=53 time=48.424 ms
^C
--- www.google.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 48.424/58.307/74.899/11.803 ms```

↑ 返ってきている

boku $ ping www.hoge.huga.com
PING www.hoge.huga.com (52.20.84.62): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
^C
--- www.hoge.huga.com ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss

↑ 返ってこない→疎通できない

techno.kokitechno.koki

curl コマンド
プロトコルやポートを指定して、疎通確認ができる
※疎通確認というか、外部API叩いたり、サイトにアクセスすることを目的として使う場面が多い

boku $ curl http://abehiroshi.la.coocan.jp/
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta name="GENERATOR" content="JustSystems Homepage Builder Version 20.0.6.0 for Windows">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>???????̃z?[???y?[?W</title>
</head>
<frameset cols=18,82>
  <frame src="menu.htm" marginheight="0" marginwidth="0" scrolling="auto" name="left">
  <frame src="top.htm" marginheight="0" marginwidth="0" scrolling="auto" name="right">
  <noframes>
  <body></body>
  </noframes>
</frameset>
</html>
techno.kokitechno.koki

これぐらい知っておけば、困ることはあまりないかなー
各コマンドにオプションが色々あるけど、使いながら知っていこう

このスクラップは2021/07/07にクローズされました