Linux 網絡管理(4) - 網絡測試命令:ping、telnet、traceroute、tcpdump

Linux 網絡管理 - 網絡測試命令

1、ping

ping命令用來測試主機之間網絡的連通性。執行ping指令會使用ICMP傳輸協議,發出要求迴應的信息,若遠端主機的網絡功能沒有問題,就會迴應該信息,於是得知該主機運做正常。

1. 語法

ping [選項] [域名或IP地址]

2. 經常使用選項

-c <完成次數>:設置完成要求迴應的次數;
-i <間隔秒數>:指定收發信息的間隔時間;
-s <數據包大小>:設置ICMP數據部分的大小;

3. 應用

[vagrant@10 tmp]$ ping -c 3 -i 2 -s 100 www.baidu.com
PING www.baidu.com (61.135.169.121) 100(128) bytes of data.
108 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=56 time=11.6 ms
108 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=56 time=7.36 ms
108 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=3 ttl=56 time=6.47 ms

--- www.baidu.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 6.471/8.487/11.632/2.255 ms
\ 解釋
www.baidu.com (61.135.169.121) 目標主機的主機名和IP地址
100(128) bytes ICMP數據部分的大小100字節
加上8字節的ICMP頭,則ICMP包大小爲108字節
再加上20字節的IP頭,IP包大小爲128字節
108 bytes ICMP數據包大小
61.135.169.121 目標主機的IP地址
icmp_seq ICMP包序號
ttl 剩餘生存時間
生存時間,是指數據包被路由器丟棄以前容許經過的網段數量。
TTL 是由發送主機設置的,以防止數據包不斷在 IP 互聯網絡上永不終止地循環。轉發 IP 數據包時,要求路由器至少將 TTL 減少 1。
time 響應時間,這個時間越小,說明你鏈接這個地址速度越快
3 packets transmitted 發送數據包的數量
3 received 接收到的數據包的數量
0% packet loss 數據包的丟失率
time 4006ms 整個過程消耗的總時間
rtt min/avg/max/mdev 最小響應時間/平均響應時間/最大響應時間/響應時間的平均差

2、telnet

telnet可用於登陸遠程主機,對遠程主機進行管理。telnet由於採用明文傳送報文,安全性很差,不少Linux服務器都不開放telnet服務,而改用更安全的ssh方式了。
這裏咱們主要介紹使用 telnet 探測遠程端口是否開放。

1. 語法

telnet [域名或IP地址] [端口號]

2. 應用

  • 探測 man.linuxde.net 的 80端口、22端口、11211端口是否開放
[root@10 vagrant]# telnet man.linuxde.net 80
Trying 192.250.198.125...
Connected to man.linuxde.net.
Escape character is '^]'.

Connection closed by foreign host.
[root@10 vagrant]# telnet man.linuxde.net 22
Trying 192.250.198.125...
Connected to man.linuxde.net.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3

Protocol mismatch.
Connection closed by foreign host.
[root@10 vagrant]# telnet man.linuxde.net 11211
Trying 192.250.198.125...
telnet: connect to address 192.250.198.125: Connection refused

可見,man.linuxde.net 開放了80端口、22端口,沒有開放11211端口。linux

3、traceroute

路由跟蹤命令。用於追蹤數據包在網絡上的傳輸時的所有路徑,它默認發送的數據包大小是40字節。安全

經過traceroute咱們能夠知道信息從你的計算機到互聯網另外一端的主機是走的什麼路徑。固然每次數據包由某一一樣的出發點(source)到達某一一樣的目的地(destination)走的路徑可能會不同,但基本上來講大部分時候所走的路由是相同的。服務器

traceroute 和 ping 命令同樣,都是用 ICMP 協議。網絡

部分節點可能會出現不通的狀況,此時會出現 * * *ssh

1. 語法

traceroute [選項] [域名或IP]

2. 經常使用選項

-n:直接使用IP地址而非主機名稱,速度更快

3. 應用

