Monday, July 2, 2018

Networks Basics

Network topologies:
- bus topology - all devices connected on the same wire
- star/heirarchial topolgy - all devices directly connected to a central physical netwoking device
- mesh topology - each device is directly connected to each device on the network.
- circular topology - each device is connected to two other devices.

Subnettin and subnet masks:
IP addresses are divided into two parts:

<network address><host address>

The 1s in the subnet mask ANDed with the IP address results in the network part of the IP address, and the rest is the host part.

Classful network addresses:
Class A: first bit is 0         (subnet mask of 255:0:0:0)
Class B: first two bits are 10         (subnet mask of 255:255:0:0)
Class C: first three bits are 110    (subnet mask of 255:255:255:0)
Class D: first four bits are 1110    (subnet mask is not defined) -> Used for multicast
Class E: first four bits are 1111    (subnet mask is not defined) -> Usecase is not defined yet

Each network was assigned IPs from a different class which led to a problem. Networks which required more host addresses than a class C network (>255) and less than a class B network (<65535) were assigned class B networks which led to inefficient assignment of the address space.

This led to a new address assignment scheme CIDR "Classless intern-domain routing". Where the subnet masks were no longer restricted to that of Class A.. Class C adress spaces but made more flexible. this allowed for a more efficient assignment of the address space.


Routing at layer 3:
RIP (Routing information protocol): Distance vector protocol, hops are used as the metric. full routinng tables broadcasted
OSFP (open shortest path first): Link state protocol. cost is used as the metric (interface bandwidth is used as the cost). information is forwarded from the source.
EIGRP (Enhanced Intergateway routing protocol). Is a proprietory hybrid protocol used by cisco router.

IGP vs EGP:
IGP (Inter-Gateway Protocol): These include the routing protocols inside the same policy network... (within border gateways)
EGP (External-Gateway protocol): BGP (Border gateway protocol)


Spanning tree algorithm: 
It is an algorithm used to eliminate loops in a layer 2 network. Loops add redundancy, so if a link goes down, there is always another route to take its place.
- One switch is voted as the root switch. (the lowest ID).
- Then it broadcasts BPDU (bridge protocol data units) containing its address and ID.
- All switches that receive that BPDU, broadcast it on all their ports. When a switch receives the same BPDU on two different ports, it will block one depending on which one has the larger sender ID/address. 



Vlans: Virtual LANs, they are logically seperated networks on the same switch. essentially different LAN environments.

trunks: Trunks are ports on switches that can be assigned to more than one VLAN. This enables differnet switches to host the same VLAN. frames from a vlan are encapsulated into a "jacket" before being transmitted over a VLAN to notify the other switch which VLAN the frame belongs to. The standard which defines this is the "802.1q".




Common Protocols in the TCP/IP suite:

TCP:
HTTP (80) - Web applications
HTTPS (443) - Secure HTTP
telnet (23) - Remote shell
SSH (22) - Secure Remote shell


FTP (20,21) - File transfer
SCP (22) - File transfer
SFTP (22) - File transfer


SMTP (25) - Email
IMAP (143) - Email
POP3 (110) - Email

UDP:
DHCP (67-server, 68-client) - DORA (Discover, Offer, Request, Acknoledgment)
DNS (43)
NTP (123)



SNMP (Simple network management protocol, ver 1,2,3 (has agent authentication and encryption)): (Server/Agent). You can control agents using the server (manager) e.g when the agent is at more than 80% CPU unitilization message the server, this is called a trap.
The server can also request for information when the need arises.
It can also write device configurations through the agents.


TCP: Three way handshake [SYN, SYN-ACK, ACK]

Initiation:
Syn ->      - Sender sends a syn and a random sequence number, A
       <- Syn, ACK - Receiver sends a SYN+ACK, with ack number as A+1, and a random sequence number, B
Ack ->        - Sender sends an Ack, with ack number as B+1 and sequence number A+1


Termination:
Fourway handshake:
Fin ->
      <- Ack
      <- Fin
Ack ->

Threeway handshake:
Fin   ->
        <- Fin/Ack
Ack  ->


Half-duplex closing sequence:
Fin -> (recieves some data)
Rst -> (Indicating to the sender that the data was lost)





Some Layer 3 protocols that require QOS marking:
VoIP (Voice over IP) - Packets are marked at layer 3 for QoS
SIP (Session initiation protocol) - Uses TCP
RTP (Realtime transfer protocol) - Uses UDP