/42Lisboa-lvl_4_netpractice

This project aims to broaden your networking. You will have to configure small-scale networks. To do so, it will be necessary to under- stand how TCP/IP addressing works.

Primary LanguageJavaScript

Recent Update on 05/05/2022.

• Finished the project.

Old Update on 03/05/2022.

• Started the project.

Subject:

You can find the subject of this project here.

How to run:

First download the repository.

On the folder /extras/net_practice, grab the index.html and drop it on your browser.
There just insert your name, follow the instructions and click start.

Answers:

Level 1:
Level 2:
Level 3:
Level 4:
Level 5:
Level 6:
Level 7:
Level 8:
Level 9:
Level 10:

Useful Links:

IP
TCP/IP
NetMask
What is a network switch? | Switch vs. router

Research:

Network:

A network, in computing, is a group of two or more devices or nodes that can communicate.
The devices or nodes in question can be connected by physical or wireless connections.
The key is that there are at least two separate components, and they are connected.

The scale of a network can range from a single pair of devices or nodes sending data
back and forth, to massive data centers and even the global Internet, the largest network
in existence. What all of these networks have in common, from the smallest ones to the
largest, is that they allow computers and/or users to share information and resources.

An IP address has two parts—-one part identifies the host, such as a computer or other
device. And the other part identifies the network it belongs to. TCP/IP uses a subnet mask
to separate them.

Networks may be used for:

	- Communications such as email, instant messaging, chat rooms, etc.
	- Shared hardware such as printers and input devices.
	- Shared data and information through the use of shared storage devices.
	- Shared software, which is achieved by running applications on remote computers.

Internet, Intranet and Extranet:

Each describes a different type of network, and while they all sound similar, they have
vastly different security implications and business uses.

The internet is a global collection of computer networks known as the world wide web.
On the other hand, an intranet is an online network only company employees can access.
An extranet is an extension of an intranet. It lets approved third parties (such as
vendors or customers) access restricted information.

The internet is the most expansive of the three networks. It creates connections between
computers around the world.

An intranet is a local network that only people within the organization can access. It’s
the most restricted network of the three.

Extranets fall in the middle since they allow for some connections outside of the company,
but they’re not available to the public.

Internet Protocol(IP)

What is an IP Address?

	An IP address is a unique address that identifies a device on the internet or
	a local network. IP stands for "Internet Protocol," which is the set of rules
	governing the format of data sent via the internet or local network.

	In essence, IP addresses are the identifier that allows information to be sent
	between devices on a network: they contain location information and make devices
	accessible for communication. The internet needs a way to differentiate between
	different computers, routers, and websites. IP addresses provide a way of doing
	so and form an essential part of how the internet works.

	An IP address is a string of numbers separated by periods. IP addresses are expressed
	as a set of four numbers — an example address might be 192.158.1.38. Each number in
	the set can range from 0 to 255. So, the full IP addressing range goes from 0.0.0.0
	to 255.255.255.255.


How do IP addresses work?

	Internet Protocol works the same way as any other language, by communicating using
	set guidelines to pass information. All devices find, send, and exchange information
	with other connected devices using this protocol. By speaking the same language, any
	computer in any location can talk to one another.

	The process works like this:

		- Your device indirectly connects to the internet by connecting at first to a
		network connected to the internet, which then grants your device access to the
		internet.

		- When you are at home, that network will probably be your Internet Service
		Provider (ISP). At work, it will be your company network.

		- Your IP address is assigned to your device by your ISP.

		- Your internet activity goes through the ISP, and they route it back to you,
		using your IP address. Since they are giving you access to the internet, it is
		their role to assign an IP address to your device.

		- However, your IP address can change. For example, turning your modem or router
		on or off can change it. Or you can contact your ISP, and they can change it for you.

		- When you are out and about – for example, traveling – and you take your device
		with you, your home IP address does not come with you. This is because you will be
		using another network (Wi-Fi at a hotel, airport, or coffee shop, etc.) to access
		the internet and will be using a different (and temporary) IP address, assigned to
		you by the ISP of the hotel, airport or coffee shop.


