Question about networks (layer 2)

Matts0344

Member
Jan 28, 2005
56
0
0
This is more of a basic network question. Just curious.

If I have, say, a switch and then one PC connected to one port (A) and another on another port (B). They each have static IP addresses, say 192.168.0.1 and .2

From the .1 PC I ping the .2 machine, then the switch knows the MAC of the .1 is on port A but how does the .1 PC know what MAC address to put for the "Destination Address" field in the ethernet packet?
 

spidey07

No Lifer
Aug 4, 2000
65,469
5
76
Address Resolution Protocol. ARP.

It's a layer2 broadcast asking for "who has this IP address? Respond to my source mac address"
 

ScottMac

Moderator<br>Networking<br>Elite member
Mar 19, 2001
5,471
2
0
A switch is essentially a fast, multi-port bridge, and it operates as a bridge does (@ Layer 2).

The bridge gets it's addresses (MACs) by passively listening and noting the *source* address of the frame on the "wire". If it hasn't seen that source before, it adds it to the forwarding table (for whatever the defined amount of time). It goes in the table as 'this MAC came in from this Port'.

When one device send a frame to another, the switch/bridge looks at the destination MAC ... if it's in the table, it sends the frame out that port. It also looks at the source address ... if that source is not in the table, it's added.

If the destination MAC is not in the table (unknown), the switch/bridge "Floods" the frame out all ports except the one it came in on.

Do not confuse "Flooding" with "Broadcasting" ... they are different.

With a broadcast, the destination MAC is all ones (usually, by convention) which matches all addresses in the broadcast domain.

Flooding sends the frame out all ports with the source and destination address intact (not all ones destination). The general idea is that if the destination evice is out there, it'll get the frame and respond accordingly.

Hope this helps

Scott

Edit: Nuts. I somehow managed to miss the whole last paragraph of the OP ... I gotta get some better drugs ...
 

Matts0344

Member
Jan 28, 2005
56
0
0
So do each of the PCs keep a table of IPs to MAC address entries?

I understand how a switch knows how to forward to which port, just confused on how the PCs know which MAC address to put in for the DA MAC.
 

spyordie007

Diamond Member
May 28, 2001
6,229
0
0
Originally posted by: Matts0344
So do each of the PCs keep a table of IPs to MAC address entries?

I understand how a switch knows how to forward to which port, just confused on how the PCs know which MAC address to put in for the DA MAC.
Yup, each host keeps an arp table/cache of the other hosts they can connect to over layer 2. If you're running a windows machine bring up a command prompt and type "arp -a" to see what your machine has in it's cache right now.

Erik
 

Matts0344

Member
Jan 28, 2005
56
0
0
Ah ok, this makes a lot more sense now! I was looking for a command like that too.

Thanks everyone!