xkonekt
Language: EN
  • English
  • Türkçe
  • Español, Coming soon
  • Português, Coming soon
  • Deutsch, Coming soon
  • Français, Coming soon

TCP and UDP · Introduction · Module 2

Opening and closing a TCP connection

Show topologyHide topology
R1routerH1host10.0.1.0/24Et0/0eth0.1.10Et0/0 = Ethernet0/0.1 = the last number of the address
Topology · One cable joins the router R1 and the host H1, on 10.0.1.0/24.

The router R1 at the left end and the host H1 at the right end, joined by one cable. At R1’s end, Et0/0 above the cable and .1 under it: R1’s interface Ethernet0/0 with address 10.0.1.1. At H1’s end, eth0 above and .10 under it: H1’s interface eth0 with address 10.0.1.10. Under the cable, mid-way, its network: 10.0.1.0/24. A legend explains the short forms.

What a handshake is

Agree before sending

telnet prints Open before any data moves. What do R1 and H1 settle first?

They settle the number each end starts counting its data from.

Why count at all? TCP numbers the data each end sends, so the other end can tell what has arrived and in what order. The number TCP gives that data is its sequence number. Each end counts its own data, from a starting number it picks itself (Figure 2.1).

So each end must tell the other its starting number and hear that it arrived. Three segments do this, and together they are the three-way handshake, the segments that open a TCP connection, in which each end gives its starting number, and each end confirms the other’s. When telnet prints Open, R1 has received H1’s answer and the connection is open (ESTAB).

R1H1R1’s datacounted from R1’s numberH1’s datacounted from H1’s number
Figure 2.1 · Each end numbers the data it sends, from a starting number of its own; the handshake tells each end the other’s number.

The router R1 stands on the left and the host H1 on the right, each with a line running down under it. An arrow from R1 to H1 is labeled “R1’s data, counted from R1’s number”. Under it, an arrow from H1 back to R1 is labeled “H1’s data, counted from H1’s number”.

Would a request and one answer do? The answer would tell the client that a program waits, but nothing would confirm the server’s starting number, so a third segment is needed.

The two starting numbers are separate. Each end picks its own, because it numbers only the data it sends, so there is no shared number for both ends to count from.

Key idea

Each end counts its own data. The handshake tells each end the other’s starting number, and confirms it.

Why does opening a TCP connection take three segments and not two?

How it works

Three segments open, two FINs close

Three segments open it

R1 wants a connection to the program on H1 port 2001. What crosses the link before Open?

Each end has a number to give and a number to confirm, and TCP has a kind of segment for each job. A SYN is a segment that asks to open a connection and carries the sender’s starting sequence number. A SYN uses up one number of its sender’s count, so the first data after it is numbered the starting number plus one. An ACK confirms what arrived and names the next number its sender expects, so in the handshake, an ACK names the other end’s number plus one.

First, R1, the client, sends a SYN with its starting number. H1 answers with one segment that is both a SYN, with H1’s own starting number, and an ACK of R1’s number. Last, R1 sends an ACK of H1’s number. Each end has now given its number and heard it confirmed, so the connection is open.

To watch the three cross, turn on TCP debugging for port 2001 (debug ip tcp packet port 2001), and R1 logs each segment of that connection it sends or receives. After tcp0:, O marks a segment R1’s TCP sends, I one coming in, and R one that R1 sends again because no answer came in time. Then come R1’s state when the line was logged, the far end, R1’s own end (each address:port, the reverse order of show tcp brief) and the sender’s number after seq. Debugging can affect the router’s performance, so turn it off afterwards with undebug all.

Each end of a connection has its own port number. R1, the client, uses 41868, a number chosen for it, and H1’s end is 2001 (Figure 2.2).

Step 1 of 4

R1H1SYNSENTport 2001SYN · seq 4266631647

R1, the client, sends a SYN from its port 41868 to H1’s port 2001. It carries R1’s starting number, 4266631647. Its log line shows CLOSED, R1’s state when the line was logged; then R1 waits in SYNSENT.

