네트워크 연결이 잘 되고 있는지를 확인하기 위해 사용하는 command다. RTT랑 packet loss 유무도 확인이 가능하다.
ICMP Echo request를 기반으로 작동을 하는데, 이를 목적지에 보내고 답변을 기다린다. 목적지의 경우 이것을 받았으면 ICMP Echo reply를 보낸다.
설치를 필요로 하며, Ubuntu는 다음 command를 통해 설치가 가능하다.
$ sudo apt install iputils-ping
ping
과 목적지를 명시하며, option을 넣을 수도 있다.$ ping google.com
$ ping google.com
PING google.com (142.250.76.142) 56(84) bytes of data.
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=1 ttl=53 time=32.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=2 ttl=53 time=31.6 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=3 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=4 ttl=53 time=31.6 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=5 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=6 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=7 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=8 ttl=53 time=31.6 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=9 ttl=53 time=31.6 ms
^C
--- google.com ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8010ms
rtt min/avg/max/mdev = 31.491/31.652/32.464/0.288 ms
각 줄마다 표기되는 정보는
kis07s06-in-f14.1e100.net (142.250.76.142)
ping
은 interrupt를 받을 때까지 계속해서 packet을 보내며, 기본으로 설정된 보내는 주기는 1초다.
interrupt를 받으면 위처럼 통계를 보여주는데, 몇개를 보냈는지, 몇개를 받는데 성공했는지, 전체 packet 대비 loss가 생긴 비율은 얼마인지, 첫 packet 전송에서 마지막 packet 수신 사이에 걸린 시간(time)과 RTT관련 통계가 나온다.
ping이 연걸 자체가 설정은 되어있는데 reply를 받지 못하는 경우에는 출력물이 아예 안나오며, statistic은 다음과 같이 나온다.
$ ping 1.2.3.4
PING 1.2.3.4 (1.2.3.4) 56(84) bytes of data.
^C
--- 1.2.3.4 ping statistics ---
21 packets transmitted, 0 received, 100% packet loss, time 20764ms
이는 여러 이유가 가능한데
ping이 한 packet의 response에 대해 기다리는 시간은 다음과 같다.
$ ping -c 1 google.com
PING google.com (142.250.207.110) 56(84) bytes of data.
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=1 ttl=53 time=31.5 ms
--- google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 31.467/31.467/31.467/0.000 ms
$ ping -I eth0 google.com
PING google.com (142.250.207.110) from 172.18.215.138 eth0: 56(84) bytes of data.
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=1 ttl=53 time=31.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=2 ttl=53 time=30.4 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=3 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=4 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=5 ttl=53 time=30.5 ms
^C
--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 30.447/30.695/31.525/0.416 ms
$ ping -4 google.com
PING google.com (142.250.207.110) 56(84) bytes of data.
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=1 ttl=53 time=30.7 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=2 ttl=53 time=30.4 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=3 ttl=53 time=30.5 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 30.355/30.524/30.697/0.139 ms
-6
의 경우 밑과 같이 나온다.$ ping -6 google.com
ping: connect: Network is unreachable
$ ping -s 10 google.com
PING google.com (142.250.207.110) 10(38) bytes of data.
18 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=1 ttl=53
18 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=2 ttl=53
18 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=3 ttl=53
18 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=4 ttl=53
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
$ ping -i 0.5 google.com
PING google.com (142.250.207.110) 56(84) bytes of data.
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=1 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=2 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=3 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=4 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=5 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=6 ttl=53 time=30.6 ms
^C
--- google.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 2504ms
rtt min/avg/max/mdev = 30.473/30.523/30.569/0.029 ms
$ ping -q google.com
PING google.com (142.250.207.110) 56(84) bytes of data.
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 30.475/31.329/32.183/0.854 ms
$ ping -i 0.5 -w 2 google.com
PING google.com (142.250.207.110) 56(84) bytes of data.
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=1 ttl=53 time=30.6 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=2 ttl=53 time=30.6 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=3 ttl=53 time=30.5 ms
64 bytes from kix06s11-in-f14.1e100.net (142.250.207.110): icmp_seq=4 ttl=53 time=30.5 ms
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 1502ms
rtt min/avg/max/mdev = 30.487/30.559/30.644/0.056 ms
PING request flooding을 수행한다. 이는 정확히는 다음을 말한다.
-f
사용이 가능하다..
이 print한다..
하나를 지운다.이것은 network가 해당 destination을 향해 packet을 보낼 때 dropping이 얼마나 이루어지는지 파악하는 것이 가능하다. 왜냐하면 drop된 만큼 .
이 남을 것이기 때문이다.
밑은 super-user이 아니어서 ping request flooding을 주기 없음으로 하는게 불가능한 경우
~$ ping -f google.com
PING google.com (142.250.76.142) 56(84) bytes of data.
ping: cannot flood; minimal interval allowed for user is 2ms
$ sudo ping -f google.com
[sudo] password for sycho:
PING google.com (142.250.76.142) 56(84) bytes of data.
..^C
--- google.com ping statistics ---
459 packets transmitted, 457 received, 0.43573% packet loss, time 7050ms
rtt min/avg/max/mdev = 31.259/31.389/31.793/0.061 ms, pipe 3, ipg/ewma 15.393/31.395 ms
timestamp를 더한다. 각 router에 도달할때마다 timestamp를 남기라는 것인데... 이 때 어떤 형식의 timestamp를 넣을지 정하는게 가능한데
tsonly
: timestamp만 나오게 한다.$ ping -T tsonly 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(124) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.016 ms
TS: 26376133 absolute
0
0
0
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.027 ms
TS: 26377172 absolute
0
0
0
^C
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1039ms
rtt min/avg/max/mdev = 0.016/0.021/0.027/0.005 ms
tsandaddr
: timestamp와 address가 함께 나오게 한다.$ ping -T tsandaddr 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(124) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.015 ms
TS: 127.0.0.1 26423751 absolute
127.0.0.1 0
127.0.0.1 0
127.0.0.1 0
^C
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.015/0.015/0.015/0.000 ms
tsprespec
: timestamp prespecified hops의 약자다. 위에 봤다시피 다른 mode의 timestamp는 도달한 모든 host들이 timestamp를 남기도록 설정을 하는데, 이 option은 지정된 host들만 timestamp를 남기도록 설정을 한다. 최대 4개의 host에 대해 지정이 가능하다.$ ping -T tsprespec 127.0.0.1 127.0.0.2 127.0.0.3
PING 127.0.0.3 (127.0.0.3) 56(124) bytes of data.
64 bytes from 127.0.0.3: icmp_seq=1 ttl=64 time=0.094 ms
TS: 127.0.0.1 26593915 absolute
127.0.0.2 0
64 bytes from 127.0.0.3: icmp_seq=2 ttl=64 time=0.027 ms
TS: 127.0.0.1 26594932 absolute
127.0.0.2 0
64 bytes from 127.0.0.3: icmp_seq=3 ttl=64 time=0.028 ms
TS: 127.0.0.1 26595972 absolute
127.0.0.2 0
64 bytes from 127.0.0.3: icmp_seq=4 ttl=64 time=0.027 ms
TS: 127.0.0.1 26597012 absolute
127.0.0.2 0
^C
--- 127.0.0.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3097ms
rtt min/avg/max/mdev = 0.027/0.044/0.094/0.028 ms
그러나 위와 같은 것을 요구하는 ICMP packet을 거부하는 router, host 및 방화벽들이 워낙 많아서 현실 외부 host에 시도하면 거의 작동하지 않을 것이라는 점 유의.
$ ping -W 2 google.com
PING google.com (142.250.76.142) 56(84) bytes of data.
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=1 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=2 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=3 ttl=53 time=31.7 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 31.497/31.576/31.690/0.082 ms
packet에 있는 data를 어떤 값으로 채워넣는데 사용한다. 넣을 값은 pattern 형태로 주어지는데, 최대 16의 길이로 해당 pattern을 지정하는게 가능하다. byte pattern 형태로 설정.
예를들어 밑의 경우 2byte단위로 ff
를 계속해서 채워넣는다.
$ ping -p ff google.com
PATTERN: 0xff
PING google.com (142.250.76.142) 56(84) bytes of data.
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=1 ttl=53 time=31.8 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=2 ttl=53 time=31.5 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=3 ttl=53 time=31.6 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=4 ttl=53 time=31.6 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 31.506/31.632/31.812/0.112 ms
abcd
를 계속해서 채워 넣는다.$ ping -p abcd google.com
PATTERN: 0xabcd
PING google.com (142.250.76.142) 56(84) bytes of data.
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=1 ttl=53 time=32.4 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=2 ttl=53 time=31.6 ms
64 bytes from kix07s06-in-f14.1e100.net (142.250.76.142): icmp_seq=3 ttl=53 time=31.6 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 31.596/31.871/32.375/0.356 ms
Path Maximum Transmission Unit (PMTU) Discovery라는 기능을 TCP가 가지고 있는데, TCP가 감당 가능한 MTU를 파악하는데 도움이 된다. -M
은 이것과 관련이 있는데, 3가지 option을 설정하는게 가능하다.
do
: 전송되는 packet의 fragmentation을 제한한다.
want
: 전송되는 packet에 대해 PMTU discovery를 수행, 해당 discovery 결과 packet size가 큰 경우 fragment를 local하게 수행하도록 허용한다.
don't
: 전송되는 packet의 DF flag를 없애서 그냥 fragmentation이 언제든 일어날 수 있도록 허용한다.
$ ping -t 7 google.com
PING google.com (142.250.207.110) 56(84) bytes of data.
From 211.230.12.5 (211.230.12.5) icmp_seq=1 Time to live exceeded
From 211.230.12.5 (211.230.12.5) icmp_seq=2 Time to live exceeded
From 211.230.12.5 (211.230.12.5) icmp_seq=3 Time to live exceeded
^CFrom 211.230.12.5 icmp_seq=4 Time to live exceeded
--- google.com ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3032ms