Skip to content

How switches learn

Module
Ethernet and Local Delivery
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS, netlab 1.0, GNU Bash 5.2.21, tcpdump 4.99.4
On this page

Phone did not hear laptop’s web request in Choosing a capture location. The switch knew which cable to use, although you never entered laptop’s address into it. Here you will read what the switch remembers and connect each learned entry to a frame’s source.

Finish MAC addresses and frames. Leave machine shells and run netlab reset from the VM terminal. Keep modes off. Run the table reads from the VM terminal, learner@rootvolt:~$. A blank result is evidence too: do not fill it with an assumed device list.

A MAC address table records which switch port leads to each learned MAC address. Here the ports have machine names. The entry with dev laptop says that frames from that source arrived through the port toward laptop.

Use netlab shell sw-home -- bridge fdb show br sw-home dynamic. As before, the part after -- runs one command on the named switch and returns to the VM. bridge fdb show reads its address table; br sw-home selects this bridge. dynamic hides the entries the switch was given at start, its own fixed entries.

The option -W 1 gives ping a one-second reply timeout. The unused address makes this check finish without a reply.

Predict: laptop sends a frame that nobody answers, to an address nobody has. Which machines are in the table?

Read the switch table as it learns
learner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic[sudo] password for learner: learner@rootvolt:~$ netlab shell laptop -- ping -c 1 -W 1 10.77.10.99PING 10.77.10.99 (10.77.10.99) 56(84) bytes of data.

--- 10.77.10.99 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0mslearner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic02:77:10:00:00:10 dev laptop master sw-home learner@rootvolt:~$ netlab shell laptop -- ping -c 1 10.77.10.11PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data.
64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.563 ms

--- 10.77.10.11 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.563/0.563/0.563/0.000 mslearner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic02:77:10:00:00:10 dev laptop master sw-home 
02:77:10:00:00:11 dev phone master sw-home learner@rootvolt:~$ netlab shell sw-home -- cat /sys/class/net/sw-home/bridge/ageing_time30000learner@rootvolt:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. From the VM, read an empty table, send toward an unused address, read again, then ping phone and read a third time.
Steps (20)
  1. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Type netlab shell laptop -- ping -c 1 -W 1 10.77.10.99
  7. Press Enter
  8. Output: PING 10.77.10.99 (10.77.10.99) 56(84) bytes of data. --- 10.77.10.99 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 0ms
  9. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  10. Press Enter
  11. Output: 02:77:10:00:00:10 dev laptop master sw-home
  12. Type netlab shell laptop -- ping -c 1 10.77.10.11
  13. Press Enter
  14. Output: PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data. 64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.563 ms --- 10.77.10.11 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.563/0.563/0.563/0.000 ms
  15. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  16. Press Enter
  17. Output: 02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:11 dev phone master sw-home
  18. Type netlab shell sw-home -- cat /sys/class/net/sw-home/bridge/ageing_time
  19. Press Enter
  20. Output: 30000
Check your answer

Only laptop is learned from the unanswered question for 10.77.10.99. The first read prints nothing. The second lists laptop alone. The third lists laptop and phone, after phone has answered.

Before ping can send its echo request, laptop asks who has the address. That question already carries laptop’s source MAC address. No successful ping is needed for learning.

The switch reads the source address of an arriving frame and remembers its incoming port. When phone answers, its source teaches the phone port. Sending more frames from a source refreshes that entry. A destination lookup uses the table, but does not create the destination’s entry.

Predict which step first adds phone. Look at the source of each frame before moving to the next step.

Learn from the source of each frame

  1. laptop
  2. phone
  3. router
  1. Nobody answers: laptop to phone and router
  2. Who has phone?: laptop to phone and router
  3. Phone answers: phone to laptop
  4. Echo request: laptop to phone
  5. Echo reply: phone to laptop

