In this blog, I will summarize the basics of TCP/IP which most developers should know.
Basics
Let's first see how a simple network request works. When a client machine sends a url request, the first job is to figure out which machine this url maps to. This is done using DNS (domain name service). This service is used to convert names/urls into IP addresses. Once the ip address is obtained the request then goes to the actual machine in the data center.
Each client machine also has an IP address. It gets this IP address from the DHCP (Dynamic Host Configuration Protocol) server. Usually at home, the linksys or netgear etc router has a DHCP server inbuilt. The client machine requests the DHCP server for an IP address. DHCP server assigns an IP address to this client machine which the client machine acknowledges. If the client is unable to get an IP address from DHCP, it will self configure itself to 169.254.x.x. This IP is never used in the real world and if you see this IP address, it means that there is something wrong with the network.
IPv4 is the version 4 of IP. Its address space is 2^32 which is now running out. IPv4 looks like xxx.xxx.xxx.xxx where x is a number. IPv6 is created to resolve this problem. Its address space is 2^128. IPv6 is looks like xxxx::xxxx::xxxx::xxxx where x can be a number or letter.
Basics
Let's first see how a simple network request works. When a client machine sends a url request, the first job is to figure out which machine this url maps to. This is done using DNS (domain name service). This service is used to convert names/urls into IP addresses. Once the ip address is obtained the request then goes to the actual machine in the data center.
Each client machine also has an IP address. It gets this IP address from the DHCP (Dynamic Host Configuration Protocol) server. Usually at home, the linksys or netgear etc router has a DHCP server inbuilt. The client machine requests the DHCP server for an IP address. DHCP server assigns an IP address to this client machine which the client machine acknowledges. If the client is unable to get an IP address from DHCP, it will self configure itself to 169.254.x.x. This IP is never used in the real world and if you see this IP address, it means that there is something wrong with the network.
IPv4 is the version 4 of IP. Its address space is 2^32 which is now running out. IPv4 looks like xxx.xxx.xxx.xxx where x is a number. IPv6 is created to resolve this problem. Its address space is 2^128. IPv6 is looks like xxxx::xxxx::xxxx::xxxx where x can be a number or letter.
How DNS Works
Let's say a client machine tries to surf www.google.com. These are the steps that happen in order to resolve www.google.com into an IP address -
Let's say a client machine tries to surf www.google.com. These are the steps that happen in order to resolve www.google.com into an IP address -
- The client machine asks the DNS server about where this website may be. If you run ipconfig command you can find the IP address of the DNS server that the client machine contacts.
- The DNS server contacts a root NS asking about this website. The root NS knows about .com NS, .net NS, .info NS. So for our case the root NS tells our DNS server about the .com NS.
- DNS server then contacts the .com NS. com NS knows where google.com NS is located and sends this information to the DNS server.
- DNS server then contacts the google.com NS. google.com NS sends the IP address to the DNS server concluding the name resolution process.
We can verify these steps by using tools like Wireshark. We can use the nslookup command to do the dns lookup. Below is a screenshot of nslookup for www.microsoft.com.
DNS entries are cached for a certain duration. We can use the command ipconfig /displaydns to see which entries are cached on your machine.
nslookup has multiple types that we can query. The one queried above was of type A. It means it will return address for the name provided. Example of few other types are shown below:
Type NS (for name servers)
Type MX (for mail exchange servers)
Type CNAME (for aliases)
We can also use the type AAAA for finding IPv6 addresses.