Computer Networking-How does the Internet work?
I love teaching and passionate about coding!!
Introduction:
The computers connected together are known as NETWORK. The collection of such computer networks is called the INTERNET. Internet was started by the USA, as ARPANET (advanced research projects agency network), as a research project.
The computers across the countries are connected using submarine cables that run across the ocean (buried on the ocean floor). These submarine cables are faster than satellites. ISPs(internet service providers) are the companies that provide access to the internet.
Internet is a collection of LAN (local area network for a smaller range i.e., small office), MAN(metropolitan area network for a long-range i.e., across the city), and WAN(wide area network for a very long range, i.e. across countries). Frame relay is a type of technology, that helps you connect LANs with WAN.
The computers on the internet communicate with each other using IP addresses. Routers are used to route our data based on IP address.
Topology:
The way in which computers are connected in the network is known as topology.

Types of Topologies:
- Bus Topology: All computers/nodes are connected to the backbone(bus). Cons: 1. If the bus is broken, it spoils the entire network, 2. Only one person can send data at a time.
- Ring Topology: Each computer/node is connected to another computer/node to form a ring. Cons: 1. If one cable breaks, the entire network is broken, 2. Have to make a lot of unnecessary calls
- Star Topology: All computers/nodes are connected to the central network hub. Cons: 1. If the central network fails, the network is broken.
- Tree Topology: It’s a combination of a bus and a star. Pros: 1. Gives more fault tolerance. Cons: 1. If the bus breaks, the entire network is not broken, but still it impacts the network.
- Mesh Topology: Every computer/node is connected to every other computer/node. Cons:1. Very expensive,2. Difficult to scale.
Architecture:
- Client-server architecture: Here, you have 2 parts: 1. Client part 2. Server part. A computer can either be a client or a server. These parts are known as processes as they communicate with each other. If you want to host on your own server, you must have a reliable IP address that can be reached by any client. Every company has a lot of servers.

Ping: It measures the round-trip time for the destination from the host. Ping is used to test the reachability of the host and check if we can accept requests on an IP network by sending the echo and waiting for it back. It gives the TTL (time to live), IP address, ICMP sequence number (to reassemble), and data chunk size. Can we reduce the ping time? No, because we always get the best possible time.
TTL: It is used in the network layer, after hopping over various routers, even if your packet does not reach its destination after TTL, the packet is dropped.
REST: REST stands for representational state transfer. It follows a client-server architecture.
2.Peer-to-peer architecture: Here, you will not have a dedicated client or server. Every computer can serve as both client and server.

Networking Models:
There are two types of standards: 1. OSI model 2. TCP/IP model.
i.OSI Model: It’s the open system interconnection model. It has 7 layers.
- Application Layer: All applications reside here. The user interacts with the application. Applications such as web browsers, and the WhatsApp messenger app. HTTP, FTP, TELNET, etc are the protocols of this layer.
- Presentation Layer: Data from the application layer is sent to the presentation layer. This data is converted to 0s and 1s. Data is then encrypted so that only the person who sent data can read it. Data is also compressed.
- Session Layer: Setting up of connections, management of connections, and termination of connections take place in this layer. Before the session is established it will do some authentication and authorization. The session is created between the website and your computer.
- Transport Layer: TCP and UDP are protocols of this layer. 3 things happen in this layer. 1) Segmentation: Data received from the transport layer is divided into small parts known as segments. Every segment will contain source port no., destination port no., and sequence number (helps to reassemble segments in correct order). 2) Flow Control: Controls the amount of data that is transported, in terms of speed. 3)Error Control: For the data packets that are lost or corrupted data.
- Network Layer: It assigns IP addresses to every segment and it forms IP packets. This is where the router lives. Routing and load balancing happens in this layer. Every packet received from the network layer will have 3 things, 1. Sender IP address, 2. Receiver’s IP address and 3. Subnet mask.
- Data Link Layer: The data link layer provides a data transfer link between two directly connected nodes/computers. It has 2 sub-layers: The medium access control (MAC) layer – controls how devices in a network gain access to a medium to transmit data. Logical link control (LLC) layer – identifies network layer protocols, and controls error checking and frame synchronization.
- Physical Layer: The transfer of data happens over a physical link. Ethernet is a technology for a physical connection between devices using cables and adapters. For a wireless connection between devices, we can use Bluetooth or wi-fi.