In the capture5 messages at laptop:eth0

  1. 1. Nobody answers18:12:42.087080 02:77:10:00:00:10 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.77.10.99 tell 10.77.10.10, length 28
  2. 2. Who has phone?18:12:44.230161 02:77:10:00:00:10 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.77.10.11 tell 10.77.10.10, length 28
  3. 3. Phone answers18:12:44.230200 02:77:10:00:00:11 > 02:77:10:00:00:10, ethertype ARP (0x0806), length 42: Reply 10.77.10.11 is-at 02:77:10:00:00:11, length 28
  4. 4. Echo request18:12:44.230202 02:77:10:00:00:10 > 02:77:10:00:00:11, ethertype IPv4 (0x0800), length 98: 10.77.10.10 > 10.77.10.11: ICMP echo request, id 177, seq 1, length 64
  5. 5. Echo reply18:12:44.230260 02:77:10:00:00:11 > 02:77:10:00:00:10, ethertype IPv4 (0x0800), length 98: 10.77.10.11 > 10.77.10.10: ICMP echo reply, id 177, seq 1, length 64

sw-home MAC address table

MAC addressPort
02:77:10:00:00:10laptop
02:77:10:00:00:11phone

Checked against bridge fdb show before step 1 and after steps 1 and 5.

Step-by-step model built from captured frames · Frames captured at laptop:eth0 while running netlab shell laptop -- ping -c 1 -W 1 10.77.10.99; netlab shell laptop -- ping -c 1 10.77.10.11, on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. The values are the capture's. The table is checked against the three real reads. Repeated unanswered questions between the first two displayed frames are omitted.
Steps (5)
  1. Nobody answers. laptop to phone and router. Laptop asks who has an unused address. This frame names laptop as its source. sw-home learned 02:77:10:00:00:10 on port laptop.18:12:42.087080 02:77:10:00:00:10 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.77.10.99 tell 10.77.10.10, length 28
  2. Who has phone?. laptop to phone and router. Laptop asks who has 10.77.10.11. sw-home table unchanged.18:12:44.230161 02:77:10:00:00:10 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.77.10.11 tell 10.77.10.10, length 28
  3. Phone answers. phone to laptop. Phone answers laptop. sw-home learned 02:77:10:00:00:11 on port phone.18:12:44.230200 02:77:10:00:00:11 > 02:77:10:00:00:10, ethertype ARP (0x0806), length 42: Reply 10.77.10.11 is-at 02:77:10:00:00:11, length 28
  4. Echo request. laptop to phone. Laptop sends one ping to phone. sw-home table unchanged.18:12:44.230202 02:77:10:00:00:10 > 02:77:10:00:00:11, ethertype IPv4 (0x0800), length 98: 10.77.10.10 > 10.77.10.11: ICMP echo request, id 177, seq 1, length 64
  5. Echo reply. phone to laptop. Phone answers the ping. sw-home table unchanged.18:12:44.230260 02:77:10:00:00:11 > 02:77:10:00:00:10, ethertype IPv4 (0x0800), length 98: 10.77.10.11 > 10.77.10.10: ICMP echo reply, id 177, seq 1, length 64
Check your answer

Phone first appears when it answers the address question. The earlier question names phone’s IP address, but its source is still laptop. The following ping frames refresh existing entries.

Frame Source address Arrived on Added
No answer 02:77:10:00:00:10 laptop laptop
Question 02:77:10:00:00:10 laptop None
Answer 02:77:10:00:00:11 phone phone
Request 02:77:10:00:00:10 laptop None
Reply 02:77:10:00:00:11 phone None

Aging removes a learned entry after it has not been refreshed for a time. The read using cat prints the switch’s aging setting from the named system file. The captured value is 30000 hundredths of a second, which is 300 seconds.

The command sleep 310 does nothing for 310 seconds, a little more than the switch’s 300-second aging time. Keep the lab quiet during that wait. The replay advances past the wait; repeating the command in your terminal takes the full time.

Learn entries, wait for aging and read the empty table
learner@rootvolt:~$ netlab shell laptop -- ping -c 1 10.77.10.1[sudo] password for learner: PING 10.77.10.1 (10.77.10.1) 56(84) bytes of data.
64 bytes from 10.77.10.1: icmp_seq=1 ttl=64 time=0.180 ms