H1’s answer will confirm R1’s number, 4266631647. Which number will its ACK name?

  • 4266631647, the same number R1 sent.: Sending back 4266631647 would only echo R1’s number. The ACK names the number H1 expects next.
  • H1’s own starting number, which R1 will then count from too.: H1 does send its own starting number in this answer, but in its SYN, for its own data. The ACK names R1’s number plus one, 4266631648.
  • 4266631648, one more than R1’s number. (Correct): An ACK names the next number its sender expects. In the handshake that is the other end’s number plus one: H1 has heard R1’s number 4266631647, so it names 4266631648.

Step 2 of 4

R1H1SYNSENTport 2001SYN · seq 4266631647SYN, ACK · seq 2290243570ack 4266631648

H1 answers with one segment that does two jobs. As a SYN, it carries H1’s own starting number, 2290243570. As an ACK, it names 4266631648, the next number it expects from R1.

Step 3 of 4

R1H1ESTABport 2001SYN · seq 4266631647SYN, ACK · seq 2290243570ack 4266631648ACK · ack 2290243571

R1 confirms H1’s number with an ACK that names 2290243571. Both numbers have now been given and confirmed, and R1’s state becomes ESTAB. Its log line reads seq 4266631648, because the SYN used up R1’s starting number.

Step 4 of 4

R1H1ESTABport 2001SYN · seq 4266631647SYN, ACK · seq 2290243570ack 4266631648ACK · ack 2290243571connection 41868 – 2001open: data can flow

The connection from 41868 to 2001 is open, and data can now flow both ways.

Step 1 of 4

R1 stands on the left and H1 on the right, each with a lane running down under it; time runs down. Under H1 a small note reads “port 2001”. Under R1 a state tag reads SYNSENT and later ESTAB. Arrows cross between the lanes, top down: “SYN, seq 4266631647” from R1 to H1; “SYN, ACK, seq 2290243570, ack 4266631648” from H1 to R1; “ACK, ack 2290243571” from R1 to H1. The last step adds a box under the lanes: “connection 41868 to 2001, open”.

Figure 2.2 · Three segments open the connection: R1’s SYN, H1’s SYN and ACK, R1’s ACK. Each ACK names the other end’s number plus one.Debug line at this stepNov 24 20:28:41.742: tcp0: O CLOSED 10.0.1.10:2001 10.0.1.1:41868 seq 4266631647R1, the client, sends a SYN from its port 41868 to H1’s port 2001. It carries R1’s starting number, 4266631647. Its log line shows CLOSED, R1’s state when the line was logged; then R1 waits in SYNSENT.Debug line at this stepNov 24 20:28:43.743: tcp0: I SYNSENT 10.0.1.10:2001 10.0.1.1:41868 seq 2290243570H1 answers with one segment that does two jobs. As a SYN, it carries H1’s own starting number, 2290243570. As an ACK, it names 4266631648, the next number it expects from R1.Debug line at this stepNov 24 20:28:43.743: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648R1 confirms H1’s number with an ACK that names 2290243571. Both numbers have now been given and confirmed, and R1’s state becomes ESTAB. Its log line reads seq 4266631648, because the SYN used up R1’s starting number.The connection from 41868 to 2001 is open, and data can now flow both ways.

On R1, TCP debugging (debug ip tcp packet port 2001) was on while this connection opened and later closed. The log is filtered to the first line of each segment:

R1’s SYN goes out (O CLOSED), H1’s SYN and ACK come in (I SYNSENT), and R1’s ACK goes out (O ESTAB). The next two lines are more ACKs from R1, and from 20:28:55 on, the lines are the close of the connection.

Lines appear as you step through.