ii. TCP/IP model: It is the same as OSI but has only 5 layers. This model is used widely.
- Application layer 2. Transport Layer 3. Network Layer 4. Data Link layer 5. Physical Layer
Protocols:
Protocols In Application Layer:
- HTTP(web protocol): Hypertext transfer protocol with port no.80. It’s a client-server protocol. This is an application layer protocol. This protocol tells us how to make a request to the server, such a request (the client making a request to the server) is called an HTTP Request. It also tells us how the server sends a response to the client, such a response is known as HTTP Response. HTTP is a stateless protocol, meaning the server does not store any information about the client. It uses the HTTP methods to specify the action that the server is to perform.
HTTP Methods:
- Get Method: It’s the reading part of CRUD operations. To read(get) the data from the server.
- Post Method: It’s the creative part of CRUD. To Create new data(resources) on the server.
- Put Method: It’s the update part of CRUD. To update data(resources) on the server.
- Delete Method: It’s the delete part of CRUD. To delete data from the server.
- Patch Method: It’s used to modify the resource on the server.
- Options Method: To know the options of resources present on the server.
Note: All these methods are idempotent (methods that do not respond differently even if you call them multiple times) except post and patch.
Status Codes: When you send a request to the server, you need some way to make sure the request is successful. This is done by Status Codes. Format of status codes: 1xx->Informational Category codes,2xx->success,3xx->redirecting, 4xx->client error, 5xx->server error.
Cookies: It is a unique string stored on the client browser. When first time you send a request to the server, the cookie is set by the server and saved in the browser. After that whenever you make a new request to the server, in the request header a new cookie is sent. Sometimes, cookies can be used to track you.
2.Email Protocols: i. SMTP (simple mail transfer protocol) for sending the email.
Ii.POP3 (post office protocol) for receiving the email. Port no. 101. The client connects to the server using authorization and then receives the emails from the server.
iii. IMAP (internet mail access protocol) to view your emails on multiple devices, you can sync all the emails. An email will use TCP in the transport layer, as the data must not get corrupted.
The sender of the email will send the email to the sender’s SMTP server. This server will make a connection with the receiver’s SMTP server. When the receiver logs in, the emails are downloaded. Here, if both sender and the receiver use the same email service(eg., Gmail) then no need to connect to the receiver’s SMTP server.
3.DNS protocol: Domain name system. There are so many URLs, will one database be sufficient to store all of them? No, the domain is divided into various classes. For example, in google.com, .com(commercial) is the top-level domain (it’s the first point of contact). Google is the second-level domain. ICANN.org maintains all these top-level domains.

When you type google.com how does it connect to google server? First, the local cache of the browser is searched to find the IP address, if it does exist then it will look in the local DNS server. If not found, it checks the root server. If not found in the root server, will check the top-level domain.
4.RIP: It’s the routing information protocol. This is a dynamic routing protocol. It makes use of hop count as its primary metric to find the best path between the source and destination. RIP uses the User Datagram Protocol (UDP) as its transport protocol, and is assigned the reserved port number 520.
Transport Layer:
Here the chunks of data are called segments. The role of the transport layer is to send data from the network layer to the application layer within your computer. Various types of data, such as text, photos, and videos, are received from the application layer to the transport layer. This layer uses multiplexers and demultiplexers to bundle the data which is sent to the network layer and application layer respectively. Now how will the transport layer know, which application to send the data to? After demultiplexing the data received from the network layer, the data is sent to various sockets via port numbers (which help to recognize the application).
Protocols In Transport Layer:
1.TCP: It’s the transmission control protocol. It’s a connection-oriented protocol, which is slow but secure as it waits for the acknowledgment of each data packet sent. First, the connection has to be established only then we can send data. TCP provides us with error control and congestion control.
Each segment will have a header, which contains, source port no., destination port no., checksum, length of data, sequence no., acknowledgment no. The data is attached to this header and sent.
3-way Handshake: The connection between two computers is established in the TCP using a 3-way handshake. In this process, first, the client sends the request with the synchronization flag + sequence no. to the server. In response, the server will send acknowledgment no. + sequence no. Finally, the client sends acknowledgment no. + synchronization flag.
Congestion Control: Let’s say, the bandwidth of the network layer is lower than your bandwidth, then some of the data packets are lost, this is known as congestion. It happens in both the transport layer and network layer. The transport layer uses congestion control algorithms that are built in TCP. Sometimes, data is lost or corrupted or data packets are not in order, to deal with this situation transport layer uses a checksum. While sending data, the checksum is calculated and attached to the data to be sent. On the receiving side, the checksum is recalculated, if both the checksums are the same, then data is not corrupted.

