Network models · Fundamentals · Module 3
Devices and the layers they work at
Show topologyHide topology
Four devices in a column, joined by three cables. At the top the host H1: its eth0, address ending .10, is cabled to the switch SW1’s Et0/1. SW1’s Et0/0 is cabled to the router R1’s Et0/0, address ending .1. Both of SW1’s cables are one network, 10.0.1.0/24, written on each of them; SW1 itself has no address. R1’s Et0/1, address ending .1, is cabled to the host H2 at the bottom, its eth0 ending .20, in the network 10.0.2.0/24, written on that cable. A legend explains the short forms.
What each device reads
Hub, switch, router, host
H1’s packet for H2 crosses SW1 and R1. Which of them opens which header, and who writes a new frame?
Each device reads only as far as its job needs. A frame carries a packet, with the frame header and its MAC addresses outside and the IP header inside. A device works at the layer of the highest header it reads.
First the frame reaches SW1, which only has to get it to R1. SW1 is a switch, which works at layer 2, the data link layer. It looks at the destination MAC address of the frame and passes the frame out of the port, the switch’s interface, toward the device with that address.
At R1 the packet changes networks. R1 is a router, which works at layer 3, the network layer. It examines the IP header and picks the way out from the destination IP address. Then it removes the frame header it got and puts on a new one for the next network.
At the end, H2 takes the data. H1 and H2 are hosts, where the data is made and used, so a host works up to the application layer (layer 7 in OSI). It typically runs at least one protocol at each TCP/IP layer (Figure 3.2). The device you are reading this on is one.
A hub reads no header, so it works at layer 1, the physical layer. It receives a signal on one port and passes it along to the other ports (Figure 3.1).
Two small drawings side by side, parted by a thin dashed line, the same in each: three hosts, A at the top left, B at the top right and C at the bottom left, each on its own port of a box in the middle. In both, host A sends a frame for host B: a small arrow beside A’s cable points from A into the box. Left, the box is a hub: arrows beside the cables to B and to C point out of it toward both, and the note reads “out of every other port”. Right, the box is a switch: one arrow, in the accent color, beside B’s cable only, points toward B, and the note reads “toward B’s MAC”.
The four devices of the network in their column, joined by three cables: H1, SW1, R1 and H2 from top to bottom. Under each name, the layers it works at: H1 and H2 layers 1 to 7, SW1 layers 1 to 2, R1 layers 1 to 3. Left of each device, what it reads or makes; right of it, under the layers, what it writes or does with the data. H1: makes the data; writes every header. SW1: reads the MAC it goes to; writes no new header. R1: reads the IP it goes to; writes a new frame header, in the accent color. H2: reads every header; takes the data.
From outside, a hub and a switch are both a box with many ports; only the switch reads an address in what it passes on.
The source MAC address of a frame a switch passes on is still the sender’s, not the switch’s.
The destination IP address, in the IP header, is enough to choose the way out; the TCP header behind it is not needed.
One network through a switch, two networks through a router
Why does SW1 have no address in 10.0.1.0/24, when R1 has one on each side?
SW1 joins cables into one network. In the topology, H1 and R1’s Ethernet0/0 are both in 10.0.1.0/24, with SW1 between them. 10.0.1.10 and 10.0.1.1 begin with the same network part, the part the mask marks, and 10.0.2.20 does not.
Inside that network, SW1 passes frames by MAC address, so it needs no IP address, and it has none.
A router is different, because hosts send packets to it. R1 joins 10.0.1.0/24 and 10.0.2.0/24, and a host sends a packet for another network to a gateway, a router in its own network. So H1 must be able to reach R1 at 10.0.1.1. A router needs an address in each network it joins.
Key idea
On SW1, show ip interface brief lists its ports toward R1 and H1 as unassigned and up and up: they work with no IP address.
How it works
One packet from H1 to H2
A packet’s walk from H1 to H2
H1 pings H2. On each of the three cables, which addresses do the frame and the packet carry?
H1 sends H2 one test packet, a ping. H2 is in another network, so H1 sends the packet to its gateway, R1. Each frame header names the sender and the receiver within one network.
R1 can print lines for each packet it passes on, with debug ip packet detail. Packets on its quick path are missed, so no ip route-cache turns that path off on both interfaces. Debugging can affect the router’s performance, so turn it off afterwards with undebug all.
Step 1 of 6
H1 sends a frame from its own MAC address, 5254.0000.0110, to R1’s Ethernet0/0, aabb.cc00.0900. Inside is the packet from 10.0.1.10 to 10.0.2.20.
Step 2 of 6
SW1 reads the frame’s MAC addresses; the destination decides the port. It sends the frame on toward R1 and writes no new frame header: the frame still goes from H1 to R1.
Step 3 of 6
R1 takes the frame: it is for its own MAC address. It removes the frame header, reads the destination IP address, 10.0.2.20, and chooses Ethernet0/1 as the way out.
Which destination MAC address does R1 write in the new frame on H2’s link?
- H2’s MAC address. (Correct): A MAC address works only within its own network. On H2’s link the next device is H2 itself, so R1 writes H2’s MAC address as the new destination.
- R1’s own Ethernet0/0 MAC address, as in the frame it got.: That address named R1 on the first network. R1 replaces the frame header for the next network; keeping the old one would address the frame to R1’s own Ethernet0/0, which is not on H2’s link.
- H1’s MAC address.: H1’s MAC address is the source of the first frame, and only on H1’s network. The new frame goes toward H2.
- None, since R1 sends H1’s frame on as it came.: That is what a switch does, inside one network. A router removes the frame header it got and puts on a new one for the next network.
Step 4 of 6
R1 puts the same packet in a new frame: from its Ethernet0/1, aabb.cc00.0910, to H2, 5254.0000.0220. The IP addresses stay; R1 lowers the TTL, a field of the IP header.
Step 5 of 6
H2 takes the frame, because it is for its MAC address, and the packet, because it is for its IP address.
Step 6 of 6
On every cable the packet kept its IP addresses. The frame header was new after R1. The reply crosses the same devices back, again in a new frame after R1.
The four devices of the network in their column, H1 at the top, then SW1, R1 and H2, joined by three cables. Beside each cable, in turn, a small arrow pointing down shows the frame moving along it. Level with each cable, two tags: left the frame header, right the packet inside it, each as “from → to”. On the first two cables the frame tag reads “frame, H1 → R1”. On the last cable it reads “frame, R1 → H2”, and at that step it is drawn in the accent color. The packet tag reads “packet, 10.0.1.10 → 10.0.2.20” on all three cables. Notes beside the devices say what each does: SW1 “reads the MAC it goes to”, R1 “reads the IP: new frame”, H2 “takes it: its MAC, its IP”. At each step the newest part is drawn in the accent color and earlier parts are dimmed.
Answer here to see step 4, or tap “Skip, show me”.
Three of R1’s lines for H1’s test packet, printed with debug ip packet detail. The number beside each line is the step it belongs to:
Lines appear as you step through.
R1#show logging… 23 more lines (see Full output)3IP: s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (nil), len 84, input feature… 5 more lines (see Full output)3IP: s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (Ethernet0/1), g=10.0.2.20, len 84, forward… 1 more line (see Full output)4IP: s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (Ethernet0/1), len 84, sending full packet… 11 more lines (see Full output)
Full output · 43 lines
R1#show loggingSyslog logging: enabled (0 messages dropped, 2 messages rate-limited, 0 flushes, 0 overruns, xml disabled, filtering disabled) No Active Message Discriminator. No Inactive Message Discriminator. Console logging: disabled Monitor logging: level debugging, 0 messages logged, xml disabled, filtering disabled Buffer logging: level debugging, 74 messages logged, xml disabled, filtering disabled Exception Logging: size (4096 bytes) Count and timestamp logging messages: disabled Persistent logging: disabled Trap logging: level informational, 54 message lines logged Logging Source-Interface: VRF Name: Log Buffer (128000 bytes): Nov 25 21:09:03.290: %SYS-4-LOG_CLEARED: Logging buffer was cleared by user UnknownIP: s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (nil), len 84, input feature ICMP type=8, code=0, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEFIBipv4-packet-proc: route packet from Ethernet0/0 src 10.0.1.10 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (Ethernet0/1), g=10.0.2.20, len 84, forward ICMP type=8, code=0IP: s=10.0.1.10 (Ethernet0/0), d=10.0.2.20 (Ethernet0/1), len 84, sending full packet ICMP type=8, code=0IP: s=10.0.2.20 (Ethernet0/1), d=10.0.1.10 (nil), len 84, input feature ICMP type=0, code=0, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.1.10FIBfwd-proc: packet routed by adj to Ethernet0/0 10.0.1.10FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.20 (Ethernet0/1), d=10.0.1.10 (Ethernet0/0) nexthop=10.0.1.10, routed via FIBIP: s=10.0.2.20 (Ethernet0/1), d=10.0.1.10 (Ethernet0/0), g=10.0.1.10, len 84, forward ICMP type=0, code=0IP: s=10.0.2.20 (Ethernet0/1), d=10.0.1.10 (Ethernet0/0), len 84, sending full packet ICMP type=0, code=0
The first line is the packet arriving on Ethernet0/0. The second is R1’s choice: out of Ethernet0/1, with g=10.0.2.20 as the next hop, the next device it goes to, which is H2 itself. The third, sending full packet, is the packet leaving. Did R1 change the IP addresses? All three read the same s= and d=, 10.0.1.10 and 10.0.2.20, so R1 passed the packet on with the same two IP addresses.
Interface counters show the same path. With the counts on R1’s two interfaces and SW1’s two ports set back to zero, H1 sent H2 5 test packets with ping.
On SW1, its port toward H1, after the pings:
SW1#show interfaces Ethernet0/1Ethernet0/1 is up, line protocol is up (connected) … 15 more lines (see Full output)1 5 packets input, 490 bytes, 0 no buffer… 4 more lines (see Full output)2 5 packets output, 490 bytes, 0 underruns… 6 more lines (see Full output)
- 5 in: H1’s requests.
- 5 out: the replies, back to H1.
Full output · 28 lines
SW1#show interfaces Ethernet0/1Ethernet0/1 is up, line protocol is up (connected) Hardware is Ethernet, address is aabb.cc00.0a10 (bia aabb.cc00.0a10) MTU 1500 bytes, BW 10000 Kbit/sec, DLY 1000 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set Keepalive not set Full-duplex, Auto-speed, media type is 10/100/1000BaseTX input flow-control is off, output flow-control is unsupported ARP type: ARPA, ARP Timeout 04:00:00 Last input 00:00:09, output 00:00:09, output hang never Last clearing of "show interface" counters 00:00:19 Input queue: 0/2000/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) 5 minute input rate 0 bits/sec, 0 packets/sec 5 minute output rate 0 bits/sec, 0 packets/sec 5 packets input, 490 bytes, 0 no buffer Received 0 broadcasts (0 multicasts) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 input packets with dribble condition detected 5 packets output, 490 bytes, 0 underruns Output 0 broadcasts (0 multicasts) 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier 0 output buffer failures, 0 output buffers swapped out
On R1, its interface toward H2, after the same pings:
R1#show interfaces Ethernet0/1Ethernet0/1 is up, line protocol is up … 14 more lines (see Full output)1 5 packets input, 490 bytes, 0 no buffer… 4 more lines (see Full output)2 5 packets output, 490 bytes, 0 underruns… 6 more lines (see Full output)
- 5 in: H2’s replies.
- 5 out: the requests, in new frames for H2.
Full output · 27 lines
R1#show interfaces Ethernet0/1Ethernet0/1 is up, line protocol is up Hardware is AmdP2, address is aabb.cc00.0910 (bia aabb.cc00.0910) Internet address is 10.0.2.1/24 MTU 1500 bytes, BW 10000 Kbit/sec, DLY 1000 usec, reliability 255/255, txload 1/255, rxload 1/255 Encapsulation ARPA, loopback not set Keepalive not set ARP type: ARPA, ARP Timeout 04:00:00 Last input 00:00:09, output 00:00:09, output hang never Last clearing of "show interface" counters 00:00:19 Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0 Queueing strategy: fifo Output queue: 0/40 (size/max) 5 minute input rate 0 bits/sec, 0 packets/sec 5 minute output rate 0 bits/sec, 0 packets/sec 5 packets input, 490 bytes, 0 no buffer Received 0 broadcasts (0 IP multicasts) 0 runts, 0 giants, 0 throttles 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 input packets with dribble condition detected 5 packets output, 490 bytes, 0 underruns Output 0 broadcasts (0 IP multicasts) 0 output errors, 0 collisions, 0 interface resets 0 unknown protocol drops 0 babbles, 0 late collision, 0 deferred 0 lost carrier, 0 no carrier 0 output buffer failures, 0 output buffers swapped out
What changes at the router, and what stays
Put the frame on H1’s cable next to the frame on H2’s cable. What did R1 change?
| Field | On H1’s cable | On H2’s cable |
|---|---|---|
| Destination MAC | R1 Et0/0 | H2 |
| Source MAC | H1 | R1 Et0/1 |
| TTL | as H1 set it | lowered |
| Source IP | 10.0.1.10 | 10.0.1.10 |
| Destination IP | 10.0.2.20 | 10.0.2.20 |
R1 does change the TTL, a field of the IP header. A router that passes a packet on lowers it by at least one, and a packet whose TTL reaches zero is dropped. Because the TTL changed, R1 also works out the header’s checksum again, a check value over the IP header only, which each router checks.
Can anything change the IP addresses? With address translation (NAT), a router or firewall on the way maps IP addresses from one group to another. Without NAT, a router normally leaves the IP addresses as they are, as R1 did.
The packet is for H2, so you might expect H2’s MAC address on H1’s cable. A MAC address works only within one network, though, so the destination there is R1’s.
Key idea
MAC addresses are for one network; IP addresses are for the whole way.