Output · IOS XE 17.18.2
R1#show logging | include tcp01Nov 24 20:28:41.742: tcp0: O CLOSED 10.0.1.10:2001 10.0.1.1:41868 seq 4266631647… 1 more line (see Full output)2Nov 24 20:28:43.743: tcp0: I SYNSENT 10.0.1.10:2001 10.0.1.1:41868 seq 22902435703Nov 24 20:28:43.743: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:28:43.743: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:28:44.948: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:28:55.657: tcp0: I ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 2290243571Nov 24 20:28:55.657: tcp0: O CLOSEWAIT 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:29:06.701: tcp0: O LASTACK 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:29:06.702: tcp0: I LASTACK 10.0.1.10:2001 10.0.1.1:41868 seq 2290243572
Full output · 10 lines
R1#show logging | include tcp0Nov 24 20:28:41.742: tcp0: O CLOSED 10.0.1.10:2001 10.0.1.1:41868 seq 4266631647Nov 24 20:28:43.742: tcp0: R SYNSENT 10.0.1.10:2001 10.0.1.1:41868 seq 4266631647Nov 24 20:28:43.743: tcp0: I SYNSENT 10.0.1.10:2001 10.0.1.1:41868 seq 2290243570Nov 24 20:28:43.743: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:28:43.743: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:28:44.948: tcp0: O ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:28:55.657: tcp0: I ESTAB 10.0.1.10:2001 10.0.1.1:41868 seq 2290243571Nov 24 20:28:55.657: tcp0: O CLOSEWAIT 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:29:06.701: tcp0: O LASTACK 10.0.1.10:2001 10.0.1.1:41868 seq 4266631648Nov 24 20:29:06.702: tcp0: I LASTACK 10.0.1.10:2001 10.0.1.1:41868 seq 2290243572

On R1, right after the handshake:

R1 lists one open connection: its own end, port 41868, and H1’s end at port 2001.

Output · IOS XE 17.18.2 · some columns removed
R1#show tcp briefLocal Address   Foreign Address  (state)110.0.1.1.41868  10.0.1.10.2001   ESTAB0.0.0.0.22      *.*              LISTEN::.22           *.*              LISTEN
  1. ESTAB: the handshake is done and the connection is open.
Full output · 4 lines
R1#show tcp briefTCB       Local Address               Foreign Address             (state)7A404C8FFA40  10.0.1.1.41868             10.0.1.10.2001              ESTAB------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN

Use the rule: in the handshake, an ACK names the other end’s number plus one.

H1’s SYN carries the starting number 2290243570. Complete R1’s last segment of the handshake: ACK __.

A FIN from each end closes it

The program on H1 port 2001 stops. How do the two ends take the connection down?

In a normal close, each end tells the other that it has finished sending. A FIN is the segment that says so, and it means “I have nothing more to send”. It closes one direction only, and the other end confirms it with an ACK. Here the close took four segments, a FIN and an ACK in each direction.

Once H1 has sent its FIN, can R1 still send? It can still send until it sends its own FIN (Figure 2.3). Each direction closes on its own.

R1H1FIN from H1nothing more to sendACKCLOSEWAITFIN from R1nothing more to sendACK
Figure 2.3 · H1 closes its direction first; R1 confirms it and shows CLOSEWAIT; then R1 closes its own.

Two lanes, R1 on the left and H1 on the right; time runs down. Top down: an arrow “FIN from H1, nothing more to send” from H1 to R1; an arrow “ACK” back to H1; on R1’s lane a highlighted state tag, CLOSEWAIT; an arrow “FIN from R1, nothing more to send” from R1 to H1; an arrow “ACK” back to R1.

Between the two FINs, R1’s state is CLOSEWAIT. H1 has sent its FIN and R1 has confirmed it, but R1 has not sent its own. R1 stays in CLOSEWAIT until something on R1 itself asks to close; here R1 closes it with disconnect 1.

On R1, after the program on H1 port 2001 stops:

Only H1’s direction is closed; R1’s own direction is still open.