[root@10 vagrant]# traceroute www.google.com
traceroute to www.google.com (216.58.216.132), 30 hops max, 60 byte packets
 1  ec2-50-112-0-6.us-west-2.compute.amazonaws.com (50.112.0.6)  20.061 ms ec2-50-112-0-26.us-west-2.compute.amazonaws.com (50.112.0.26)  22.021 ms ec2-50-112-0-16.us-west-2.compute.amazonaws.com (50.112.0.16)  13.175 ms
 2  100.66.8.224 (100.66.8.224)  16.202 ms 100.66.8.28 (100.66.8.28)  21.064 ms 100.66.8.206 (100.66.8.206)  18.758 ms
 3  100.66.10.0 (100.66.10.0)  11.659 ms 100.66.10.76 (100.66.10.76)  19.651 ms 100.66.10.206 (100.66.10.206)  20.616 ms
 4  100.66.7.33 (100.66.7.33)  18.709 ms 100.66.6.35 (100.66.6.35)  14.456 ms 100.66.6.143 (100.66.6.143)  13.734 ms
 5  100.66.4.155 (100.66.4.155)  12.962 ms 100.66.4.101 (100.66.4.101)  16.822 ms 100.66.4.43 (100.66.4.43)  10.394 ms
 6  100.65.11.193 (100.65.11.193)  0.603 ms 100.65.8.193 (100.65.8.193)  0.315 ms 100.65.8.97 (100.65.8.97)  0.829 ms
 7  52.93.240.26 (52.93.240.26)  0.605 ms 52.93.240.42 (52.93.240.42)  0.606 ms  0.555 ms
 8  52.93.12.98 (52.93.12.98)  22.474 ms 52.93.12.134 (52.93.12.134)  25.651 ms  24.525 ms
 9  52.93.12.125 (52.93.12.125)  0.670 ms 52.93.12.235 (52.93.12.235)  0.720 ms 52.93.12.161 (52.93.12.161)  0.620 ms
10  100.91.25.194 (100.91.25.194)  9.060 ms 100.91.25.84 (100.91.25.84)  8.406 ms 100.91.25.214 (100.91.25.214)  8.496 ms
11  54.239.45.126 (54.239.45.126)  10.438 ms  8.839 ms 54.239.42.195 (54.239.42.195)  8.165 ms
12  54.239.42.220 (54.239.42.220)  7.394 ms 100.91.139.53 (100.91.139.53)  7.085 ms 100.91.139.51 (100.91.139.51)  7.078 ms
13  52.95.52.196 (52.95.52.196)  6.492 ms 100.91.139.83 (100.91.139.83)  7.490 ms 100.91.139.101 (100.91.139.101)  9.663 ms
14  52.95.52.13 (52.95.52.13)  6.416 ms 52.95.52.232 (52.95.52.232)  7.480 ms 52.95.52.157 (52.95.52.157)  7.202 ms
15  52.95.216.103 (52.95.216.103)  6.107 ms 52.95.52.47 (52.95.52.47)  8.358 ms  8.385 ms
16  108.170.245.97 (108.170.245.97)  8.150 ms  8.163 ms 52.95.216.101 (52.95.216.101)  8.017 ms
17  209.85.240.253 (209.85.240.253)  6.260 ms  6.228 ms 108.170.245.113 (108.170.245.113)  7.949 ms
18  sea15s01-in-f132.1e100.net (216.58.216.132)  6.928 ms 209.85.240.253 (209.85.240.253)  7.060 ms sea15s01-in-f4.1e100.net (216.58.216.132)  6.910 ms

4、tcpdump

tcpdump命令是一款sniffer工具,它能夠打印全部通過網絡接口的數據包的頭信息,也能夠使用-w選項將數據包保存到文件中,方便之後分析。

1. 語法

dig [選項]

2. 經常使用選項

-i<網絡界面>:使用指定的網絡截面送出數據包
-nn:將數據包中的域名和服務名轉換爲IP和端口號
-X:用十六進制和ASCII字碼顯示數據包內容
port <端口號>:指定監聽的端口tcp

3. 應用

  • 監聽網卡 eth1 的 11211 端口傳送的數據
[root@10 tmp]# tcpdump -i eth1 -nnX port 11211
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
08:24:46.381529 IP 192.168.33.1.11623 > 192.168.33.88.11211: Flags [P.], seq 823138355:823138356, ack 3518529694, win 2052, length 1
        0x0000:  4500 0029 2b15 4000 4006 4c10 c0a8 2101  E..)+.@.@.L...!.
        0x0010:  c0a8 2158 2d67 2bcb 3110 1833 d1b8 809e  ..!X-g+.1..3....
        0x0020:  5018 0804 be50 0000 3100 0000 0000       P....P..1.....
08:24:46.381589 IP 192.168.33.88.11211 > 192.168.33.1.11623: Flags [.], ack 1, win 229, length 0
        0x0000:  4500 0028 d629 4000 4006 a0fc c0a8 2158  E..(.)@.@.....!X
        0x0010:  c0a8 2101 2bcb 2d67 d1b8 809e 3110 1834  ..!.+.-g....1..4
        0x0020:  5010 00e5 c3c4 0000                      P.......
