How does a switch learn MAC Addresses

Thank you very much for your answer!
One last comment:
As I understand, the switch senses the absense of a station (and the present of it). Suppose that a 48-port switch connects 8 stations on ports 1-8. When powered on, its mac table it’s empty. On the arrivalal of the first frame, lets say from station on port 1, it broadcast it only to ports 2-7 (where it senses there are connected stations) or to all 47 other port interfaces?

Thanks again!

1 Like

Hi,

What abt the frame filtering mechanism when two computers connected in a hub environment which in turn connect with siwtch. Will the switch learn both mac address during l2 forwarding scenario?? Kindly help.

Thanks,
Raghav

Hi Raghav,

When you have a hub connected to the switchport, the switch will learn both MAC addresses from the computers connected to the hub. A switchport can learn multiple MAC addresses…

Rene

Dear Rene,

Thank you for creating this online source. It is really helpful in preparation for CCNA exam.

There is one thing I would like to ask you. If we continue your scenario and assume that computer A has some data to send for computer C.

Does the switch flood the frames again? Or does it make an exception assuming that computer C is located in a port which has not been learned yet?

Best regards,
Aisha

Dear Aisha,

Thank you, glad to hear that you like it. The logic of the switch is pretty simple…it only does two things:

- When it receives an Eternet frame, it will learn the source MAC address and saves it in the MAC address table for each interface.
- When it forwards the Ethernet frame, it will check the MAC address table…if the destination MAC address is unknown, it will be flooded. When it is known, it will be forwarded out of the correct interface.

So when Computer C hasn’t sent any frames yet, the switch didn’t have any opportunity to learn its MAC address. As a result, a frame meant for Computer C will be flooded…

Does that help?

Rene

1 Like

Yes, it does. Thanks a lot!

Hi Rene,

First of all, thanks for you share your knowledge of a nice and simple method/way.

So, If on a real network we will always have a ARP or DHCP Discovery, when the concept this article it is apply? Since ARP and DHCP Discovery send messages broadcast, so a switch will flood all port because is explicit on ARP or DHCP Discovery Frame. Is there any way where a computer can exchange data each other just using mac address?

I know there are some printers software that discovery your device just with mac addess and I think winbox tool(Microtik) works the same form. Do you know something about that?

Sorry for my English mistakes and I hope you can understand my doubt.

Hugs

Hi Gabriel,

The switch is a pretty “dumb” box…it only cares about a couple of things:

  • When it receives an ethernet frame and it didn’t see the source MAC address before, it is stored in the mac address table.
  • If the destination MAC address is known, it forwards it out of the correct interface.
  • If the destination MAC address is unknown, it is flooded on all ports (except the one where it came from).
  • If the destination MAC address is a broadcast, it is flooded on all ports (except the one it came from).

So this story about the switch learning MAC addresses always applies on a LAN since we always use Ethernet there. You have to see the switch and the computer completely seperate from each other…the switch doesn’t care about any of the traffic, only about the frames and their MAC addresses…that’s it.

About the computers,we use IP for pretty much everything so most of the traffic from your computer will use IP packets but it’s possible that some protocols use something else. Not sure if Windows uses any “discovery” protocols that don’t use IP but are encapsulated in an Ethernet frame directly. I do know a Cisco example:

Cisco Discovery Protocol

CDP doesn’t use IP but is encapsulated in Ethernet frames directly .

Rene,

First sorry for my long delay and thanks for answer me again. Now I can understand better how a switch works.

Abraço

Rene,

Thanks again, I am one video closer to passing my CCNA! This was helpful.

Chris

Hello Rene,
What is the difference between sh mac address table static and sh mac address table dynamic commands. What exactly are shown as static entries in the CAM table

Regards
Ashok

Hi Ashok,

The dynamic entries are those that the switch has learned by itself. You can also add manual entries for MAC addresses if you want, those are the static entries.

Rene

Hello Rene,
As you described a switch as pretty “dumb” box, I would like to ask, if the sentence in brackets “(except the one it came from)” could be added to the second thing, in your explanation.

Then Your explanation could look like this:

The switch is a pretty “dumb” box…it only cares about a couple of things:

