iT邦幫忙

8

Linux連載 3

今天講一個很基本的東西ping
相信大家對ping應該很熟悉,雖然很基本,但是也是有些地方可以玩點花樣的.

這是最基本的, -c num 代表送幾次封包,若未指定,就會一直發送,
跟Windows 上的ping 行為不一樣.
$ ping -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.499 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=0.554 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=0.526 ms

--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.499/0.526/0.554/0.029 ms

加一個 -a , 用來發出聲音,比較有感覺.
$ ping -a -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.319 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=0.346 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=0.555 ms

--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.319/0.406/0.555/0.108 ms

-s 設定封包大小,最終發送的還會加上8,是ICMP檔頭.
一般未指定時,是 56, 加上檔頭,就64. 看上面例子就知道了.
用比較大的封包,可以讓負擔加重,有時候比較能夠看出網路情況.

$ ping -s 3000 -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 3000(3028) bytes of data.
3008 bytes from 192.168.1.1: icmp_seq=1 ttl=63 time=1.44 ms
3008 bytes from 192.168.1.1: icmp_seq=2 ttl=63 time=7.00 ms
3008 bytes from 192.168.1.1: icmp_seq=3 ttl=63 time=1.40 ms

--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 1.400/3.285/7.009/2.633 ms

試試看對www.google.com.tw 用比較大的封包.

$ ping -s 3000 -c 3 www.google.com.tw
PING www.google.com.tw (173.194.72.94) 3000(3028) bytes of data.

--- www.google.com.tw ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 11999ms

有防火牆,遇到這種比較大的封包,就不回應.

還是用正常的方式吧.
$ ping -c 3 www.google.com.tw
PING www.google.com.tw (74.125.31.94) 56(84) bytes of data.
64 bytes from tb-in-f94.1e100.net (74.125.31.94): icmp_seq=1 ttl=49 time=22.4 ms
64 bytes from tb-in-f94.1e100.net (74.125.31.94): icmp_seq=2 ttl=49 time=22.3 ms
64 bytes from tb-in-f94.1e100.net (74.125.31.94): icmp_seq=3 ttl=49 time=22.4 ms

--- www.google.com.tw ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2025ms
rtt min/avg/max/mdev = 22.310/22.416/22.482/0.188 ms

用正常的方式,www.google.com.tw 還是會回應,讓我們可以用來
觀察是否還運作.

我要留言

立即登入留言