Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts
8

MAC address of switches

I've been searching for an answer to this question for a while now but somehow I couldn't find a satisfying answer.

Assume a host H is connected to a router R via a switch S. Now assume the router receives an IP datagram addressed to H. It consults its routing table and determines the interface upon which to forward the packet.

Now it must encapsulate the IP datagram in a link-layer frame and send it on its way. The next hop is obviously the switch, so the router must put the switch's MAC address in the destination MAC field.

But how does the router know the switch's MAC address? It can't use ARP to resolve the switch's MAC address since the switch doesn't necessarily have an IP address (e.g. if the switch is an unmanaged switch). And if it has the switch's MAC address stored in its forwarding table somehow, then how did it get it in the first place? Or does it just put H's MAC address in the destination field and the switch ignores that the MAC address doesn't match its MAC address?

Thank you for your help :)

14 comments
70% Upvoted
What are your thoughts? Log in or Sign uplog insign up
Meow 馃悎馃悎Meow 馃惐馃惐 Meow Meow馃嵑馃悎馃惐Meow A+!
20 points4 days ago

Now it must encapsulate the IP datagram in a link-layer frame and send it on its way. The next hop is obviously the switch, so the router must put the switch's MAC address in the destination MAC field.

Here is your incorrect assumption. dst mac is the host H. Switch does not re-write MAC addr, just reads src,dst. Records src in CAM table with ingress i/f, forwards frame out the entry for dst in the CAM.

Original Poster3 points4 days ago

I see! Makes sense since the switch wouldn't need to pass anything up to any upper layers since they don't exist, so it wouldn't have to match the datagram's MAC address to its own. Thank you very much for your reply.

However this raises a follow up question. Why would a switch need a MAC address in the first place?

12 points4 days ago

Why would a switch need a MAC address in the first place?

I believe this is only for managed switches, which have layer 3 functionality in the sense that they have a management interface of some kind (web, telnet, SSH) and therefore need an IP to function, therefore need a MAC.

If you have a completely unmanaged switch then I don't believe that would have a MAC address of its own, merely a CAM table to look up other MAC addresses that it knows about.

Original Poster3 points4 days ago

Thank you :)

Network Engineer
1 point3 days ago

If you have a completely unmanaged switch then I don't believe that would have a MAC address of its own,

I wonder how an unmanaged switch would participate (if it can) in spanning tree, if it needs a MAC to do the root bridge election.

EDIT: I see that BPDUs are sent with the src MAC of the origin port, so maybe the switch can entirely function without a base MAC?

1 point2 days ago

I wonder how an unmanaged switch would participate (if it can) in spanning tree

Easy: Most don't.

Freelance Network Coder
5 points3 days ago

Why would a switch need a MAC address in the first place?

Apart from forwarding end-user traffic, a switch port can also participate in control protocols (CDP, LLDP, STP, LACP etc); and when transmitting the packets (PDUs) for these control protocols it needs something to put into the Source MAC Address field.

Meow 馃悎馃悎Meow 馃惐馃惐 Meow Meow馃嵑馃悎馃惐Meow A+!
1 point4 days ago

Why would a switch need a MAC address in the first place?

Each interface needs a mac, so the system is assigned a base mac addr and interfaces are keyed off of that.

8 points4 days ago

Partially incorrect. Each Layer 3 interface (including mgmt) needs a MAC address. If you have an unmanaged switch, it has no such concept.

Meow 馃悎馃悎Meow 馃惐馃惐 Meow Meow馃嵑馃悎馃惐Meow A+!
5 points4 days ago

unmanaged

GO WASH YOUR MOUTH OUT WITH SOAP AND WATER

Also, I forgot that STP needs a mac addr also.

Original Poster1 point4 days ago

Thank you for your reply :D

Can I piggyback off this and ask a kind of similar question (probably a dumb question though, :D) ?

So when a host sends a packet across a network, lets say, for example, Host A sends traffic destined for a host over the internet, but in order to reach the internet it has to go through a couple switches/routers. My question is, how much of that packet can each switch/router that it goes through see? I know they have to see source/dest. MAC/IP, but can the switches/routers read the data that's in the packet?

And actually this brings up another question... if a host generates layer 2 or 3 traffic, like an ARP request or ICMP, does it only encapsulate that specific layer down? Or does it still encapsulate all 7 layers of the OSI?

Probably drunk | Moderator
4 points4 days ago

can the switches/routers read the data that's in the packet?

Yes, they can see the payload. This is why encryption is important as it encrypts the payload.

if a host generates layer 2 or 3 traffic, like an ARP request or ICMP, does it only encapsulate that specific layer down? Or does it still encapsulate all 7 layers of the OSI?

I think this would be an excellent opportunity for you to fire up Wireshark and take a look. :)

But how does the router know the switch's MAC address? It can't use ARP to resolve the switch's MAC address since the switch doesn't necessarily have an IP address (e.g. if the switch is an unmanaged switch). And if it has the switch's MAC address stored in its forwarding table somehow, then how did it get it in the first place?

A switch (routers too) learns MAC addresses from the source address in a frame. The router, in your example, learned the switch's MAC address when it received the first frame. It added the source MAC to its table and associated the incoming interface with it.

Or does it just put H's MAC address in the destination field and the switch ignores that the MAC address doesn't match its MAC address?

MAC addresses are never the HOP over the link. They will always be what is connected directly. The R forwarded the frame (previously a packet with routing information) to H towards the S. It forwarded it towards the S because it found a matching route in its routing table. The S then forwarded the frame towards the H. It knows where H is, because it learned H's MAC address in a frame that it received from it.

I invite you to read Wikipedia's layer 2 and 3 of the OSI model. You'll get a lot of details that will fill in the gaps.

Community Details

123k

Subscribers

1.2k

Online

###Enterprise Networking Routers, switches and firewalls. Network blogs, news and network management articles. Cisco, Juniper, Brocade and more all welcome.

Create Post
r/networking Rules
1.
Rule #1: No Home Networking.
2.
Rule #2: No Certification Brain Dumps / Cheating.
3.
Rule #3: No BlogSpam / Traffic re-direction.
4.
Rule #4: No Low Quality Posts.
5.
Rule #5: No Early Career Advice.
6.
Rule #6: Educational Questions must show effort.
Cookies help us deliver our Services. By using our Services or clicking I agree, you agree to our use of cookies.Learn More.