ubuntu:network:arp:about_arp
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
ubuntu:network:arp:about_arp [2020/08/19 16:37] – created 192.168.1.1 | ubuntu:network:arp:about_arp [2021/01/07 09:40] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Network - ARP - About ARP ====== | ||
- | |||
- | Two machines in a network can only communicate with each other if they know each other’s physical address. | ||
- | |||
- | Although computer programs use IP addresses to send and receive messages, the actual underlying communication always happens over the physical address. | ||
- | |||
- | Let’s first understand how communication happens over the wire. Let’s try pinging google' | ||
- | |||
- | <code bash> | ||
- | ping 8.8.8.8 | ||
- | </ | ||
- | |||
- | result: | ||
- | |||
- | <code bash> | ||
- | PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. | ||
- | 64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=15.4 ms | ||
- | 64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=15.3 ms | ||
- | 64 bytes from 8.8.8.8: icmp_seq=3 ttl=58 time=15.2 ms | ||
- | 64 bytes from 8.8.8.8: icmp_seq=4 ttl=58 time=15.2 ms | ||
- | 64 bytes from 8.8.8.8: icmp_seq=5 ttl=58 time=15.2 ms | ||
- | </ | ||
- | |||
- | Now at the same time, as the above ping is working, let's try capturing network packets using another shell session on the same server. | ||
- | |||
- | TCP Dump will be used in this example for capturing network packets but any alternative program can be used instead. | ||
- | |||
- | <code bash> | ||
- | tcpdump -n host 8.8.8.8 | ||
- | </ | ||
- | |||
- | * **-n host 8.8.8.8** will only capture packets where either the source or the destination is 8.8.8.8 (Also it will show IP addresses in the output rather than DNS names). | ||
- | |||
- | result: | ||
- | |||
- | <code bash> | ||
- | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode | ||
- | listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes | ||
- | 21: | ||
- | 21: | ||
- | 21: | ||
- | 21: | ||
- | </ | ||
- | |||
- | |||
- | The output of tcpdump command is pretty straight forward. | ||
- | |||
- | It shows a continues series of ICMP echo requests going out from our server (indicated by 10.12.2.73), | ||
- | |||
- | As 8.8.8.8 is not in the same network, the local server cannot reach there directly without a gateway. | ||
- | |||
- | <code bash> | ||
- | route -n | ||
- | </ | ||
- | |||
- | result: | ||
- | |||
- | <code bash> | ||
- | Kernel IP routing table | ||
- | Destination | ||
- | 0.0.0.0 | ||
- | 10.12.2.0 | ||
- | </ | ||
- | |||
- | Our gateway here is 10.12.2.1. | ||
- | |||
- | So even if we need to reach 8.8.8.8, we need to go via 10.12.2.1 (as it is our gateway). | ||
- | |||
- | <WRAP notice> | ||
- | Tcpdump is showing that the source address is 10.12.2.73 and destination is 8.8.8.8. | ||
- | |||
- | As 8.8.8.8 is not part of our local network, we will have to go via our gateway address of 10.12.2.1. | ||
- | |||
- | So somewhere the destination address should be 10.12.2.1 right? | ||
- | |||
- | Our ping is working perfectly. | ||
- | |||
- | This is exactly where physical addresses (MAC Addresses) steps in. | ||
- | </ | ||
- | |||
- | As the ping to 8.8.8.8 is going on, lets execute tcpdump on another session once again (this time with an additional option **-e**.) | ||
- | |||
- | <code bash> | ||
- | tcpdump -e -n host 8.8.8.8 | ||
- | </ | ||
- | |||
- | Result | ||
- | |||
- | <code bash> | ||
- | tcpdump: verbose output suppressed, use -v or -vv for full protocol decode | ||
- | listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes | ||
- | 21: | ||
- | 21: | ||
- | 21: | ||
- | 21: | ||
- | </ | ||
- | |||
- | This time along with the IP addresses, we are able to see physical addresses (mac addresses) as well in the output. | ||
- | |||
- | <code bash> | ||
- | ifconfig eth0 | ||
- | </ | ||
- | |||
- | Result | ||
- | |||
- | <code bash> | ||
- | eth0 Link encap: | ||
- | inet addr: | ||
- | inet6 addr: fe80:: | ||
- | UP BROADCAST RUNNING MULTICAST | ||
- | RX packets: | ||
- | TX packets: | ||
- | collisions: | ||
- | RX bytes: | ||
- | </ | ||
- | |||
- | From the above ifconfig command output, we can confirm that 12: | ||
- | |||
- | But what is 12: | ||
- | |||
- | <code bash> | ||
- | arp -n -a | ||
- | </ | ||
- | |||
- | Result | ||
- | |||
- | <code bash> | ||
- | ? (10.12.2.40) at 12: | ||
- | ? (172.17.0.2) at 02: | ||
- | ? (10.12.2.43) at 12: | ||
- | ? (10.12.2.8) at 12: | ||
- | ? (10.12.2.94) at 12: | ||
- | ? (10.12.2.1) at 12: | ||
- | </ | ||
- | |||
- | 12: | ||
- | |||
- | MAC addresses (Physical addresses) are part of layer 2. IP addresses are part of layer 3 (source address). | ||
- | |||
- | This is how the packet travels and reaches its final destination of 8.8.8.8. | ||
- | |||
- | The bottom line is...If you want to reach a particular destination IP address, the system will be doing a translation of that IP address to equivalent mac address. | ||
- | |||
- | {{: | ||
- | |||
- | Above shown diagram explains how a computer finds out the mac address associated with an IP address using Address Resolution Protocol. | ||
- | |||
- | This ARP request is a broadcast request. | ||
- | |||
- | Although every computer in the network recieves that request. | ||
- | |||
- | While responding back, it will send its own mac address. | ||
- | |||
- | * ARP Cache: After finding the MAC address associated with an IP, the computer stores it in a table for future reference. | ||
- | * ARP Cache Timeout: The entries added to ARP table for future reference will be valid for a specified amount of time. This indicates that time. | ||
- | * ARP Request: We already saw that above. Its the broadcast request send by a computer to find out the mac associated with an IP address. | ||
- | * ARP Response: As shown in the above diagram, this is the response from the destination host, containing both IP and MAC. | ||
- | |||
ubuntu/network/arp/about_arp.1597855031.txt.gz · Last modified: 2020/08/19 16:37 by 192.168.1.1