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
- DNS client creates a message
- Create a datagram
- Create a packet
- Determine destination MAC address
- Create and transmit a frame
- NAT and forward frame to Internet
- Forward frame to DNS server
- DNS server receives frame
- DNS translates and generates reply
- Forward frame to local router
- NAT translation in local router
- Frame forwarded to PC
- DNS client delivers IP address
- HTTP client creates message
1 Enter website in browser
Open a web browser on the PC and enter the website name.
2 DNS client creates a message
The HTTP client in the PC tries to generate a message requesting the HTML file at 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.
3 Create a datagram
It creates the source port number and assigns it to the DNS process requesting the IP address. The "Well-Known" DNS server port # is used as the destination port. The resulting datagram is then sent to the Network layer.
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.
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 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 for the default gateway. The Address Resolution Protocol or ARP was created to solve this problem.
6 Create and transmit a frame
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.
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 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 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 ISP router's MAC address.
The local router forwards this new frame to the ISP's router.
8 Forward frame to DNS server
The router at the Internet Service Provider 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 the source and destination IP addresses remain the same.
The new frame is sent to the DNS server.
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.
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.
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.
12 NAT translation in local router
When the local router receives the packet from the ISP’s router, it consults its NAT translation 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 # are substituted into the packet that will be sent to the local network.
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.
14 DNS client delivers IP address
When the Frame arrives at the PC the message is sent to the DNS client.
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.
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.