🌐
CCNA Prep
  • Intro
  • Network Devices
  • Interfaces and Cables
  • OSI Model & TCP/IP Suite
  • Intro to the CLI
  • Ethernet LAN Switching (Part 1)
  • Ethernet LAN Switching (Part 2)
  • IPv4 Addressing (Part 1)
  • IPv4 Addressing (Part 2)
  • Switch Interfaces
  • IPv4 Header
  • Routing Fundamentals
  • The Life of a Packet
  • Subnetting (Part 1)
  • Subnetting (Part 2)
  • Subnetting (Part 3 - VLSM)
  • VLANs (Part 1)
  • VLANs (Part 2)
  • VLANs (Part 3)
  • DTP/VTP
  • Spanning Tree Protocol (Part 1)
  • Spanning Tree Protocol (Part 2)
  • Rapid Spanning Tree Protocol
  • EtherChannel
  • Dynamic Routing
  • RIP & EIGRP
  • OSPF (Part 1)
  • OSPF (Part 2)
  • OSPF (Part 3)
  • First Hop Redundancy Protocols
  • TCP & UDP
  • IPv6 (Part 1)
  • IPv6 (Part 2)
  • IPv6 (Part 3)
  • Standard ACLs
  • Extended ACLs
  • CDP & LLDP
  • NTP
  • DNS
  • DHCP
  • SNMP
  • Syslog
  • SSH
  • FTP & TFTP
  • NAT (Part 1)
  • NAT (part 2)
  • QoS (Part 1)
  • QoS (Part 2)
  • Security Fundamentals
  • Port Security
  • DHCP Snooping
  • Dynamic ARP Inspection
  • LAN Architectures
  • WAN Architectures
  • Virtualization & Cloud, Containers, VRF
  • Wireless Fundamentals
  • Wireless Architectures
  • Wireless Security
  • Wireless Configuration
  • Network Automation
  • JSON, XML, & YAML
  • REST APIs
  • Software-Defined Networking
  • Ansible, Puppet, & Chef
Powered by GitBook
On this page
  • Transport Layer
  • TCP
  • UDP

TCP & UDP

Day 30

PreviousFirst Hop Redundancy ProtocolsNextIPv6 (Part 1)

Last updated 1 year ago

Transport Layer

The transport layer provides Layer 4 addressing (port numbers). TCP also provides some services to applications:

  • reliable data transfer

  • error recovery

  • data sequencing

  • flow control

When accessing several services simultaneously, the sessions need to be tracked. A session is an exchange of data between two or more communicating devices. The host should be able to handle multiple communication sessions (e.g. multiple internet tabs) at once. So, the combination of source and destination port numbers is used to distinguish between these sessions. IANA (Internet Assigned Numbers Authority) has designated the following ranges:

  • Well-known port numbers: 0 - 1023

  • Registered port numbers: 1024 - 49151

  • Ephemeral/private/dynamic port numbers: 49152 - 65535

Well-known port numbers are used for major protocols (e.g. HTTP, FTP) and very strictly regulated. Registered port numbers require registration to use. Private ports are used when selecting a random source port.

TCP

  • TCP is connection-oriented. Before sending data to the destination host, the two hosts first communicate to establish a connection.

  • TCP provides reliable communication. The destination host must acknowledge that it received each TCP segment. If not acknowledged within a certain time, the segment is sent again. Hosts set a random initial sequence number. Forward acknowledgement is used to indicate the sequence number of the next segment the host expects to receive.

  • TCP provides sequencing. Sequence numbers in the TCP header allow destination hosts to put segments in the correct order even when data arrives out of order.

  • TCP provides flow control. It helps to regulate the rate data is sent. Acknowledging every single segment is inefficient. The TCP header's Window Size field allows more data to be sent before an acknowledgement is required. A sliding window can be used to dynamically adjust the window size.

Header

The source and destination port fields are 16 bits each so there are 65536 available port numbers. Sequence and acknowledgement number fields provide sequencing and reliable communication. ACK, SYN, and FIN flags are used to establish and terminate connections. The window size field is used for flow control.

3-way Handshake

Before sending the data, TCP first establishes a connection by using a 3-way handshake. First, the source host sends a TCP segment with a SYN flag set. The destination host then replies with a SYN and ACK flags set. Lastly, the source host sends a TCP segment with an ACK flag set and the connection is established.

4-way Handshake

To terminate the connection, TCP uses a 4-way handshake. The client sends a TCP segment with a FIN flag set. The server then acknowledges it with an ACK flag set and sends its own TCP segment with a FIN flag. Finally, the client acknowledges it and the connection is terminated.

UDP

  • UDP is not connection-oriented. The data is sent without any prior connection.

  • UDP doesn't provide a reliable communication. There is no concept of acknowledgements and re-transmission. Segments are sent best-effort.

  • UDP doesn't provide sequencing. There is no sequence number field in the UDP header.

  • UDP doesn't provide flow control.

So, here is a chart comparing TCP with UDP.

14KB
Day 30 Flashcards - TCP _ UDP.apkg
TCP Header
UDP Header
port number example
tcp header
3-way handshake
4-way handshake
udp header
tcp vs. udp