If data packets over the network are lost due to congestion or any other reason, then how will it be rectified? The sender uses timers. While sending data, the timer is started, if the receiver doesn’t send the acknowledgment within the time frame, the sender sends another data packet. Sometimes, the receiver could receive more than one duplicate segment, to solve this issue, the receiver uses sequence numbers (unique identification numbers) to reassemble the segments received from the network layer.
2.UDP: It’s the user datagram protocol. It’s a connectionless protocol, which is fast but not secure, as it doesn’t use acknowledgment. Data could get corrupted. Used by video conferencing apps and gaming apps. No need to establish a connection, before the transmission of data. Each segment header has the source port no., destination port no., length of the segment, and checksum. The data is attached to this header. The segment header is 8 bytes. The total size of data in each segment is 65,000 bytes.
Network Layer:
In this layer, the router resides and routes the data. Every single router in the network layer has its network address and a routing table that has a destination address. The routing table consists of the forwarding table. The router on receiving the packet will check its forwarding table, it hops the packet to the next router. This hopping routers to routers till it reaches the correct router is known as hop-by-hop forwarding. The routing table may have multiple paths. There are two types of routing:
1. Static routing: the network address is added manually.
2. Dynamic routing: whenever the network changes, the network addresses are changed/added
dynamically.
Protocols in Network Layer:
1.IP: It’s the internet protocol. It is of 2 versions. IPv4 (uses 32-bit for IP address) and IPv6(uses 128-bit for IP address). In IPv4, the first 3 words are the network address (which network your device resides in) of the device, also known as subnet IP and the last word is the device address. Instead of hoping on your routers, the hoping takes place over ISP. It has blocks of IP addresses and these blocks of IP addresses are assigned ISP. This is known as subnetting. Whenever the router will forward a packet, it should know the subnet of the destination. Subnet Masking: Mask the subnet part of the IP address and it leaves us to choose the host part. IPv4 Reserved Address: The first 8-bits of IPv4 are reserved, such addresses are known as loopback addresses. These are needed to make sure that, your device will act both as a client and server. Eg., Localhost which is used both as a client and server with IP address, 127.0.0.1. Advantages of IPv6: It resolves the issue of shortage of IP addresses. Disadvantages of IPv6: 1. Not backward compatible, meaning, if your device is configured to IPv4 it cannot access devices configured with IPv6. 2. Lot of effort to shift to IPv6, lot of hardware work to shift ISPs. IP header: Apart from data, it is 20 bytes. It consists of the IP version, length of data, identification no., flags, protocols, checksum, TTL, etc.
Data-Link Layer:
It is responsible to send the packets it received from the network layer over a physical link. In a network, when we connect ISP to the router which in turn is connected to various devices, these devices have the local IP address and ISP has the global IP address. One device will communicate with another using frame in the data-link layer. Each frame contains the data link address of the sender and the IP address of the destination. The data link layer also does the flow control and error control.

The data link address is known as the MAC address of your device. MAC address is unique not to every device but every component. This 12-bit MAC(media access control) address is used to identify a particular network interface. This layer works very closely with the physical layer(hardware).
Protocols of Data-link Layer:
1.DHCP: Its dynamic host configuration protocol. Whenever you want to add a new device to the router, the new device is connected to the DHCP server (which has a pool of IP addresses). It allocates the local IP address. At the data link layer, the devices communicate with each other using the data link layer address.

2.ARP: Its address resolution protocol. In a LAN, whenever one device wants to communicate with another device, it first checks the ARP cache.
Firewalls:
We can use firewalls both in the network layer and in the transport layer. There are 2 types of firewalls, one that is connected to the global internet and the other one that is connected to your trusted network. They filter out IP packets(meaning control the network traffic) based on addresses, port nos., flags, and protocols. Firewalls can be both hardware or software or both.

NAT:
It’s network address translation. NAT is used by the routers in the network layer. It’s a method of mapping one IP address space into another by modifying network address information in the IP header of packets(meaning we are remapping one IP address space with another IP address space). NAT is used to slow down the IP address of the location.
