Introduction to TCP/IP (Part 5) - Detailed TCP/IP Communication Example

Last modified by Microchip on 2023/11/10 11:18

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.

Enter website in browser

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

enter the website name in browser
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 Domain Name Server (DNS) client sends a message to the Transport layer requesting the IP address for website.com.

DNS client creates a message
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.

Create a datagram
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.

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.

Create a packet
Use ARP for gateway 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.

Use ARP for gateway MAC address
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.

Create and transmit a frame
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 incoming 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.

NAT and forward frame to Internet
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.

Forward frame to DNS server
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.

DNS server receives frame
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.

DNS translates and generates reply
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.

Forward frame to local router
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.

NAT translation in local router
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.

Frame forwarded to PC
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.

DNS client delivers IP address
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.

HTTP client creates message

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.

Back to top

Learn More

Back to top