1 | Network Performance Definitions and Measurement Exercises |
---|
2 | ========================================================= |
---|
3 | |
---|
4 | Notes: |
---|
5 | ------ |
---|
6 | * Commands preceded with "$" imply that you should execute the command as |
---|
7 | a general user - not as root. |
---|
8 | * Commands preceded with "#" imply that you should be working as root. |
---|
9 | * Commands with more specific command lines (e.g. "GW-RTR>" or "mysql>") |
---|
10 | imply that you are executing commands on remote equipment, or within |
---|
11 | another program. |
---|
12 | * If a command line ends with "\" this indicates that the command continues |
---|
13 | on the next line and you should treat this as a single line. |
---|
14 | |
---|
15 | Exercises Part I |
---|
16 | ================ |
---|
17 | |
---|
18 | 0. Log in to your PC/VM or open a terminal window as the sysadm user. |
---|
19 | |
---|
20 | NOTE: During these exercises if you find that the apt-get command complains |
---|
21 | that some archives cannot be found, then you may need to update your |
---|
22 | apt package database. To do this type: |
---|
23 | |
---|
24 | $ sudo apt-get update |
---|
25 | |
---|
26 | |
---|
27 | Network Performance Metrics |
---|
28 | --------------------------- |
---|
29 | |
---|
30 | 1. ping |
---|
31 | ------- |
---|
32 | |
---|
33 | ping is a program that sends ICMP echo request packets to target hosts and |
---|
34 | waits for an ICMP response from the host. Depending on the operating system |
---|
35 | on which you are using ping you may see the minimum, maximum, and the mean |
---|
36 | round-trip times, and sometimes the standard deviation of the mean for the |
---|
37 | ICMP responses from the target host. For more details see: |
---|
38 | |
---|
39 | http://en.wikipedia.org/wiki/Ping |
---|
40 | |
---|
41 | Blocking ping is generally a bad idea. |
---|
42 | |
---|
43 | With all this in mind, try using ping in a few different ways: |
---|
44 | |
---|
45 | $ ping localhost |
---|
46 | |
---|
47 | Press ctrl-c to stop the process. Here is typical output from the above |
---|
48 | command: |
---|
49 | |
---|
50 | PING localhost (127.0.0.1) 56(84) bytes of data. |
---|
51 | 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.020 ms |
---|
52 | 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.006 ms |
---|
53 | 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.006 ms |
---|
54 | 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.006 ms |
---|
55 | 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.006 ms |
---|
56 | 64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.009 ms |
---|
57 | 64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.007 ms |
---|
58 | ^C |
---|
59 | --- localhost ping statistics --- |
---|
60 | 7 packets transmitted, 7 received, 0% packet loss, time 5994ms |
---|
61 | rtt min/avg/max/mdev = 0.006/0.008/0.020/0.005 ms |
---|
62 | |
---|
63 | Question: why did the first ICMP response take 20ms while the remaining |
---|
64 | responses were much quicker? This is a type of delay. What kind is it? |
---|
65 | |
---|
66 | |
---|
67 | 2. traceroute |
---|
68 | ------------- |
---|
69 | |
---|
70 | You may have used traceroute before, but have you really looked at what it is |
---|
71 | doing? If not, read this: |
---|
72 | |
---|
73 | http://en.wikipedia.org/wiki/Traceroute |
---|
74 | |
---|
75 | You may need to install the traceroute command first. To do this do: |
---|
76 | |
---|
77 | $ sudo apt-get install traceroute |
---|
78 | |
---|
79 | Once installed try: |
---|
80 | |
---|
81 | $ traceroute nsrc.org |
---|
82 | |
---|
83 | Here's sample output from traceroute to nsrc.org (lines wrapped due to length): |
---|
84 | |
---|
85 | traceroute to nsrc.org (128.223.157.19), 64 hops max, 52 byte packets |
---|
86 | 1 gw.ws.nsrc.org (10.10.0.254) 1.490 ms 1.069 ms 1.055 ms |
---|
87 | 2 192.248.5.2 (192.248.5.2) 2.741 ms 2.450 ms 3.182 ms |
---|
88 | 3 192.248.1.126 (192.248.1.126) 2.473 ms 2.497 ms 2.618 ms |
---|
89 | 4 mb-t3-01-v4.bb.tein3.net (202.179.249.93) 26.324 ms 28.049 ms 27.403 ms |
---|
90 | 5 sg-so-06-v4.bb.tein3.net (202.179.249.81) 103.321 ms 91.072 ms 91.674 ms |
---|
91 | 6 jp-pop-sg-v4.bb.tein3.net (202.179.249.50) 168.948 ms 168.712 ms 168.903 ms |
---|
92 | 7 tpr5-ge0-0-0-4.jp.apan.net (203.181.248.250) 172.789 ms 170.367 ms 188.689 ms |
---|
93 | 8 losa-tokyo-tp2.transpac2.net (192.203.116.145) 579.586 ms 284.736 ms 284.202 ms |
---|
94 | 9 abilene-1-lo-jmb-702.lsanca.pacificwave.net (207.231.240.131) 303.736 ms |
---|
95 | 284.884 ms 530.854 ms |
---|
96 | 10 vl-101.xe-0-0-0.core0-gw.pdx.oregon-gigapop.net (198.32.165.65) 328.082 ms |
---|
97 | 305.800 ms 533.644 ms |
---|
98 | 11 vl-105.uonet9-gw.eug.oregon-gigapop.net (198.32.165.92) 336.680 ms 617.267 ms |
---|
99 | 495.685 ms |
---|
100 | 12 vl-3.uonet2-gw.uoregon.edu (128.223.3.2) 310.552 ms 421.638 ms 612.399 ms |
---|
101 | 13 nsrc.org (128.223.157.19) 309.548 ms 612.151 ms 611.505 ms |
---|
102 | |
---|
103 | Do you understand what each item means? If not, see the Wikipedia page and type: |
---|
104 | |
---|
105 | $ man traceroute |
---|
106 | |
---|
107 | for more information. What does it mean if you see lines like this? |
---|
108 | |
---|
109 | 15 * * * |
---|
110 | 16 * * * |
---|
111 | 17 * * * |
---|
112 | |
---|
113 | When you see this it means that the remote device does not reply to icmp echo requests, or |
---|
114 | it uses a private network address (RFC 1918). |
---|
115 | |
---|
116 | As you can see traceroute can be used to determine where problems are taking place |
---|
117 | between two endpoints on a network. |
---|
118 | |
---|
119 | Try running traceroute again to the same host (nsrc.org). It will likely take considerably |
---|
120 | less time. |
---|
121 | |
---|
122 | |
---|
123 | 3. mtr |
---|
124 | ------ |
---|
125 | |
---|
126 | The mtr tool combines ping and traceroute in to a single, dynamically updating display. |
---|
127 | Before using mtr you may need to first install it: |
---|
128 | |
---|
129 | $ sudo apt-get install mtr-tiny |
---|
130 | |
---|
131 | Now give it a try: |
---|
132 | |
---|
133 | $ mtr nsrc.org |
---|
134 | |
---|
135 | The output of the command looks different on different Linux and UNIX flavors, but in |
---|
136 | general you'll see a summary of packet loss to each node on the path to the remote |
---|
137 | target host, number of ICMP echo request packets sent, last rtt (round-trip-time) to |
---|
138 | the host, average, best and worst rtt as well as the standard deviation of rtt's. |
---|
139 | |
---|
140 | By showing the percent loss of packets in this format it makes it much easier to see |
---|
141 | where you may be having network issues. |
---|
142 | |
---|
143 | |
---|
144 | 4. ping with variable packet size |
---|
145 | --------------------------------- |
---|
146 | |
---|
147 | By default, ping sends out IP datagrams of size 84 bytes: |
---|
148 | |
---|
149 | * 20 bytes IP header |
---|
150 | * 8 bytes ICMP header |
---|
151 | * 56 bytes data padding |
---|
152 | |
---|
153 | However, you can send out larger packets using the -s option. Using |
---|
154 | `-s 1472` will give you a 1500-byte IP datagram, which is the maximum for |
---|
155 | most networks before fragmentation takes place (MTU = Maximum Transmission |
---|
156 | Unit) |
---|
157 | |
---|
158 | This simple mechanism can be used to debug all sorts of problems, and even |
---|
159 | distinguish between transmission delay and propagation delay. |
---|
160 | |
---|
161 | Let's find a host that is a few hops away from us. First do: |
---|
162 | |
---|
163 | $ traceroute nsrc.org |
---|
164 | |
---|
165 | Now look for a machine that is more than two hops away and make a note of |
---|
166 | the IP address. Why? Because one hop is your virtual router and this exercise |
---|
167 | will not work reliably using virtual hardware. The second hop is the gateway |
---|
168 | router on our private network. It is too close and the difference in ping |
---|
169 | times are likely to be too small to be useful. We'll refer to the machine |
---|
170 | you choose to ping to as PING_MACHINE. |
---|
171 | |
---|
172 | Send 20 standard pings to that address: |
---|
173 | |
---|
174 | $ ping -c20 PING_MACHINE |
---|
175 | |
---|
176 | Make a note of the *average* round-trip time seen (t1). |
---|
177 | |
---|
178 | Now send 20 maximum-sized pings: |
---|
179 | |
---|
180 | $ ping -c20 -s1472 PING_MACHINE |
---|
181 | |
---|
182 | Again, make a note of the *average* round-trip time seen (t2). |
---|
183 | |
---|
184 | The propagation delay is the same in both cases, so the larger round-trip |
---|
185 | time must be due to transmission delay. |
---|
186 | |
---|
187 | You can now estimate the transmission delay and hence the bandwidth of |
---|
188 | the link between two points |
---|
189 | |
---|
190 | increase in transmission time = t2 - t1 |
---|
191 | increase in bits sent = (1500-84) * 8 * 2 = 22656 |
---|
192 | |
---|
193 | (multiply by 2 because the round-trip time involves sending the packet twice) |
---|
194 | |
---|
195 | Divide the bits by time to get an estimate of bits per second. Remember to |
---|
196 | convert milliseconds to seconds first. |
---|
197 | |
---|
198 | Example: |
---|
199 | |
---|
200 | t2 = 1.71 |
---|
201 | t1 = 1.14 |
---|
202 | |
---|
203 | t2-t1 = 0.57 |
---|
204 | |
---|
205 | 0.57 ms = 0.00057 sec |
---|
206 | |
---|
207 | 22656 bits / 0.00057 sec = 39747368.42 bps |
---|
208 | |
---|
209 | You could then convert this to Kbps, Mbps, etc. |
---|
210 | |
---|
211 | By doing this for subsequent hops, it's possible to estimate the bandwidth |
---|
212 | on each hop, even those remote from you. There is a tool available which |
---|
213 | does this automatically - it's called "pathchar" but you have to build it |
---|
214 | from source. A few OS-specific binaries are available at: |
---|
215 | |
---|
216 | ftp://ftp.ee.lbl.gov/pathchar/ |
---|
217 | |
---|
218 | The web page, including documentation is available here: |
---|
219 | |
---|
220 | http://www.caida.org/tools/utilities/others/pathchar/ |
---|
221 | |
---|
222 | |
---|
223 | --------------------------------------------------------------------------- |
---|
224 | |
---|
225 | |
---|
226 | Exercises Part II |
---|
227 | ================= |
---|
228 | |
---|
229 | Network Analysis |
---|
230 | ---------------- |
---|
231 | |
---|
232 | 1. lsof and netstat |
---|
233 | ------------------- |
---|
234 | |
---|
235 | See what services are running on your machine. You can use the |
---|
236 | presentation as a reference. |
---|
237 | |
---|
238 | Or, utilize "man lsof", "man netstat", "lsof -h" and "netstat -h" to see |
---|
239 | the available options (there are a lot!). Remember to use |
---|
240 | sudo when using lsof and netstat to give yourself necessary permissions |
---|
241 | to view everything. |
---|
242 | |
---|
243 | You may need to install lsof. To do this type: |
---|
244 | |
---|
245 | $ sudo apt-get install lsof |
---|
246 | |
---|
247 | * Using lsof, what IPv4 services are listening on your machine? |
---|
248 | * Using netstat, what IPv4 and IPv6 services are listening on your machine? |
---|
249 | |
---|
250 | When you run lsof and netstat you should run them as root: |
---|
251 | |
---|
252 | $ sudo lsof |
---|
253 | $ sudo netstat |
---|
254 | |
---|
255 | Remember - you will need to specify options to answer what IPv4 and IPv6 services |
---|
256 | are running on your machine. |
---|
257 | |
---|
258 | |
---|
259 | 2. tcpdump and tshark |
---|
260 | --------------------- |
---|
261 | |
---|
262 | First we need to install both these programs: |
---|
263 | |
---|
264 | $ sudo apt-get install tcpdump tshark |
---|
265 | |
---|
266 | Use tcpdump like this: |
---|
267 | |
---|
268 | $ sudo tcpdump -i lo -A -s1500 -w /tmp/tcpdump.log |
---|
269 | |
---|
270 | Now, generate some traffic on your lo interface in another terminal. That is |
---|
271 | open another ssh session to your pc/vm. |
---|
272 | |
---|
273 | For example: |
---|
274 | |
---|
275 | $ ping localhost |
---|
276 | $ ssh localhost |
---|
277 | |
---|
278 | etc. Afterwords press CTRL-C to terminate the tcpdump session. |
---|
279 | |
---|
280 | Note: ssh generates much more "interesting" output. Now let's read the |
---|
281 | output from tcpdump using tshark: |
---|
282 | |
---|
283 | $ sudo tshark -r /tmp/tcpdump.log | less |
---|
284 | |
---|
285 | What do you see? Can you follow the SSH session you initiated earlier? |
---|
286 | |
---|
287 | Next we'll use ftp. First we need to install an ftp client: |
---|
288 | |
---|
289 | $ sudo apt-get install ftp |
---|
290 | |
---|
291 | Now try something like this: |
---|
292 | |
---|
293 | $ sudo rm /tmp/tcpdump.log |
---|
294 | $ sudo tcpdump -i eth0 -A -s1500 -w /tmp/tcpdump.log |
---|
295 | |
---|
296 | In another terminal do: |
---|
297 | |
---|
298 | $ ftp limestone.uoregon.edu |
---|
299 | |
---|
300 | Connected to limestone.uoregon.edu. |
---|
301 | 220 FTP Server ready. |
---|
302 | Name (limestone.uoregon.edu:sysadmin): anonymous |
---|
303 | Password: <anything you want> |
---|
304 | ftp> exit |
---|
305 | |
---|
306 | End the tcpdump session in the other terminal (CTRL-C). Now view the |
---|
307 | contents of the log file: |
---|
308 | |
---|
309 | $ sudo tshark -r /tmp/tcpdump.log | less |
---|
310 | |
---|
311 | Can you see your password? If you have a lot of traffic on your network, then |
---|
312 | the tcpdump.log file may be fairly large. You can search for your FTP session |
---|
313 | by typing: |
---|
314 | |
---|
315 | "/FTP" |
---|
316 | |
---|
317 | in the output screen. Since you piped your shark command output to the "less" |
---|
318 | command using the "/" to search for strings works. Now press the "n" key for |
---|
319 | "n"ext to follow the FTP session. You should see a line with the string: |
---|
320 | |
---|
321 | "FTP Request: PASS PasswordYouTypedIn" |
---|
322 | |
---|
323 | Sniffing unencrypted passwords on wireless lans is very easy with a tool like |
---|
324 | this. |
---|
325 | |
---|
326 | Rememer to clean up after yourself: |
---|
327 | |
---|
328 | $ rm /tmp/tcpdump.log |
---|
329 | |
---|
330 | |
---|
331 | 3. tcpdump part II |
---|
332 | ------------------- |
---|
333 | |
---|
334 | You can use tcpdump as a forensic tool in real-time as well. To completely cover tcpdump would |
---|
335 | take several hours of class time, but let's get started with another practical example. |
---|
336 | |
---|
337 | Let's watch a dhcp request from your PC and the responses that it receives. |
---|
338 | |
---|
339 | First connect to your PC image and become root: |
---|
340 | |
---|
341 | $ sudo bash |
---|
342 | |
---|
343 | Next we are going to use a utility called screen: |
---|
344 | |
---|
345 | # apt-get install screen |
---|
346 | |
---|
347 | Now run screen: |
---|
348 | |
---|
349 | # screen |
---|
350 | |
---|
351 | At this point you can have multiple terminal sessions open in a single ssh window. Let's start |
---|
352 | the tcpdump process listening for dhcp requests: |
---|
353 | |
---|
354 | # tcpdump -s0 -ni eth0 port 67 or port 68 |
---|
355 | |
---|
356 | Now use screen to open another "screen" in your ssh terminal window. |
---|
357 | |
---|
358 | Press ctrl-a c |
---|
359 | |
---|
360 | To figure out what "-s0", "-n" and "-i" are doing you can read the tcpdump man page: |
---|
361 | |
---|
362 | # man tcpdump |
---|
363 | |
---|
364 | Search for "-s" by typing a "/" and then "-s" and then press ENTER. Press "n" to see the next |
---|
365 | occurrence of the string "-s". |
---|
366 | |
---|
367 | Now make a dhcp request for a new address for eth0 on your machine: |
---|
368 | |
---|
369 | # dhcpclient |
---|
370 | |
---|
371 | Return to the previous screen to see what tcpdump displays: |
---|
372 | |
---|
373 | Press "ctrl-a p" ("p" for previous, "n" for next" to cycle through screens) |
---|
374 | |
---|
375 | You should see some output like this: |
---|
376 | |
---|
377 | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode |
---|
378 | listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes |
---|
379 | 18:03:05.003190 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 52:54:4a:5e:68:77, length 300 |
---|
380 | 18:03:05.004349 IP 10.10.0.254.67 > 10.10.0.250.68: BOOTP/DHCP, Reply, length 300 |
---|
381 | |
---|
382 | To stop the tcpdump session type "ctrl-c" |
---|
383 | |
---|
384 | Do you know what this means? Why did we specify to listen on ports 67 and 68? If you look in the |
---|
385 | file /etc/services you will find the following defintions for ports 67 and 68 |
---|
386 | |
---|
387 | bootps 67/udp # Bootstrap Protocol Server |
---|
388 | bootps 67/tcp # Bootstrap Protocol Server |
---|
389 | bootpc 68/udp # Bootstrap Protocol Client |
---|
390 | bootpc 68/tcp # Bootstrap Protocol Client |
---|
391 | |
---|
392 | You can return the screen where you ran dhcpclient and exit from the screen if you wish: |
---|
393 | |
---|
394 | ctrl-a-n |
---|
395 | |
---|
396 | Then type: |
---|
397 | |
---|
398 | # exit |
---|
399 | |
---|
400 | If you are interested in the screen utility and how it works see: |
---|
401 | |
---|
402 | http://www.howtoforge.com/linux_screen |
---|
403 | |
---|
404 | for more information or ask your instructor. |
---|
405 | |
---|
406 | |
---|
407 | 4. Using iperf |
---|
408 | -------------- |
---|
409 | |
---|
410 | First we need to install iperf: |
---|
411 | |
---|
412 | $ sudo apt-get install iperf |
---|
413 | |
---|
414 | Use "man iperf" or "iperf -h" for help. |
---|
415 | |
---|
416 | Ask your neighbor to run: |
---|
417 | |
---|
418 | $ iperf -s |
---|
419 | |
---|
420 | Connect to your neighbor's machine using: |
---|
421 | |
---|
422 | $ iperf -c ipNeighbor |
---|
423 | |
---|
424 | If you don't know the IP address of your neighbor's machine ask them to |
---|
425 | do: |
---|
426 | |
---|
427 | $ ifconfig eth0 |
---|
428 | |
---|
429 | and tell you what IP address their machine is using. |
---|
430 | |
---|
431 | How much throughput is there between your machines? You can repeat this |
---|
432 | exercise with any remote machine where iperf is installed and you have |
---|
433 | an account. This is a quick way to see what bandwidth looks like between |
---|
434 | two points. |
---|
435 | |
---|
436 | To stop the iperf server where you ran "iperf -s" press CTRL-c. |
---|
437 | |
---|
438 | If you have time continue playing with iperf options. If you have a |
---|
439 | remote PC running UNIX or Linux you might want to try installing iperf |
---|
440 | and testing your connection from the workshop lab to your remote |
---|
441 | machine. |
---|
442 | |
---|
443 | Some more things to try... |
---|
444 | |
---|
445 | * Test TCP using various window sizes (-2). |
---|
446 | |
---|
447 | * Verify TCP MSS (-m). How does this affect throughput? What is |
---|
448 | Path MTU discovery? |
---|
449 | |
---|
450 | * Test with two parallel threads (-P) and compare the totals. Is |
---|
451 | there any difference? Why? |
---|
452 | |
---|
453 | * Test with different packet sizes and the TCP_NODELAY (-N) option. |
---|