--- 10.77.10.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.180/0.180/0.180/0.000 mslearner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic02:77:10:00:00:10 dev laptop master sw-home 
02:77:10:00:00:01 dev router master sw-home learner@rootvolt:~$ netlab shell sw-home -- cat /sys/class/net/sw-home/bridge/ageing_time30000learner@rootvolt:~$ sleep 310learner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamiclearner@rootvolt:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. From a reset lab, learn laptop and router, wait for aging, then read the empty table.
Steps (16)
  1. Type netlab shell laptop -- ping -c 1 10.77.10.1
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: PING 10.77.10.1 (10.77.10.1) 56(84) bytes of data. 64 bytes from 10.77.10.1: icmp_seq=1 ttl=64 time=0.180 ms --- 10.77.10.1 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.180/0.180/0.180/0.000 ms
  7. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  8. Press Enter
  9. Output: 02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:01 dev router master sw-home
  10. Type netlab shell sw-home -- cat /sys/class/net/sw-home/bridge/ageing_time
  11. Press Enter
  12. Output: 30000
  13. Type sleep 310
  14. Press Enter
  15. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  16. Press Enter

This run learns laptop and router before waiting. Both entries disappear. The cables remain connected and the machines keep their addresses. A missing table entry means the switch must choose how to deliver the next frame without that remembered location.

“The switch learns from frames sent to a machine.” The no-answer read adds only the sender. Phone appears after its own answer, not when laptop asks for it.

“An administrator configured this table.” The clean table and the two later reads show entries appearing from traffic alone. Fixed entries exist too, but this command hides them.

Reading the table sends no frame from laptop or phone. Read promptly after the traffic you are checking. Waiting for several minutes changes the question because learned entries can expire.

Reset from the VM. Predict the table after five frames: phone’s question for laptop, laptop’s answer, phone’s echo request, laptop’s echo reply, then router’s question for the unused address. Write the source and incoming port beside each frame. Read the table with netlab shell sw-home -- bridge fdb show br sw-home dynamic. Run netlab shell phone -- ping -c 1 10.77.10.10, read again, then run netlab shell router -- ping -c 1 -W 1 10.77.10.99 and read again. Compare the results with your predicted entries after the first four frames and the fifth frame.

Solution
Check five frames from phone, laptop and router
learner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic[sudo] password for learner: learner@rootvolt:~$ netlab shell phone -- ping -c 1 10.77.10.10PING 10.77.10.10 (10.77.10.10) 56(84) bytes of data.
64 bytes from 10.77.10.10: icmp_seq=1 ttl=64 time=0.122 ms

--- 10.77.10.10 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.122/0.122/0.122/0.000 mslearner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic02:77:10:00:00:10 dev laptop master sw-home 
02:77:10:00:00:11 dev phone master sw-home learner@rootvolt:~$ netlab shell router -- ping -c 1 -W 1 10.77.10.99PING 10.77.10.99 (10.77.10.99) 56(84) bytes of data.

--- 10.77.10.99 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0mslearner@rootvolt:~$ netlab shell sw-home -- bridge fdb show br sw-home dynamic02:77:10:00:00:10 dev laptop master sw-home 
02:77:10:00:00:11 dev phone master sw-home 
02:77:10:00:00:01 dev router master sw-home learner@rootvolt:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. The first ping causes four frames. Router's later unanswered question supplies the fifth distinct step; retries repeat the same source.
Steps (17)
  1. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Type netlab shell phone -- ping -c 1 10.77.10.10
  7. Press Enter
  8. Output: PING 10.77.10.10 (10.77.10.10) 56(84) bytes of data. 64 bytes from 10.77.10.10: icmp_seq=1 ttl=64 time=0.122 ms --- 10.77.10.10 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.122/0.122/0.122/0.000 ms
  9. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  10. Press Enter
  11. Output: 02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:11 dev phone master sw-home
  12. Type netlab shell router -- ping -c 1 -W 1 10.77.10.99
  13. Press Enter
  14. Output: PING 10.77.10.99 (10.77.10.99) 56(84) bytes of data. --- 10.77.10.99 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 0ms
  15. Type netlab shell sw-home -- bridge fdb show br sw-home dynamic
  16. Press Enter
  17. Output: 02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:11 dev phone master sw-home 02:77:10:00:00:01 dev router master sw-home

The first frame adds phone; the second adds laptop. The next two add nothing. The fifth adds router. The reads check the empty start, the two entries after the first ping, then all three. Retried unanswered questions do not add another machine.

  • Learn an address from a frame’s source and incoming port.
  • Look up a destination using what has already been learned.
  • Expect quiet entries to disappear through aging.

Next, Unicast, broadcast, and flooding tests delivery with and without a learned destination.