– When it receives an Ethernet frame, and it didn’t see the source MAC address before, it is stored in the mac address table.
– If the destination MAC address is known, it forwards it out of the correct interface (except the one it came from).
– If the destination MAC address is unknown, it is flooded on all ports (except the one where it came from).
– If the destination MAC address is a broadcast, it is flooded on all ports (except the one it came from).

I considered the situation, where we have 3 switches and 3 hosts (as shown in the attached picture http://imgur.com/SaBSnbd)
All switches have all MAC addresses in their mac-address-tables.
All hosts have all MAC addresses mapped to IP addresses in their memory.
PC1 sends the frame to the PC2. When a frame enters Switch1 in the same time mac-address-table in Switch2 is cleared.
When the frame enters Switch2, it is flooded on all ports (except the one it came from).
One frame enters the PC2 and second enters the Switch3.
Switch3 has MAC address of PC2, so the destination MAC address is known, but it does not forward it out of the correct port because outgoing port and incoming port are the same.
The Switch3 drops the frame.

In my simulator, this works similarly as I wrote.
Could you answer if my suggestion is ok?

Jarisk

Hi Jarisk,

I’ll add your bulletpoints in a conclusion. It might be helpful to others to have a short overview.

Your explanation is correct btw. SW1 will know where to forward it, SW2 doesn’t so it floods it towards PC2/SW3. SW3 will drop it since it knows the destination MAC address can be reached on the interface where it received the frame on.

Rene

Hi Rene

I have a question about the Mac address learning on a switch, if a hub is connected to it. Say I have a hub(connected to Fa0/1 of switch) with two PCs, mac address table on the switch is empty. PC1 is trying to reach PC2, how does the switch learn mac address in this situation. Switch gets the ARP requests from PC1 on Fa0/1 and since there is no entry it forwards on all port except fa0/1

But here PC2 is also in Fa0/1? What happens here.

Thanks
Palani

Palani,
In this case, the switch would learn the MACs of both PC1 and PC2 and associate them with Fa0/1.

When PC1 sends out the ARP for PC2, that request is also sent out the Hub->Switch FA0/1 link. The switch learns PC1’s MAC from this request, and records it. However, the switch does not have the requested MAC for PC2, so it would have the request go out all switchports as well.

When PC2 answers the ARP of PC1 on the Hub, the switch would also get this traffic via Fa0/1 (since a Hub sends traffic to all ports). This is the mechanism by which the Switch would also learn the MAC of PC2; the switch would record it and associate it with Fa0/1.

Hi Andrew,

I above case

When PC1 sends out the ARP for PC2, that request is also sent out the Hub->Switch FA0/1 link. The switch learns PC1’s MAC from this request, and records it. However, the switch does not have the requested MAC for PC2, so it would have the request go out all switchports as well.

When PC2 answers the ARP of PC1 on the Hub, the switch would also get this traffic via Fa0/1 (since a Hub sends traffic to all ports). This is the mechanism by which the Switch would also learn the MAC of PC2; the switch would record it and associate it with Fa0/1.

Switch should not sent ARP request to the port where it came from,as both the PCs coonected to same ports ?

Rohitendu,
Correct, but that doesn’t change the results. The switch will learn the MAC of both PC1 and PC2 via the mechanism I described.

19 posts were merged into an existing topic: how does a switch learn MAC Addresses

Rene,

You stated in a earlier post the following:
The switch is a pretty “dumb” box…it only cares about a couple of things:

When it receives an ethernet frame and it didn’t see the source MAC address before, it is stored in the mac address table.
If the destination MAC address is known, it forwards it out of the correct interface.
If the destination MAC address is unknown, it is flooded on all ports (except the one where it came from).
If the destination MAC address is a broadcast, it is flooded on all ports (except the one it came from).

Here is an explanation from the Cisco book "Incoming frames also include the destination MAC address. Again, the switch looks up this address in the address table, hoping to find the switch port and VLAN where the destination address is attached. If it is found, the frame can be forwarded out the corresponding switch port. If the address is not found in the table, the switch must take more drastic action: The frame is forwarded in a “best effort” fashion by flooding it out all switch ports assigned to the source VLAN.

I am a little confused. Will destination MAC address get flooded on all ports or flooding out all switch ports assigned to the source VLAN?