Output · IOS XE 17.18.2 · some columns removed
R1#show tcp briefLocal Address   Foreign Address  (state)110.0.1.1.41868  10.0.1.10.2001   CLOSEWAIT0.0.0.0.22      *.*              LISTEN::.22           *.*              LISTEN
  1. The same R1 end, 10.0.1.1.41868, and the same far end. The state is now CLOSEWAIT.
Full output · 4 lines
R1#show tcp briefTCB       Local Address               Foreign Address             (state)7A404C8FFA40  10.0.1.1.41868             10.0.1.10.2001              CLOSEWAIT------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN

On R1, the client closes its own side with disconnect 1. The 1 names the connection to close, here the telnet session R1 opened to H1:

After you press Enter, R1 sends its FIN.

Output · IOS XE 17.18.2
R1#disconnect 11Closing connection to 10.0.1.10 [confirm]
  1. R1 names the connection to 10.0.1.10 and asks you to confirm.

Impact Closes this one connection on R1.

On R1, right after:

H1 has confirmed R1’s FIN, and the connection is gone.

Output · IOS XE 17.18.2 · some columns removed
R1#show tcp brief10.0.0.0.22  *.*  LISTEN1::.22       *.*  LISTEN
  1. Only R1’s own LISTEN lines on port 22 are left; no line shows the far end 10.0.1.10.2001 any more.
Full output · 2 lines
R1#show tcp brief------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN

In R1’s log, H1’s FIN comes in at 20:28:55 (I ESTAB) and R1 confirms it (O CLOSEWAIT). At 20:29:06 R1 sends its own FIN (O LASTACK) and waits in LASTACK for the ACK of that FIN, which comes in a millisecond later (I LASTACK).

The connection did not vanish when the program on H1 stopped. It stayed as CLOSEWAIT while R1 could still send.

Key idea

Each end closes its own direction with a FIN, and the other end confirms it with an ACK.

R1 holds connections to H1 ports 2001 and 2002. The program on 2002 stops and sends its FIN. What does R1 show for the 2002 line, and which end must send the next FIN?

Verify

Read where each connection stands

R1 holds three connections with H1, each at a different point between opening and closing. How do you tell them apart?

R1’s show tcp brief has one line for each connection (Figure 2.4), so you tell the three apart by H1’s port in the far end’s address.

Where each one stands is in the last column, the state. ESTAB means an open connection. CLOSEWAIT means the far end has sent its FIN, and this end has not sent its own. FINWAIT2 means this end has sent its FIN and the far end has confirmed it; this end is now waiting for the far end’s FIN.

R1H1port 2001port 2002port 2003connectionone link, three connections
Figure 2.4 · R1 holds three connections with H1, one to each program.

R1 stands on the left and H1 on the right, with three port tags inside H1: port 2001, port 2002 and port 2003. One link joins R1 and H1. Beside it, three dashed lines, the connections, run from just in front of R1 to the three tags, each with a dot at both ends. A note under them reads “one link, three connections”.

On R1, with three connections to H1, just after R1 sends its FIN on the one to port 2003:

Tap a line, or “Not in the output”, then submit.

Find the connection where H1 has sent its FIN but R1 has not sent its own.

Output · IOS XE 17.18.2 · some columns removed
R1#show tcp brief1Local Address   Foreign Address  (state)

One connection is open, one is half closed by H1, and one R1 has just closed from its side.

  1. Column names: R1’s end (Local Address), the far end (Foreign Address), the state.
  2. The connection to port 2001: ESTAB, open in both directions.
  3. The connection to port 2002: CLOSEWAIT. H1 has sent its FIN; R1 has not sent its own.
  4. On the connection to port 2003, R1 sent its FIN first and H1 confirmed it, so the state is FINWAIT2.
Full output · 6 lines
R1#show tcp briefTCB       Local Address               Foreign Address             (state)7A4045C10CA8  10.0.1.1.54564             10.0.1.10.2001              ESTAB7A404BA882D0  10.0.1.1.49125             10.0.1.10.2002              CLOSEWAIT7A404BA88EF0  10.0.1.1.23440             10.0.1.10.2003              FINWAIT2------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN

