How Two Node Communicate To Eachother
A host is basically a computer in a network.
On internal network
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 ofHost B
(10.1.1.33
)- Maybe the user give to it (i.e
ping
) - Maybe DNS (Domain Name System) Protocol
- Maybe the user give to it (i.e
Host A
will know that10.1.1.33
is in the same IP network. It knows by calculating its IP address and the Subnet Mask to see if10.1.1.33
is within the same network- Since
Host A
knowsHost B
ip address, it will create aLayer 3 Header
:src: 10.1.1.22
dst: 10.1.1.33
- Since
Layer3
cannot communicate over the wired,Host A
needs to add aLayer 2 Header
. HoweverHost A
does not knowHost B
mac address. - Therefore
Host A
will use ARP (Address Resolution Protocol) to find out the MAC address ofHost B
.- 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
anda2a2
- Which has the IP address it's looking for:
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.
Host B
will prepare anARP
response with its MAC addressb3b3
so thatHost A
will know.ARP
is Unicast, so therefore only it only send toHost A
.- It also updated the
ARP
table becauseHost A
already provided its mac address. SoHost B
ARP Table would be10.1.1.22 -> a2a2
- It also updated the
Host A
will then update itsARP
table with:10.1.1.33 -> b3b3
Host A
will then sendData, L3 Header, L2 Header
toHost B
- It shoots out the
- Upons packet arrival at
Host B
it will discardL2 Header
andL3 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 toHost B
, it needs to prepare aL2 Header
. The problem isHost A
needs to know which address to put onL2 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 theHost B
mac address is already in FIB (Forwarding information base) of the switch.
On External network (via router)
- 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 to10.9.9.44
. Based on its subnet information, it knows that this IP address is not in the same network.Host A
will create aL3
header:src: 10.1.1.22
dst: 10.9.9.44
Host A
then create aL2
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 for10.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
andIP 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)
- It will send the
Host A
then store routerARP 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 prepareLayer 2
header:src: a2a2
dst: e5e5
Host A
then sendData, L3 Header, L2 Header
toRouter
- Upons receiving,
Router
will discardL2 Header
- Router will add a different
L2 Header
to reach to the next Hop orHost C
.