Docsity

Understanding Network Communication: IP Addresses, MAC Addresses, and ARP, Lecture notes of Computer Networks

Partial preview of the text

Download Understanding Network Communication: IP Addresses, MAC Addresses, and ARP and more Lecture notes Computer Networks in PDF only on Docsity!

Network Fundamentals

From Zero to HTTP

One To One

โ— Two machines can talk to each other โ— Each machine has a network interface โ— Network interfaces can be connected directly to each other via network cable โ— Each network interface has a Media Access Control (MAC) address (AKA hardware address) โ— MAC addresses look like this: 50:46:5d:54:94: โ— MAC addresses are globally unique (at least in theory) โ— Data is sent in chunks called โ€˜framesโ€™ โ— Each frame has a source and destination MAC address

Getting Your Network Interface Info

โ–ถ ifconfig enp3s enp3s0 Link encap:Ethernet HWaddr 50:46:5d:54:94: inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255. inet6 addr: fe80::5246:5dff:fe54:9423/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: RX packets:48241295 errors:0 dropped:0 overruns:0 frame: TX packets:24083899 errors:0 dropped:0 overruns:0 carrier: collisions:0 txqueuelen: RX bytes:49741929087 (49.7 GB) TX bytes:2925004440 (2.9 GB)

โ–ถ ip a show dev enp3s 2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 50:46:5d:54:94:23 brd ff:ff:ff:ff:ff:ff inet 192.168.1.30/24 brd 192.168.1.255 scope global enp3s valid_lft forever preferred_lft forever inet6 fe80::5246:5dff:fe54:9423/64 scope link valid_lft forever preferred_lft forever

Is Anybody There?

โ— Machine A wants to talk to Machine B โ— Machine A has IP 192.168.0.1 and MAC aa:aa:aa:aa:aa:aa โ— Machine B has IP 192.168.0.2 and MAC bb:bb:bb:bb:bb:bb โ— Machine A sends a frame like this: โ—‹ Source MAC: aa:aa:aa:aa:aa:aa โ—‹ Destination MAC: ff:ff:ff:ff:ff:ff โ—‹ Data: โ€œWho has 192.168.0.2? Tell 192.168.0.1!โ€ โ— Machine B responds with a frame like this: โ—‹ Source MAC: bb:bb:bb:bb:bb:bb โ—‹ Destination MAC: aa:aa:aa:aa:aa:aa โ—‹ Data: โ€œ192.168.0.2 is at bb:bb:bb:bb:bb:bb!โ€ โ— Both machines store the IPs and corresponding MACs in their Address Resolution Protocol (ARP) cache for future use

The Next Message

โ— Machine A wants to talk to Machine B again โ— This time Machine A can find the MAC address in its ARP cache โ— Machine A sends a frame that looks like this: โ—‹ Source MAC: aa:aa:aa:aa:aa:aa โ—‹ Destination MAC: bb:bb:bb:bb:bb:bb โ—‹ Data: โ€ฆ โ— Inside the data is an IP โ€˜packetโ€™, which looks like this: โ—‹ Source IP: 192.168.0. โ—‹ Destination IP: 192.168.0. โ—‹ Data: โ€ฆ โ— The data in the last slide was actually an ARP Packet โ— Why a MAC and an IP? โ—‹ Machines can have more than one IP addressโ€ฆ And other reasons too

The ARP Cache

More Than Two Machines

โ— More than two machines can be connected to a hub โ— A hub is pretty dumb โ— It just sends everything it receives back out to all ports โ— Machines ignore frames not intended for them so everything is (mostly) fine โ— Everything that worked for two machines works exactly the same way โ— But: โ—‹ Itโ€™s slow (10Mbit, 100Mbit if youโ€™re lucky) โ—‹ You get collisions (machines trying to talk over each other) โ—‹ We can do better

Hubs

Switches

Subnets

โ— Machines can only directly send IP packets to machines on the same network โ— Soooโ€ฆ How do we define what a network (technically a sub-network) is? โ— As well as an IP, each machine has a subnet mask โ—‹ They look like this: 255.255.255. โ— The subnet mask is used in combination with a source and destination IP to decide if they are on the same subnet or not โ— Itโ€™s actually much easier to understand in binary!

CIDR Notation

โ— It gets a little tiresome specifying the IP and the subnet mask โ— You can use Classless Inter-Domain Routing notation instead โ— Count the number of 1s in the subnet mask!

10.0.0.1/255.255.255. 00001010.00000000.00000000.00000001/11111111.11111111.11111111. 10.0.0.1/

Routing

โ— To send a packet to a machine on another subnet the frame is sent to a router โ— A router usually has more than one network interface (and MAC address) โ— A router always has more than one IP address (at least one per subnet) โ— Machine A (subnet one): โ—‹ MAC: aa:aa:aa:aa:aa:aa โ—‹ IP: 192.168.0.1 / 255.255.255. โ— Machine B (subnet two): โ—‹ MAC: bb:bb:bb:bb:bb:bb โ—‹ IP: 192.168.1.1 / 255.255.255. โ— Router (both subnets): โ—‹ MAC1: cc:cc:cc:cc:cc:cc โ—‹ IP1: 192.168.0.254 / 255.255.255. โ—‹ MAC2: dd:dd:dd:dd:dd:dd โ—‹ IP2: 192.168.1.254 / 255.255.255.

A Hop

Multiple Choice

โ— Machine A sent the frame to its default gateway as a last resort โ— It might have had another option in its routing table :

Network Subnet Mask Gateway 0.0.0.0 0.0.0.0 192.168.0. 192.168.1.0 255.255.255.0 192.168.0. 192.168.2.0 255.255.255.0 192.168.0.

โ— With this table the MAC for 192.168.0.253 would have been the destination โ— Multiple networks connected via routers form what we call the internet :)