Key idea

ESTAB: open. CLOSEWAIT: the far end has closed its direction; this end has not.

R1 shows CLOSEWAIT for its connection to H1 port 2002. Can R1 still send data on it?

Troubleshoot

Refused, or no answer at all

R1’s client gets no connection. Did H1 say no, or did nothing answer at all?

How can a host say no to a SYN? It answers with an RST (a reset), a segment that refuses or cuts a connection, and a host with no program on that port normally answers a SYN with an RST. Where nothing answers, no segment comes back at all. So in R1’s log, look for an I line, which shows a segment that came back to R1.

Case 1 of 2.H1 refuses the attempt with a reset

R1H1SYN to port 2010RST: nothing waits
Figure 2.5 · Case 1 · Where nothing waits on the port, H1 answers R1’s SYN with a reset.

Two lanes, R1 and H1. An arrow marked “SYN to port 2010” runs from R1 to H1, and a highlighted arrow marked “RST: nothing waits” runs back to R1.

  1. Case 1 · Symptom

    On R1, a client tries H1 port 2010 and is refused.

    Output · IOS XE 17.18.2
    R1#telnet 10.0.1.10 2010Trying 10.0.1.10, 2010 ... 1% Connection refused by remote host
    1. H1 refused the connection.
  2. Case 1 · Command

    With TCP debugging turned on for port 2010 (debug ip tcp packet port 2010), R1 logs each segment of the attempt, so show logging tells what came back to R1’s SYN. Unfiltered, the log also shows the second line of each segment, which names its kind (SYN, ACK or RST).

  3. Case 1 · Output

    R1’s SYN went out, H1’s answer came back marked RST, and R1 closed the attempt.

    Output · IOS XE 17.18.2
    R1#show logging… 24 more lines (see Full output)1Nov 24 20:45:31.637: tcp0: O CLOSED 10.0.1.10:2010 10.0.1.1:35634 seq 36447681971        OPTS 12 2  4  5  B4  4  2  1  1  3  3  2  0  SYN  WIN 65535… 3 more lines (see Full output)2Nov 24 20:45:33.638: tcp0: I SYNSENT 10.0.1.10:2010 10.0.1.1:35634 seq 02        ACK 3644768198 RST  WIN 03Nov 24 20:45:33.638: TCP0: bad seg from 10.0.1.10 -- closing connection: port 35634 seq 0 ack 3644768198 rcvnxt 0 rcvwnd 0 len 0
    1. R1’s SYN to port 2010 goes out (O). Its second line shows SYN.
    2. Key line An I line, so H1 answered. Its second line shows RST, a reset, not a SYN and ACK. Its ACK 3644768198 is R1’s number plus one, so H1 heard the SYN.
    3. R1 takes the reset and closes the attempt (closing connection).
    Full output · 32 lines
    R1#show loggingSyslog logging: enabled (0 messages dropped, 2 messages rate-limited, 0 flushes, 0 overruns, xml disabled, filtering disabled) No Active Message Discriminator.   No Inactive Message Discriminator.      Console logging: disabled    Monitor logging: level debugging, 0 messages logged, xml disabled,                     filtering disabled    Buffer logging:  level debugging, 11 messages logged, xml disabled,                    filtering disabled    Exception Logging: size (4096 bytes)    Count and timestamp logging messages: disabled    Persistent logging: disabled    Trap logging: level informational, 53 message lines logged        Logging Source-Interface:       VRF Name: Log Buffer (64000 bytes): Nov 24 20:45:25.920: %SYS-5-CONFIG_I: Configured from console by consoleNov 24 20:45:26.121: %SYS-4-LOG_CLEARED: Logging buffer was cleared by user UnknownNov 24 20:45:31.637: tcp0: O CLOSED 10.0.1.10:2010 10.0.1.1:35634 seq 3644768197        OPTS 12 2  4  5  B4  4  2  1  1  3  3  2  0  SYN  WIN 65535Nov 24 20:45:33.637: tcp0: R SYNSENT 10.0.1.10:2010 10.0.1.1:35634 seq 3644768197        OPTS 12 2  4  5  B4  4  2  1  1  3  3  2  0  SYN  WIN 65535Nov 24 20:45:33.637: TCP0: timeout #1 - timeout is 4000 ms, seq 3644768197Nov 24 20:45:33.638: tcp0: I SYNSENT 10.0.1.10:2010 10.0.1.1:35634 seq 0        ACK 3644768198 RST  WIN 0Nov 24 20:45:33.638: TCP0: bad seg from 10.0.1.10 -- closing connection: port 35634 seq 0 ack 3644768198 rcvnxt 0 rcvwnd 0 len 0
  4. Case 1 · What it means

    • H1 is there: it answered the SYN.
    • Nothing waits on port 2010, so H1 refused the connection with a reset.
    • Check the port number the client uses.
  5. Case 1 · Fix

    Use the port where the program waits, 2001. On R1:

    Output · IOS XE 17.18.2
    R1#telnet 10.0.1.10 20011Trying 10.0.1.10, 2001 ... Open
    1. Open: the connection to port 2001 is open.
  6. Case 1 · Proof

    R1 lists the connection as open.

    Output · IOS XE 17.18.2 · some columns removed
    R1#show tcp briefLocal Address   Foreign Address  (state)110.0.1.1.23017  10.0.1.10.2001   ESTAB0.0.0.0.22      *.*              LISTEN::.22           *.*              LISTEN
    1. Far end 10.0.1.10.2001, ESTAB.
    Full output · 4 lines
    R1#show tcp briefTCB       Local Address               Foreign Address             (state)7E42BA179318  10.0.1.1.23017             10.0.1.10.2001              ESTAB------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN

