# Networking #### The topics to be prepared for the technical phone interview. ## Difference between Router & Switch #### Switch: ##### &nbsp; 1. Typically belongs to L2. ##### &nbsp; 2. An LAN consist of switches. ##### &nbsp; 3. Just forwards packets according MAC address. #### Router: ##### &nbsp; 1. Typically belongs to L3. ##### &nbsp; 2. Focus on Routing amongs networks. ##### &nbsp; 3. Separate the broadcast domain. ##### &nbsp; 4. Transmit packets according IP address. ##### &nbsp; 5. Discard broadcast packets. <br/> ## What is a Broadcast Domain? ##### &nbsp; The zone that the broadcast packets could reach is a broadcast domain. ##### &nbsp; Typically, The devices connected by the same switch belong to the same broadcast domain. ##### &nbsp; The different broadcast domains could be separated by the different ports of the router. <br/> ## DHCP DORA process #### DHCP: ##### &nbsp; IP address could be divided into Public and Private IP address. ##### &nbsp; In LAN, we usually use private IP addresses due to the space of IP addresses of IPv4 is not enough. ##### &nbsp; And that private IP address is provided by DHCP. #### DORA: <br/> #### ・Discover ![](https://i.imgur.com/Rb04SpE.png) ##### &nbsp;&nbsp;&nbsp; 1. Client discover DHCP server. ##### &nbsp;&nbsp;&nbsp; 2. Discover message always broadcast at the network and data link layer. #### ・Offer ![](https://i.imgur.com/QtiESpj.png) ##### &nbsp;&nbsp;&nbsp; 1. Broadcast at Network Layer, Unicast at Data Link Layer. ##### &nbsp;&nbsp;&nbsp; 2. The client didn’t get an IP address yet from DHCP Server. #### ・Request ![](https://i.imgur.com/JkBl0de.png) ##### &nbsp;&nbsp;&nbsp; 1. Broadcast at Network Layer, Unicast at Data Link Layer. (same as DHCP Offer) ##### &nbsp;&nbsp;&nbsp; 2. The client might have received Offer from more than one DHCP server in their domain. ##### &nbsp;&nbsp;&nbsp; 3. So that broadcast is because to notify another server to release these IP they assigned. #### ・Acknowledge ![](https://i.imgur.com/Sbn5Seg.png) ##### &nbsp;&nbsp;&nbsp; 1. Broadcast at Network Layer, Unicast at Data Link Layer. (same as DHCP Offer) ##### &nbsp;&nbsp;&nbsp; 2. After this message, the DHCP client will get an IP address. <br/> ## DNS – detailed explanation. TCP/UDP and why? ![](https://i.imgur.com/mAdCpSA.png) #### &nbsp; 1. Resolve domain name to IP address #### &nbsp; 2. Typically has ***MASTER*** and ***SLAVE*** dns server. #### &nbsp; 3. SLAVE DNS server has to copy the contents from MASTER DNS server when it was lunched, it's called zone transfer and use TCP. Because the contents size are always larger than a single request. #### &nbsp; 4. Others situations used UDP so that can avoid 3-way handshake or other overhead. <br/> ## Subnetting #### &nbsp; To avoid the unnecessary packets that exist within a LAN. <br/> ## MSS/MTU #### MTU (Maxitum Transmission Unit) ##### &nbsp; 1. It's called MTU that the limited frame size among routers. Because the size of the frame is not unlimited when transmission. ##### &nbsp; 2. If there is a packet size larger than MTU, then it needs to be segmented. #### MSS (Maxitum Segment Size) ##### &nbsp; 1. The max packet's payload size that could be transmitted. ##### &nbsp; 2. The final MSS between sender & receiver = min{ MTU of both side } - 40 ##### &nbsp; *//40 = IP header + TCP header* <br/> ## Complete flow when you trigger amazon.com #### same as question: DNS – detailed explanation. <br/> ## OSI model with complete details and protocols on each layer. #### &nbsp; Application: DHCP, HTTP, FTP, SSH #### &nbsp; Presentation: Encryptions and Compression (ex. JPEG or PNG) #### &nbsp; Session: Socket #### &nbsp; Transport: TCP, UDP, SCTP #### &nbsp; Network: ICMP, IP, IPSec #### &nbsp; Data Link: ARP, PPP, PPPoE #### &nbsp; Physical: Fiber, Wireless <br/> ## TCP and SSL handshake #### &nbsp; TCP: Three-way handshake #### &nbsp; SSL: Establish after TCP handshake. ![](https://i.imgur.com/74ZUsZZ.png) #### &nbsp; 1. Authentication: 1~5 //step 4 is optional #### &nbsp; 2. Key Exchange: Typically uses Diffie-Hellman algorithm #### &nbsp; 3. Encrypted Data Transfer (Record): Provide confidentiality & integrity <br/> ## Difference between TCP/UDP, examples ![](https://i.imgur.com/M5Kx3SB.png) ###### &nbsp; *ref: https://www.guru99.com/tcp-vs-udp-understanding-the-difference.html* ![](https://i.imgur.com/6kmAD2i.png) ###### &nbsp; *ref: https://www.homenethowto.com/ports-and-nat/udp-and-tcp-two-ways-of-sending-traffic/* <br/> ## Flow/Error control #### **Flow control** ##### &nbsp; Flow control tells the sender how much data should be sent to the receiver so that it is not lost. ##### **・Stop and Wait Protocol** ##### **・Sliding Window Protocol** #### **Error control** ##### ・**Error Detection** ##### &nbsp;&nbsp;&nbsp; 1. CRC (Circular Redundancy Check) ##### &nbsp;&nbsp;&nbsp; 2. Parity Check ##### &nbsp;&nbsp;&nbsp; 3. Checksum ##### ・**Retransmission** ##### &nbsp;&nbsp;&nbsp; 1. Stop-&-Wait ##### &nbsp;&nbsp;&nbsp; 2. Go-back N ##### &nbsp;&nbsp;&nbsp; 3. Selective Repeat <br/> ## What is a firewall, why do you need it? #### What is: ##### &nbsp; It can be software, hardware or both, and it at the middle between Intranet and Internet that can control and check the network event. <br/><br/> &nbsp; It can isolate the network and makes some access control to handle the network events. #### Why do I need: ##### &nbsp; Because with a firewall you can completely prevent unauthorised access to your computers and network. Without it, your network is open to threats. <br/> ## OSI Model ##### &nbsp; The OSI Model (Open Systems Interconnection Model) is a conceptual framework used to describe the functions of a networking system. <br/><br/> &nbsp; The OSI model characterizes computing functions into a universal set of rules and requirements in order to support interoperability between different products and software. <br/> ## What is HTTP Cookie? ##### &nbsp; HTTP is a stateless protocol which means every request is Independent for server, so we can introduce COOKIE in order to remember the client's information. ##### &nbsp; **Cookie** and **Session** is stored at client side and server side respectively. ##### &nbsp; **Session** stores some sensitive data i.e. Login information, information about cart... ##### &nbsp; **Cookie** stores the session ID so that when a client sends a request with a Cookie, the server can find the corresponding client's information based on the session ID. <br/> ## Difference HTTP keepalive and TCP Keepalive? ##### &nbsp; HTTP Keep-alive timeout is mostly controlled by the server. Example, Server says, if you don't send me a request, after 15 seconds of idleness, I will close the connection. <br/><br/> &nbsp; When server closes the connection, the TCP idle timeout is irrelevant, because connection is explicitly being closed. <br/><br/> &nbsp; So in effect, http keep-alive timeout overrides the TCP one. If conneciton is closed for any reason, then client must initiate a new connection to send a new request. <br/><br/> &nbsp; The TCP idle timeout is only in effect if the connection is idle (no data transmitted) and the connection was not closed for any other reason (such as http keep-alive timeout). You can think of it as the default timeout when nothing else closes the connection. ###### &nbsp; *ref:https://devcentral.f5.com/s/question/0D51T00006j2lGH/tcp-keepalive-v-http-keepalive* <br/> ## How HTTP cached work? ###### &nbsp; *ref:https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers#implementation* <br/>