08:24:47.021627 IP 192.168.33.1.11623 > 192.168.33.88.11211: Flags [P.], seq 1:2, ack 1, win 2052, length 1
        0x0000:  4500 0029 2b16 4000 4006 4c0f c0a8 2101  E..)+.@.@.L...!.
        0x0010:  c0a8 2158 2d67 2bcb 3110 1834 d1b8 809e  ..!X-g+.1..4....
        0x0020:  5018 0804 bd4f 0000 3200 0000 0000       P....O..2.....
08:24:47.021690 IP 192.168.33.88.11211 > 192.168.33.1.11623: Flags [.], ack 2, win 229, length 0
        0x0000:  4500 0028 d62a 4000 4006 a0fb c0a8 2158  E..(.*@.@.....!X
        0x0010:  c0a8 2101 2bcb 2d67 d1b8 809e 3110 1835  ..!.+.-g....1..5
        0x0020:  5010 00e5 c3c4 0000                      P.......
08:24:48.420408 IP 192.168.33.1.11623 > 192.168.33.88.11211: Flags [P.], seq 2:3, ack 1, win 2052, length 1
        0x0000:  4500 0029 2b17 4000 4006 4c0e c0a8 2101  E..)+.@.@.L...!.
        0x0010:  c0a8 2158 2d67 2bcb 3110 1835 d1b8 809e  ..!X-g+.1..5....
        0x0020:  5018 0804 bc4e 0000 3300 0000 0000       P....N..3.....
08:24:48.420468 IP 192.168.33.88.11211 > 192.168.33.1.11623: Flags [.], ack 3, win 229, length 0
        0x0000:  4500 0028 d62b 4000 4006 a0fa c0a8 2158  E..(.+@.@.....!X
        0x0010:  c0a8 2101 2bcb 2d67 d1b8 809e 3110 1836  ..!.+.-g....1..6
        0x0020:  5010 00e5 c3c4 0000                      P.......
08:24:50.196671 IP 192.168.33.1.11623 > 192.168.33.88.11211: Flags [P.], seq 3:4, ack 1, win 2052, length 1
        0x0000:  4500 0029 2b18 4000 4006 4c0d c0a8 2101  E..)+.@.@.L...!.
        0x0010:  c0a8 2158 2d67 2bcb 3110 1836 d1b8 809e  ..!X-g+.1..6....
        0x0020:  5018 0804 8e4d 0000 6100 0000 0000       P....M..a.....
08:24:50.196752 IP 192.168.33.88.11211 > 192.168.33.1.11623: Flags [.], ack 4, win 229, length 0
        0x0000:  4500 0028 d62c 4000 4006 a0f9 c0a8 2158  E..(.,@.@.....!X
        0x0010:  c0a8 2101 2bcb 2d67 d1b8 809e 3110 1837  ..!.+.-g....1..7
        0x0020:  5010 00e5 c3c4 0000                      P.......
08:24:52.212906 IP 192.168.33.1.11623 > 192.168.33.88.11211: Flags [P.], seq 4:5, ack 1, win 2052, length 1
        0x0000:  4500 0029 2b19 4000 4006 4c0c c0a8 2101  E..)+.@.@.L...!.
        0x0010:  c0a8 2158 2d67 2bcb 3110 1837 d1b8 809e  ..!X-g+.1..7....
        0x0020:  5018 0804 8d4c 0000 6200 0000 0000       P....L..b.....
08:24:52.212977 IP 192.168.33.88.11211 > 192.168.33.1.11623: Flags [.], ack 5, win 229, length 0
        0x0000:  4500 0028 d62d 4000 4006 a0f8 c0a8 2158  E..(.-@.@.....!X
        0x0010:  c0a8 2101 2bcb 2d67 d1b8 809e 3110 1838  ..!.+.-g....1..8
        0x0020:  5010 00e5 c3c4 0000                      P.......
08:24:52.356770 IP 192.168.33.1.11623 > 192.168.33.88.11211: Flags [P.], seq 5:6, ack 1, win 2052, length 1
        0x0000:  4500 0029 2b1a 4000 4006 4c0b c0a8 2101  E..)+.@.@.L...!.
        0x0010:  c0a8 2158 2d67 2bcb 3110 1838 d1b8 809e  ..!X-g+.1..8....
        0x0020:  5018 0804 8c4b 0000 6300 0000 0000       P....K..c.....
08:24:52.356827 IP 192.168.33.88.11211 > 192.168.33.1.11623: Flags [.], ack 6, win 229, length 0
        0x0000:  4500 0028 d62e 4000 4006 a0f7 c0a8 2158  E..(..@.@.....!X
        0x0010:  c0a8 2101 2bcb 2d67 d1b8 809e 3110 1839  ..!.+.-g....1..9
        0x0020:  5010 00e5 c3c4 0000                      P.......
相關文章
相關標籤/搜索