Detailed TCP/IP Communication Example

Example: Download a Webpage from the Internet

Let’s observe the first TCP/IP transactions that enable a local host to download a webpage from the Internet. Before continuing through this example, you should be familiar with local network TCP/IP communication, and how DNS servers and NAT work.

  1. Enter website in browser
  2. DNS client creates a message
  3. Create a datagram
  4. Create a packet
  5. Determine destination MAC address
  6. Create and transmit a frame
  7. NAT and forward frame to Internet
  8. Forward frame to DNS server
  9. DNS server receives frame
  10. DNS translates and generates reply
  11. Forward frame to local router
  12. NAT translation in local router
  13. Frame forwarded to PC
  14. DNS client delivers IP address
  15. HTTP client creates message

1 Enter website in browser

Open a web browser on the PC and enter the website name.

detailed_step_1.png

2 DNS client creates a message

The HTTP client in the PC tries to generate a message requesting the HTML file from www.website.com. It needs to supply the destination IP address in the message it generates but doesn’t have it, so it employs the PC’s DNS client to get it.

The DNS client sends a message to the Transport layer requesting the IP address for website.com.

detailed_step_2.png

3 Create a datagram

The Transport layer adds the UDP header containing the source and destination port to the message.

It creates the source port number and assigns it to the DNS process requesting the IP address. The "Well-Known" DNS server port number is used as the destination port. The resulting datagram is then sent to the Network layer.

detailed_step_3.png

4 Create a packet

The Network layer adds the IP header containing the source and destination IP address to the datagram.

It adds its own IP address as the source and the DNS server IP address as the destination. The PC knows the DNS server’s IP address because the router provided the PC with it when it assigned its local IP address. The resulting packet is sent to the Link layer.

detailed_step_4.png

The router provided the PC with the default gateway (gateway between the local network and Internet which is the router in this case) and DNS IP addresses when it assigned its local IP address.

5 Determine destination MAC address

The Link layer that determines the destination IP address for this packet is not on the local network. It, therefore, needs to send the packet to its default gateway which in this example is the router.

Now we have a problem. The Link Layer can’t create the frame because it doesn’t know the MAC address of the default gateway. The Address Resolution Protocol (ARP) was created to solve this problem.

detailed_step_5.png

6 Create and transmit a frame

After using ARP to get the MAC address for its default gateway, the Link Layer can complete the frame for the DNS transaction.

It adds the source and destination MAC addresses to the packet to create a frame. The source MAC address is its own and the destination MAC address is that of the default gateway.

This frame is then sent to the Physical layer to transmit the frame’s bits.

detailed_step_6.png

7 NAT and forward frame to Internet

The router receives the frame from the PC, opens the packet and determines the destination IP address is not on the local network, so it must forward this frame to the Internet.

The router creates a new Network Address Translation (NAT) entry and changes the local network IP address to its public Internet IP address. It also uses the same NAT table entry to change the source port so the router can determine which host and host process to deliver in-coming packets to.

The router has to change the source MAC from its local network MAC to its Wide Area Network (WAN) or Internet MAC. The destination MAC address also needs to be changed to that of the router's default gateway, which in this example is the ISP's router. The local router references its ARP table to get the Internet Service Provider (ISP) router's MAC address.

The local router forwards this new frame to the ISP's router.

detailed_step_7.png

8 Forward frame to DNS server

The router at the ISP receives the frame and opens the packet to find the destination IP address. It determines the destination IP address belongs to its DNS server. The router’s Network layer sends the packet back to its Link layer to generate a new frame header.

The source MAC address is its own and the destination MAC address is the DNS server’s. Note that the source and destination IP addresses remain the same.

The new frame is sent to the DNS server.

detailed_step_8.png

9 DNS server receives frame

The DNS server’s PHY receives the bits and forwards the frame to the Link layer.

The Link layer finds its MAC address as the destination so it forwards the packet to the Network layer.

The Network layer opens the packet and finds its IP address as the destination. It still needs to pay attention to the message, so it forwards it up to the Transport layer.

The Transport layer opens the datagram and finds it is being sent to port 53. The DNS server has a process running and listening for traffic on this port, so the message is forwarded to it.

detailed_step_9.png

10 DNS translates and generates reply

The DNS Server determines the IP address for website.com and generates a reply message containing it. The message is sent back to the Transport layer.

The Transport layer adds the port information and creates the datagram.

The Network layer adds the IP information and creates the packet.

The Link layer adds the MAC information and creates the frame.

The Physical layer transmits the frame’s bits to the router.

detailed_step_10.png

11 Forward frame to local router

The ISP’s router receives the frame, finds its MAC address, and sends it to its Network layer to determine the destination IP address. It finds that the packet belongs to our local router’s IP address, so it sends the packet back down to its Link layer.

The Link layer attaches new source and destination MAC addresses to the packet then sends the frame to our local router.

detailed_step_11.png

12 NAT translation in local router

When the local router receives the packet from the ISP’s router, it consults its NAT table to determine which local host to forward it to. It finds an entry with an internet destination port number of 1 in the translation table.

The corresponding local IP address and port number are substituted into the packet that will be sent to the local network.

detailed_step_12.png

13 Frame forwarded to PC

The new packet is sent to the router’s Link layer where the source and destination MAC addresses are added creating the frame.

The router knows the destination MAC address corresponding to the destination IP address by consulting its ARP table.

This frame is then sent to the physical layer to be transmitted on the network.

detailed_step_13.png

14 DNS client delivers IP address

When the Frame arrives at the PC the message is sent to the DNS client.

The DNS client then provides the IP address for website.com to the HTTP client.

detailed_step_14.png

15 HTTP client creates message

Now that the HTTP client has the IP address for website.com (130:27:45:69) it can generate the message to download the HTML file for this website.

detailed_step_15.png

At this point in the process, we’ve demonstrated NAT and DNS server functionality. We’ve also shown how the MAC source and destination addresses change from node to node and that the IP source and destination addresses stay the same from the source to the destination (other than across the network boundary). The rest of the TCP/IP communications to download this web page should be understood at this point.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.