Understanding the Journey of a Search Query: The Role of IP Addresses and Port Numbers
Table of contents
Problem
Ever wondered what happens when you search for something on the internet?
How do you get search results from a server?
How does your search query on a website (e.g., google.com) travel from your device to Google's server, and how do you get the result back?
Do you know how the response (search result) finds its way back to your device?
Solution (IP Address)
An IP address alone won't solve all these problems, but in this article, we will focus on the role of IP addresses and how they help address these issues. In future articles in this series, we will discuss topics like the OSI model, network structure, client-server architecture, and more.
IP Address
Before understanding an IP address, let's first look at what IP (Internet Protocol) is: a set of rules for routing and addressing data packets so they can travel across networks and reach the correct destination.
An IP address is an address on the internet that helps devices communicate with each other.
Every device on the internet has its own unique IP address, which helps to uniquely identify it.
Format of IP Address: X.X.X.X where X ranges from 0 to 255.
Now that we understand the basics of IP addresses, let's address the questions mentioned above.
Solving the Problem
Let's say you searched for 'longest day of the year' on google.com
. Your search query is sent to Google's server, and the server sends the response back to your device.
This process involves several steps, which are shown below in the form of a diagram.
Let's go through the above diagram step by step from right, skipping the Internet (we all know what the Internet is and will cover this within the ISP topic).
ISP
ISP(Internet service provider) is a company which provides internet to its users via router.
Internet is the connection of computer network on global level.
Router
The router provided by the ISP contains a global IP address (publicly accessible from the Internet).
All devices connected to the router share the same global IP address for everyone around the world.
Each device connected to the router also has its own local IP address (not accessible from the Internet).
The router assigns local IP addresses to devices through DHCP (Dynamic Host Configuration Protocol).
When you search for something on the internet (google.com) using your device, Google's server receives the query from the global IP address of your router and sends the response back to the same global IP address.
After receiving the response from Google's server, the router figures out which device made the request. This is done with the help of NAT (Network Address Translation). It then remembers the local IP address of the device.
However, it doesn't know which app sent the request. This is where port numbers come to the rescue.
Port numbers help to identify which app initiated the request. This is also done with the help of NAT (Network Address Translation).
After knowing the port number, the router forwards the response to the local IP address (user device) with port number attached.
Once the device receives the response from the router, the router's job is complete.
User Device
When it receives response from router now its time to send the response to the application from where request is made.
As port numbers is also attached with response from router, device figures out port number and send the response to the appropriate app from where request was initiated.
Conclusion
In this way, you can understand the journey of a search query from your device to the internet and back. The IP address plays a vital role by uniquely identifying devices and enabling smooth communication. Ports and NAT ensure that the responses reach the correct app on the correct device. These basic concepts provide a starting point for exploring more networking topics.
You can subscribe to my newsletter to get notified when I publish more concepts like OSI model, network structure, and more!.
Subscribe to my newsletter
Read articles from Gaurab Khanal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by