18
19

More than 3 years have passed since last update.

tracerouteを使って、TCP,UDPのポートが開通しているか確認する。

Last updated at Posted at 2019-03-24

ルータ、FWを間に挟むNWで、通信不通の事象があり、原因切り分けのメモ

途中のNW機器で遮断されず、あて先まで通信している例

ICMP

あて先までルーティングが通っているか、IP到達可能かを確認。

linux : traceroute -I DEST-IP
osx   : traceroute -P icmp DEST-IP 

$ sudo traceroute -n -q 1 -I 192.168.0.120 
traceroute to 192.168.0.120 (192.168.0.120), 30 hops max, 60 byte packets
 1  192.168.4.1  3.012 ms
 2  192.168.1.1  23.497 ms
 3  192.168.1.254  24.483 ms
 4  192.168.0.120  24.598 ms

TCP

SYNを送信し、Time-to-live exceededを待っている。「!x」が帰ってきていると、そこで遮断されている。

linux : traceroute -T -p PORT DEST-IP
osx   : traceroute -P tcp -p PORT DEST-IP

DEST-IPのPORTまで疎通した場合、応答あり。

$ sudo traceroute -n -q 1 -T -p 8080  192.168.0.120 
traceroute to 192.168.0.120 (192.168.0.120), 30 hops max, 60 byte packets
 1  192.168.4.1  6.110 ms
 2  192.168.1.1  5.858 ms
 3  192.168.1.254  7.588 ms
 4  192.168.0.120  8.910 ms

DEST-IPでPORTを閉じている場合、応答なし!Xのエラー応答。

$ sudo traceroute -n -q 1 -T -p 443  192.168.0.120 
traceroute to 192.168.0.120 (192.168.0.120), 30 hops max, 60 byte packets
 1  192.168.4.1  1.608 ms
 2  192.168.1.1  1.747 ms
 3  192.168.1.254  2.500 ms
 4  192.168.0.120  3.836 ms !X

UDP

UDP+PORT指定の場合、0バイトのデータを送信するだけ。

linux : traceroute -U -p PORT DEST-IP 
osx   : traceroute -P udp -p PORT DEST-IP

DEST-IPでPORTをLISTENしている場合、データは受けていて応答がないので、***となる

$ sudo traceroute -n -q 1 -U -p 162 192.168.0.120 
traceroute to 192.168.0.120 (192.168.0.120), 30 hops max, 60 byte packets
 1  192.168.4.1  1.335 ms
 2  192.168.1.1  1.844 ms
 3  192.168.1.254  2.415 ms
 4  *

DEST-IPでPORTを閉じている場合、!Xが帰ってくる。

$ sudo traceroute -n -q 1 -U -p 999  192.168.0.120 
traceroute to 192.168.0.120 (192.168.0.120), 30 hops max, 60 byte packets
 1  192.168.4.1  2.914 ms
 2  192.168.1.1  1.565 ms
 3  192.168.1.254  4.123 ms
 4  192.168.0.120  3.841 ms !X

tracerouteのオプション

OPTIONS
  -n : no DNS hostname resolve
  -q : nqueries per hop 

よくあるPORT番号

IP-protocol No
 1:ICMP 4:IP in IP 6:TCP 17:UDP
 88:EIGRP 89:OSPF
   osx:   traceroute -P TCP|UDP|ICMP
   linux: traceroute -P nn

UDP-port
  53:domain 69:tftp 123:ntp 
  137:netbios-ns 138:netbios-dgm 139:netbios-ssn
  161:snmp 162:snmptrap

TCP-port
  20:ftp-data 21:ftp 22:ssh 23:telnet 25:smtp
  53:domain 80:http 123:ntp 
  3389:RDP 445:SMB 993:IMAPS
18
19
0

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
18
19