# Introduction To Network 🌐

## # <mark style="color:red;">Table of content</mark>

* [What is network?](#what-is-network)
* [What is packet switching network](#what-is-packet-switching-network-psn)
  * [<mark style="color:blue;">Transmission Control Protocol (TCP)</mark>](#transmission-control-protocol-tcp-1)
  * [<mark style="color:blue;">The Internet Protocol (IP)</mark>](#the-internet-protocol-ip)
* [What is Domain Name System (**DNS)**](#what-is-domain-name-system-dns)
* [DNS Servers Types](#dns-servers-types)
* [What is DNS Records?](#what-is-dns-records)
* [What is Static & Dynamic Websites ](#what-is-static-and-dynamic-websites)
* [What is HTTP Protocol and how it work?](#what-is-http-protocol-and-how-it-work)

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

### <mark style="color:purple;">What is Network?</mark>

* A network consists of two or more computers that are linked in order to share resources (such as printers and CDs), exchange files, or allow electronic communications. The computers on a network may be linked through cables, telephone lines, radio waves, satellites, or infrared light beams.

### <mark style="color:purple;">What is Packet switching Network(PSN)</mark>

* It is a method of grouping data into short messages or small segments in fixed format (**packets***) ,* that are transmitted over a digital network.
* This is the first method that used to transmit data over network and they want a unified way to transfer data so they invented the **TCP/*****IP*** Protocol.&#x20;

#### <mark style="color:blue;">Transmission Control Protocol (TCP)</mark>

* Is a communications standard that enables application programs and computing devices to exchange messages over a network. It is designed to send packets across the internet and ensure the successful delivery of data and messages over networks.

#### <mark style="color:blue;">The Internet Protocol (IP)</mark>

* Is the method for sending data from one device to another across the internet. Every device has an IP address that uniquely identifies it and enables it to communicate with and exchange data with other devices connected to the internet.
* Then another problem occurred, which was remembering the **IPs** of the sites, so **DNS** was created.

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

### <mark style="color:purple;">What is Domain Name System (DNS)</mark>

* Web browsers interact through Internet Protocol (**IP**) addresses. **DNS** translates domain names to IP addresses so browsers can load Internet resources.
* So **DNS** lets users connect to websites using domain names instead of **IP** addresses for ease of remembering..

&#x20;Ex:  IP Address              Domain Name

&#x20;  [`172.217.23.206`](< https://www.google.com/>) -> [`https://www.google.com/`](https://www.google.com/)

<div align="center"><figure><img src="/files/rLmfeXUOJdL8X3XAIY3N" alt="" width="375"><figcaption><p><a href="https://hover.blog/whats-a-domain-name-subdomain-top-level-domain/">Domain Name Levels</a></p></figcaption></figure></div>

### <mark style="color:purple;">DNS Servers Types:</mark>

<figure><img src="/files/WG6Mb6a0fAyMTuO0heYI" alt="" width="563"><figcaption><p>DNS Steps For Getting IPs</p></figcaption></figure>

1. <mark style="color:blue;">Recursive resolver:</mark> is the first stop in a DNS query and it responsible for finding domain's IP Address for users. Most Internet users use a recursive resolver provided by their ISP.
2. <mark style="color:blue;">Root nameserver:</mark> <mark style="color:red;">The 13 DNS</mark> root nameservers are known to every recursive resolver, and they are the first stop in a recursive resolver’s quest for DNS records. A  root nameserver is the most important server in DNS services cause it has all the IPs of the TLDs (.com, .net, .org, etc.).
3. <mark style="color:blue;">Top-Level Domain DNS (</mark><mark style="color:blue;">**TLD**</mark><mark style="color:blue;">) nameserver:</mark> A TLD nameserver maintains information for all the domain names that share a common domain extension, such as .com, .net
4. <mark style="color:blue;">Authoritative nameserver:</mark>  usually the resolver’s last step in the journey for an IP address.

### <mark style="color:purple;">What is DNS Records?</mark>

* DNS records (aka zone files) are instructions that live in authoritative DNS servers and provide information about a domain including what IP address is associated with that domain and how to handle requests for that domain. These records consist of a series of text files written in what is known as DNS syntax.&#x20;

* And this is the most common types of DNS record:

  1. <mark style="color:blue;">**A record**</mark> - The record that holds the IPV4 address of a domain.
  2. <mark style="color:blue;">**AAAA record**</mark> - The record that contains the IPv6 address for a domain.
  3. <mark style="color:blue;">**CNAME record**</mark> - Forwards one domain or subdomain to another domain, does NOT provide an IP address.
  4. <mark style="color:blue;">**MX record**</mark> - Directs mail to an email server.
  5. <mark style="color:blue;">**TXT record**</mark> - Lets an admin store text notes in the record. These records are often used for email security.
  6. <mark style="color:blue;">**SOA record**</mark> - Stores admin information about a domain.
  7. <mark style="color:blue;">**NS record**</mark> - Stores the name server for a DNS entry.

* We have some ways to get info about domain that we have:
  1. **`nslookup`**: Tool used to get info about domain like that \ <mark style="color:yellow;">`└─$`</mark><mark style="color:purple;">`nslookup`</mark>`<domain_name>`, and we can specify the record type to get the domain info for this type  like that \ <mark style="color:yellow;">`└─$`</mark><mark style="color:purple;">`nslookup`</mark><mark style="color:green;">`-type=<Record_type>`</mark>`<domain_name>`
  2. **`Dig-Web-Interface`**: Site can give us the same information that we can get from `nslookup`for the domain name.
  3. **`who.is:`** Website used to get the more info like Register info, Important Dates, and Name Servers info for a domain.

ـــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــــ

### <mark style="color:purple;">What is Static & Dynamic Websites ?</mark>

* <mark style="color:blue;">**Static Website**</mark> : is made up of web pages created using HTML, CSS and Javascript and dose not interacted with the user for searching, Logging, etc. It just show information and data for users.
* <mark style="color:blue;">**Dynamic Website**</mark>: Built using server-side language and technology, dynamic websites allow for the content of each page to be delivered and displayed dynamically, according to user behavior or from user-generated content.

### <mark style="color:purple;">What are HTTP and HTTPS protocols?</mark>أ

#### <mark style="color:blue;">**HTTP (Hyper Text Transfer Protocol)**</mark>

1. It used for transferring data over a network. Most information that is sent over the Internet, including website content and API calls, uses the HTTP protocol.&#x20;
2. There are <mark style="color:orange;">two main kinds</mark> of HTTP messages: <mark style="color:green;">**requests**</mark> and <mark style="color:yellow;">**responses**</mark>.
3. **HTTP** protocol use Port <mark style="color:orange;">**80**</mark> by default for connection.
4. **HTTP** protocol use plain text in requests and responses and this make it not secure enough for attacks like: Man-In-The-Middle([**MITM**](https://www.ibm.com/think/topics/man-in-the-middle)) Attacks.&#x20;
5. We usually use **HTTP** Protocol in browsers when we try to open the <mark style="color:orange;">URL</mark> of a specific website
6. This is how user can get the response from specific web server using **HTTP** Protocol.

<figure><img src="/files/8w0JyMBcs0p0OaqQ1Gr0" alt=""><figcaption><p>User Requesting website</p></figcaption></figure>

#### <mark style="color:blue;">**URL (Uniform Resource Locator)**</mark>

1. The address of a unique resource on the internet
2. One of the key mechanisms used by browsers to retrieve published resources, such as HTML pages, CSS documents, images, and so on.
3. The <mark style="color:orange;">**URL**</mark> consists of:&#x20;

   1. &#x20;<mark style="color:green;">**Scheme**</mark>: The first part of the URL, which indicates the protocol that the browser must use to request the resource.
   2. <mark style="color:green;">**Authority**</mark>: The next one after <mark style="color:orange;">**Scheme**</mark> which is separated from the scheme by the character pattern `://`. If present the authority includes both the *domain* (e.g. `www.example.com`) and the *port* (`80`), separated by a colon `:`
      1. <mark style="color:yellow;">**Domain Name**</mark>: Indicates which Web server is being requested
      2. <mark style="color:yellow;">**Port**</mark>: Indicates the technical "gate" used to access the resources on the web server.
   3. <mark style="color:green;">**Path to Resource**</mark>: is the path to the resource on the Web server.
   4. <mark style="color:green;">**Parameters**</mark>: are extra parameters provided to the Web server.  The Web server can use those parameters to do extra stuff before returning the resource.&#x20;
   5. <mark style="color:green;">**Anchor**</mark>:  is an anchor to another part of the resource itself. An anchor represents a sort of "bookmark" inside the resource, giving the browser the directions to show the content located at that "bookmarked" spot.

   <figure><img src="/files/Oxvwlxhc0UwXirmyj14x" alt=""><figcaption></figcaption></figure>

#### <mark style="color:blue;">HTTPS (Hyper Text Transfer Protocol Secure)</mark>

1. It's the same usage of **HTTP** protocol but with security connection&#x20;
2. The S in **HTTPS** stands for "secure."&#x20;
3. **HTTPS** uses <mark style="color:orange;">**TLS**</mark> (or <mark style="color:orange;">**SSL**</mark>) to encrypt **HTTP** requests and responses, instead of the plain text, an attacker would see a bunch of seemingly random characters.

<figure><img src="/files/yZiPbict52QM4puAO177" alt="" width="500"><figcaption><p>HTTP vs HTTPS</p></figcaption></figure>

### <mark style="color:purple;">What does a typical HTTP request look like?</mark>

* An HTTP request is just a series of lines of text that follow the HTTP protocol, and it contain:

  * <mark style="color:green;">**Start Line**</mark>: The first line in the request that will be like this `GET / HTTP/1.1` and contains:&#x20;
    1. The *Request* method (GET, POST, PUT, ..., etc).
    2. &#x20;The *Request* target, usually a URL, or the absolute path of the protocol, and port.
    3. The *HTTP version.*
  * <mark style="color:green;">**HTTP Headers**</mark>: A case-insensitive string followed by a colon (`':'`) and a value whose structure depends upon the header. The whole header, including the value, consists of one single line, which can be quite long.

  <figure><img src="/files/O6F6bVMdd9Yc76An3ObN" alt="" width="522"><figcaption><p>HTTP Headers</p></figcaption></figure>

  * <mark style="color:green;">**Empty Line**</mark>: An empty line to separate between the HTTP Headers and the Body Parts.&#x20;
  * <mark style="color:green;">**Body**</mark>: The last part of a request and contain data that site use it for more actions. Not all requests have one: requests with a `GET` *HTTP method* should only be used to request data and shouldn't contain a body.

* &#x20;A GET request using **curl** command might look like this:

```arduino
GET /hello.txt HTTP/1.1
User-Agent: curl/7.63.0 libcurl/7.63.0 OpenSSL/1.1.l zlib/1.2.11
Host: www.example.com
Accept-Language: en
```

* When an origin server receives an HTTP request, it sends an HTTP response, which is similar:

```
HTTP/1.1 200 OK
Date: Wed, 30 Jan 2019 12:14:39 GMT
Server: Apache
Last-Modified: Mon, 28 Jan 2019 11:17:01 GMT
Accept-Ranges: bytes
Content-Length: 12
Vary: Accept-Encoding
Content-Type: text/plain

Hello World!
```

### <mark style="color:purple;">TCP & UDP</mark>

<figure><img src="/files/OGh7hROekN0iTFwDaBmF" alt=""><figcaption><p>Difference Between TCP and UDP</p></figcaption></figure>

### <mark style="color:purple;">OSI Model</mark>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ziad-sakr.gitbook.io/zima-blog/introduction-to-network.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