Types of IP addresses:

	Every individual or business with an internet service plan will have two types of
	IP addresses: their private IP addresses and their public IP address. The terms public
	and private relate to the network location — that is, a private IP address is used inside
	a network, while a public one is used outside a network.

	Private IPs:

		Every device that connects to your internet network has a private IP address.
		This includes computers, smartphones, and tablets but also any Bluetooth-enabled
		devices like speakers, printers, or smart TVs. With the growing internet of things,
		the number of private IP addresses you have at home is probably growing. Your
		router needs a way to identify these items separately, and many items need a way
		to recognize each other. Therefore, your router generates private IP addresses that
		are unique identifiers for each device that differentiate them on the network.

	Public IP addresses:

		A public IP address is the primary address associated with your whole network.
		While each connected device has its own IP address, they are also included within
		the main IP address for your network. As described above, your public IP address
		is provided to your router by your ISP. Typically, ISPs have a large pool of IP
		addresses that they distribute to their customers. Your public IP address is the
		address that all the devices outside your internet network will use to recognize
		your network.


	Public IP addresses types:

		Public IP addresses come in two forms – dynamic and static.

		Dynamic IP addresses:

			Dynamic IP addresses change automatically and regularly. ISPs buy a large
			pool of IP addresses and assign them automatically to their customers.
			Periodically, they re-assign them and put the older IP addresses back into the
			pool to be used for other customers. The rationale for this approach is to
			generate cost savings for the ISP.

		Static IP addresses:

			In contrast to dynamic IP addresses, static addresses remain consistent.
			Once the network assigns an IP address, it remains the same. Most individuals
			and businesses do not need a static IP address, but for businesses that plan
			to host their own server, it is crucial to have one. This is because a static
			IP address ensures that websites and email addresses tied to it will have
			a consistent IP address

DNS:

DNS, or domain name system, is the phone book of the internet. It translates domain names
that we easily remember, like bluecatnetworks.com, into IP addresses like 104.239.197.100,
which are the language of the internet.

DNS allows computers, servers, and other networked devices, each with their unique IP
addresses, to talk to each other. And it gets users to the website they’re looking for.

TCP:

TCP stands for Transmission Control Protocol 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.

TCP is one of the basic standards that define the rules of the internet and is included
within the standards defined by the Internet Engineering Task Force (IETF). It is one of
the most commonly used protocols within digital network communications and ensures
end-to-end data delivery.

TCP organizes data so that it can be transmitted between a server and a client. It guarantees
the integrity of the data being communicated over a network. Before it transmits data,
TCP establishes a connection between a source and its destination, which it ensures remains
live until communication begins. It then breaks large amounts of data into smaller packets,
while ensuring data integrity is in place throughout the process.

As a result, high-level protocols that need to transmit data all use TCP Protocol.
Examples include peer-to-peer sharing methods like File Transfer Protocol (FTP), Secure
Shell (SSH), and Telnet. It is also used to send and receive email through Internet Message
Access Protocol (IMAP), Post Office Protocol (POP), and Simple Mail Transfer Protocol (SMTP),
and for web access through the Hypertext Transfer Protocol (HTTP).

TCP/IP:

What is TCP/IP?

	TCP/IP stands for Transmission Control Protocol/Internet Protocol and is a suite
	of communication protocols used to interconnect network devices on the internet.
	TCP/IP is also used as a communications protocol in a private computer network (an
	intranet or extranet).

	The entire IP suite -- a set of rules and procedures -- is commonly referred to as
	TCP/IP. TCP and IP are the two main protocols, though others are included in the suite.
	The TCP/IP protocol suite functions as an abstraction layer between internet applications
	and the routing and switching fabric.

	TCP/IP specifies how data is exchanged over the internet by providing end-to-end
	communications that identify how it should be broken into packets, addressed,
	transmitted, routed and received at the destination.



	- TCP defines how applications can create channels of communication across a network. It
	also manages how a message is assembled into smaller packets before they are then
	transmitted over the internet and reassembled in the right order at the destination
	address.

	- IP defines how to address and route each packet to make sure it reaches the right
	destination. Each gateway computer on the network checks this IP address to determine
	where to forward the message.

	- A subnet mask tells a computer, or other network device, what portion of the IP address
	is used to represent the network and what part is used to represent hosts, or other
	computers, on the network.

	- Network address translation (NAT) is the virtualization of IP addresses. NAT helps
	improve security and decrease the number of IP addresses an organization needs.


The 4 layers of the TCP/IP model:

	TCP/IP functionality is divided into four layers, each of which includes specific protocols:

		- The application layer provides applications with standardized data exchange. Its
		protocols include HTTP, FTP, Post Office Protocol 3, Simple Mail Transfer Protocol
		and	Simple Network Management Protocol. At the application layer, the payload is
		the actual application data.

		- The transport layer is responsible for maintaining end-to-end communications across
		the network. TCP handles communications between hosts and provides flow control,
		multiplexing and reliability. The transport protocols include TCP and User Datagram
		Protocol, which is sometimes used instead of TCP for special purposes.

		- The network layer, also called the internet layer, deals with packets and connects
		independent networks to transport the packets across network boundaries. The network
		layer protocols are IP and Internet Control Message Protocol, which is used for error
		reporting.

		- The physical layer, also known as the network interface layer or data link layer,
		consists of protocols that operate only on a link -- the network component that
		interconnects nodes or hosts in the network. The protocols in this lowest layer
		include Ethernet for local area networks and Address Resolution Protocol.

IPv4:

IP (version 4) addresses are 32-bit integers that can be expressed in hexadecimal notation.
The more common format, known as dotted quad or dotted decimal, is x.x.x.x, where each x
can be any value between 0 and 255. For example, 192.0.2.146 is a valid IPv4 address.


Classful Addressing:

	Classful addressing divides the IPv4 address space (0.0.0.0-255.255.255.255) into 5
	classes: A, B, C, D, and E.

	------------------------------------------------------------------------------
	|  Class |  Network Mask  |       IPv4 Address Range      |       Uses		 |
	|--------|----------------|-------------------------------|------------------|
	|	 A   |  255.0.0.0	  |  0.0.0.0   - 127.255.255.255  |  Host Addresses  |
	|	 B   |  255.255.0.0   |  128.0.0.0 - 191.255.255.255  |  Host Addresses  |
	|	 C   |  255.255.255.0 |  192.0.0.0 - 223.255.255.255  |  Host Addresses  |
	|	 D   |                |  224.0.0.0 - 239.255.255.255  |  Multicasting    |
	|	 E   |                |  240.0.0.0 - 255.255.255.255  |  "Future Uses"   |
	------------------------------------------------------------------------------

	First octet determines the class.

		- 100.0.23.5    = class A
		- 243.0.1.1     = class E
		- 132.91.12.255 = class B


	Private IPs:

	--------------------------------------------
	|  Class |         Private IP Range        |
	|--------|---------------------------------|
	|	 A   |  10.0.0.0    - 10.255.255.255   |
	|	 B   |  172.16.0.0  - 172.31.255.255   |
	|	 C   |  192.168.0.0 - 192.168.255.255  |
	--------------------------------------------

	Special IP Addresses:

		IP Range: 127.0.0.1 to 127.255.255.255 are network testing addresses (also referred
		to as loop-back addresses). These are virtual IP address, in that they cannot
		be assigned to a device. Specifically, the IP 127.0.0.1 is often used to troubleshoot
		network connectivity issues using the ping command.


	Classes Creation:

	----------------------------------------------------------------------------------------
	|		    |   8bits    |   8bits    |   8bits    |   8bits    |      Subnet Mask     |
	|-----------|------------|------------|------------|------------|----------------------|
	|  Class A  | Network    | Host       | Host       | Host       | /8 or 255.0.0.0      |
	|  Class B  | Network    | Network    | Host       | Host       | /16 or 255.255.0.0   |
	|  Class C  | Network    | Network    | Network    | Host       | /24 or 255.255.255.0 |
	----------------------------------------------------------------------------------------