End of case 1. Solved: connection to port 2001 open

Case 2 of 2.Nothing answers the SYN

R110.0.1.100no deviceSYNSYN againno answer
Figure 2.6 · Case 2 · Where no device answers, R1’s TCP tries its SYN again and again, and nothing comes back.

R1’s lane and a dotted lane under an outline card “10.0.1.100, no device”. Four arrows start from R1 and stop short of the dotted lane, the first marked “SYN”, the second “SYN again”. No arrow comes back; a note reads “no answer”.

  1. Case 2 · Symptom

    On R1, a client tries 10.0.1.100 port 2001. Nothing happens for about 30 seconds, then it gives up.

    Output · IOS XE 17.18.2
    R1#telnet 10.0.1.100 2001Trying 10.0.1.100, 2001 ... 1% Connection timed out; remote host not responding
    1. No answer came back, so the attempt timed out.
  2. Case 2 · Command

    Read R1’s TCP debugging lines with show logging | include tcp0, to see what came back to R1’s SYN.

  3. Case 2 · Output

    Output · IOS XE 17.18.2
    R1#show logging | include tcp01Nov 24 20:31:47.787: tcp0: O CLOSED 10.0.1.100:2001 10.0.1.1:41690 seq 9898544452Nov 24 20:31:49.787: tcp0: R SYNSENT 10.0.1.100:2001 10.0.1.1:41690 seq 9898544452Nov 24 20:31:53.788: tcp0: R SYNSENT 10.0.1.100:2001 10.0.1.1:41690 seq 9898544452Nov 24 20:32:01.789: tcp0: R SYNSENT 10.0.1.100:2001 10.0.1.1:41690 seq 989854445
    1. R1’s TCP sends its SYN to 10.0.1.100 (O).
    2. Key line Only R lines: R1’s TCP tries the same SYN again and again. There is no I line: nothing came back.
  4. Case 2 · What it means

    • No device answered the SYN, not even with a refusal.
    • A time-out says nothing about a program, because no far end took part.
    • Check the address: H1 is 10.0.1.10, not 10.0.1.100.
  5. Case 2 · Fix

    Use H1’s address, 10.0.1.10, instead of 10.0.1.100. R1 already holds a connection to port 2001, opened earlier; this time connect to H1’s other program, on port 2002. On R1:

    Output · IOS XE 17.18.2
    R1#telnet 10.0.1.10 20021Trying 10.0.1.10, 2002 ... Open
    1. Open: the connection to port 2002 is open.
  6. Case 2 · Proof

    R1 lists the new connection as open.

    Output · IOS XE 17.18.2 · some columns removed
    R1#show tcp briefLocal Address   Foreign Address  (state)110.0.1.1.50157  10.0.1.10.2002   ESTAB210.0.1.1.42396  10.0.1.10.2001   ESTAB… 2 more lines (see Full output)
    1. The new connection: far end 10.0.1.10.2002, ESTAB.
    2. R1’s connection to port 2001, still ESTAB.
    Full output · 5 lines
    R1#show tcp briefTCB       Local Address               Foreign Address             (state)75A0E9DBC2D0  10.0.1.1.50157             10.0.1.10.2002              ESTAB75A0E3F44CA8  10.0.1.1.42396             10.0.1.10.2001              ESTAB------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN

