How Two Node Communicate To Eachother

A host is basically a computer in a network.

On internal network

Pasted image 20240908225247.png

Pasted image 20240910230708.png

Note: In this example there will be multiple router or different devices in between. It doesn't matter, the process will be the same

There are a few key things

  • Both host will have a NIC (Network interface card) which will have the MAC address
  • Both host are configured with IP address and a subnet mask
    • Subnet Mask is to identifies the size of the IP network
  • Host A will know the IP address of Host B (10.1.1.33)
  • Host A will know that 10.1.1.33 is in the same IP network. It knows by calculating its IP address and the Subnet Mask to see if 10.1.1.33 is within the same network
  • Since Host A knows Host B ip address, it will create a Layer 3 Header:
    • src: 10.1.1.22
    • dst: 10.1.1.33
  • Since Layer3 cannot communicate over the wired, Host A needs to add a Layer 2 Header. However Host A does not know Host B mac address.
  • Therefore Host A will use ARP (Address Resolution Protocol) to find out the MAC address of Host B.
    1. It shoots out the ARP request (Layer 2).
      • Which has the IP address it's looking for: 10.1.1.33
      • Host A IP address and Mac address: 10.1.1.22 and a2a2
    2. ARP request is sent as a Broadcast via Broadcast address.
      • This will send the packet to everyone on the local network
      • This can be go through a switch or a medium that connect all the device together.
    3. Host B will prepare an ARP response with its MAC address b3b3 so that Host A will know. ARP is Unicast, so therefore only it only send to Host A.
      1. It also updated the ARP table because Host A already provided its mac address. So Host B ARP Table would be
        • 10.1.1.22 -> a2a2
    4. Host A will then update its ARP table with:
      • 10.1.1.33 -> b3b3
    5. Host A will then send Data, L3 Header, L2 Header to Host B
  • Upons packet arrival at Host B it will discard L2 Header and L3 Header as it becomes unnecessary data now.

Note: Based on Network Switch > How switch works (L2 switch example), would the switch already have MAC table which should already have Host B MAC address? Why does ARP needed.

  • When Host A need to send a packet to Host B, it needs to prepare a L2 Header. The problem is Host A needs to know which address to put on L2 Header since the L2 switch only reads L2 Header.
  • Since it doesn't know what to put, it needs to send an ARP request even though the Host B mac address is already in FIB (Forwarding information base) of the switch.

On External network (via router)

Pasted image 20240908231828.png

  • Everything with an IP address will have an ARP cache, which includes:
    • Host A,
    • Router
    • Host C
  • Host A has the ip address it wants to speak to 10.9.9.44. Based on its subnet information, it knows that this IP address is not in the same network.
  • Host A will create a L3 header:
    • src: 10.1.1.22
    • dst: 10.9.9.44
  • Host A then create a L2 header, the purpose of this is for us to deliver the packet from Hop to hop
    • Since this packet goes outside of the network, the next hop should be the router.
  • Since Host A, ARP table is empty, it doesn't know the MAC address of the router.
    • It will send the ARP request looking for 10.1.1.1, it knows this IP because of it's configured Default Gateway
    • This will go through the Broadcast address and the Router will respond with its MAC address and IP Address (e5e5, 10.1.1.1).
    • At this point the router also will save its IP address into its ARP Table as well (following the exact same process in On internal network)
  • Host A then store router ARP entry:
    • 10.1.1.1 -> e5e5
    • Note: this ARP entry will be reuse whenever Host A wants to talk to external network
  • Host A then can prepare Layer 2 header:
    • src: a2a2
    • dst: e5e5
  • Host A then send Data, L3 Header, L2 Header to Router
  • Upons receiving, Router will discard L2 Header
  • Router will add a different L2 Header to reach to the next Hop or Host C.