How switches learn
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.
Before you start
Section titled “Before you start”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.
Read what the switch knows
Section titled “Read what the switch knows”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?
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:~$ Steps (20)
- Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Type
netlab shell laptop -- ping -c 1 -W 1 10.77.10.99 - Press Enter
- 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 - Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- Output:
02:77:10:00:00:10 dev laptop master sw-home - Type
netlab shell laptop -- ping -c 1 10.77.10.11 - Press Enter
- 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 - Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- Output:
02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:11 dev phone master sw-home - Type
netlab shell sw-home -- cat /sys/class/net/sw-home/bridge/ageing_time - Press Enter
- 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.
Follow the sources into the table
Section titled “Follow the sources into the table”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
- laptop
- phone
- router
- Nobody answers: laptop to phone and router
- Who has phone?: laptop to phone and router
- Phone answers: phone to laptop
- Echo request: laptop to phone
- Echo reply: phone to laptop
In the capture5 messages at laptop:eth0
- 1. Nobody answers
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?
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
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
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
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
sw-home MAC address table
| MAC address | Port |
|---|---|
02:77:10:00:00:10 | laptop |
02:77:10:00:00:11 | phone |
Checked against bridge fdb show before step 1 and after steps 1 and 5.
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)
- 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 - 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 - 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 - 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 - 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 |
Let quiet entries expire
Section titled “Let quiet entries expire”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.
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:~$ Steps (16)
- Type
netlab shell laptop -- ping -c 1 10.77.10.1 - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- 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 - Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- Output:
02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:01 dev router master sw-home - Type
netlab shell sw-home -- cat /sys/class/net/sw-home/bridge/ageing_time - Press Enter
- Output:
30000 - Type
sleep 310 - Press Enter
- Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - 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.
Mistakes to recognize
Section titled “Mistakes to recognize”“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.
Good to know
Section titled “Good to know”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.
Try it yourself
Section titled “Try it yourself”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
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:~$ Steps (17)
- Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Type
netlab shell phone -- ping -c 1 10.77.10.10 - Press Enter
- 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 - Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- Output:
02:77:10:00:00:10 dev laptop master sw-home 02:77:10:00:00:11 dev phone master sw-home - Type
netlab shell router -- ping -c 1 -W 1 10.77.10.99 - Press Enter
- 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 - Type
netlab shell sw-home -- bridge fdb show br sw-home dynamic - Press Enter
- 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.
Further reading
Section titled “Further reading”- Ubuntu: bridge manual, for reading learned entries.
- Linux kernel: Ethernet bridging, for source learning and aging.