End of case 2. Solved: connection to port 2002 open

Both cases

Key idea

Refused: H1 answered the SYN with a reset; it is there, and nothing waits on that port. No answer: nothing came back at all; check the address, and whether the host is up.

A client on R1 tries another port on H1 and gets % Connection refused by remote host. Is H1 up?

Check

Which list puts the three segments that open a TCP connection in order?
On another connection, R1’s SYN carries the starting number 3201597434, and H1’s SYN and ACK carry H1’s starting number, 1548114120. Which number does R1’s ACK name?
An attempt from R1 waits a long time, then reports that the remote host is not responding. Which cause is more likely?

Later, on R1:

Tap a line, or “Not in the output”, then submit.

Find the connection where H1 has closed its direction.

Output · IOS XE 17.18.2 · some columns removed
R1#show tcp brief
Full output · 6 lines
R1#show tcp briefTCB       Local Address               Foreign Address             (state)75A0E9DBCEF0  10.0.1.1.55418             10.0.1.10.2003              ESTAB75A0E9DBC2D0  10.0.1.1.50157             10.0.1.10.2002              ESTAB75A0E3F44CA8  10.0.1.1.42396             10.0.1.10.2001              CLOSEWAIT------------  0.0.0.0.22                 *.*                         LISTEN------------  ::.22                      *.*                         LISTEN
R1 shows CLOSEWAIT for a connection to H1. Which FINs have been sent on it so far?

Summary

R1H1ESTABport 2001SYN · seq 4266631647SYN, ACK · seq 2290243570ack 4266631648ACK · ack 2290243571connection 41868 – 2001open: data can flow
Figure 2.2, recap · The connection from 41868 to 2001 is open, and data can now flow both ways.

R1 stands on the left and H1 on the right, each with a lane running down under it; time runs down. Under H1 a small note reads “port 2001”. Under R1 a state tag reads SYNSENT and later ESTAB. Arrows cross between the lanes, top down: “SYN, seq 4266631647” from R1 to H1; “SYN, ACK, seq 2290243570, ack 4266631648” from H1 to R1; “ACK, ack 2290243571” from R1 to H1. The last step adds a box under the lanes: “connection 41868 to 2001, open”.

  • Each end counts its own data, from a starting number of its own.
  • SYN, then SYN and ACK, then ACK open a connection; each ACK names the other end’s number plus one.
  • A FIN closes one direction, and an ACK confirms it. CLOSEWAIT means the far end has closed its direction.
  • The state column of show tcp brief says how far a connection has come.
  • Refused means a reset came back; timed out means nothing came back.