Finding the network address:

IP address | 104.198.241.125
Mask       | 255.255.255.128


We convert these to binary

	| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

	IP address | 01101000.11000110.11110001.01111101
	Mask       | 11111111.11111111.11111111.10000000

To find the network address now we have to apply bitwise &

	01101000.11000110.11110001.01111101
	11111111.11111111.11111111.10000000
	-----------------------------------
&	01101000.11000110.11110001.00000000

Which is 104.198.241.0

	Network Address | 104.198.241.0

Finding the range of host addresses:

IP address | 104.198.241.125
Mask       | 255.255.255.128

We convert these to binary

	| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |

	IP address | 01101000.11000110.11110001.01111101
	Mask       | 11111111.11111111.11111111.10000000

We know that the 0's of the Mask, we see it's the last 7 bits.
We do a Bitwise AND of the last 7 bits of the Mask with the IP address.

	IP address       | xxxxxxxx.xxxxxxxx.xxxxxxxx.x1111101
	Mask             | xxxxxxxx.xxxxxxxx.xxxxxxxx.x0000000
	------------------------------------------------------
&	First IP Binary  | xxxxxxxx.xxxxxxxx.xxxxxxxx.x0000000    = 0
	First IP Decimal | 104.198.241.0


For the Last IP we do the inversion of the Mask and the Bitwise OR

	IP address      | xxxxxxxx.xxxxxxxx.xxxxxxxx.x1111101
	Inverted Mask   | xxxxxxxx.xxxxxxxx.xxxxxxxx.x1111111
	----------------------------------------------------
|	Last IP Binary	| xxxxxxxx.xxxxxxxx.xxxxxxxx.x1111111    = 127
	Last IP Decimal | 104.198.241.127

Range goes from 104.198.241.0 - 104.198.241.127

But the extremities are reservered:

	104.198.241.0   | Reserved to represent the network address.
	104.198.241.127 | Reserved as the broadcast address; used to send packets to all
					  hosts of a network.


Usable Host IP Range is:

		104.198.241.1 - 104.198.241.126

Switch:

A network switch connects devices within a network (often a local area network, or LAN)
and forwards data packets to and from those devices. Unlike a router, a switch only sends
data to the single device it is intended for (which may be another switch, a router, or
a user's computer), not to networks of multiple devices.

Router:

Routers select paths for data packets to cross networks and reach their destinations.
Routers do this by connecting with different networks and forwarding data from network
to network — including LANs, wide area networks (WANs), or autonomous systems, which
are the large networks that make up the Internet.

What is the difference between a switch and a router?

In practice, what this means is that routers are necessary for an Internet connection,
while switches are only used for interconnecting devices. Homes and small offices need
routers for Internet access, but most do not need a network switch, unless they require
a large amount of Ethernet ports. However, large offices, networks, and data centers with
dozens or hundreds of computers usually do require switches.

Routing Table:

A routing table is a data table stored in a router or a network host that lists the routes
to particular network destinations.

	Destination: The destination specifies a network address on which a host is the end
	target of the packets. The route of default or 0.0.0.0/0, is the route that takes effect
	when no other route is available for an IP destination address. The default route will
	use the next-hop address to send the packets on their way without giving a specific
	destination. The default route will match any network.

	Next hop: The next hop refers to the next closest router a packet can go through. It
	is the IP address of the next router on the packet's way. Every single router maintains
	its routing table with a next hop address.