1.Does a Router also have a MAC address or just IP?
2.how does a router recognize a Switch because switches don't have IP address?
3.is it using the MAC? if so do routers deal with both network and data link layers?

thanks

hello silvercats..

1) Yes, a router has a MAC address and IP on each network interface. The MAC address is the layer 2 (physical) address, while the IP address is the layer 3 (logical) address.

2) the router doesnt really know that the switch is there. When a computer needs to send a packet to a remote network, it sends it to the gateway (router). there may be a switch between the computer and the gateway. The switch has the MAC addresses learned in its tables so it knows which ports to send the traffic through.

3) Routers do operating at network and data link layers. TCP/IP depends on the data link layer for local delivery of packets. what I mean by that is for one host to send a packet to another host on the same segment, the host uses the MAC address for delivery.

I can go into more detail if you have more questions after reading this response...

How does the router know which Switch to send the data to,if three or more switches connected to the router if router doesn't know about their MAC?is it like router sends to all its ports?isn't that messy?

The router may be connected to more than one switch, but it each switch will be on a different router port and VLAN. so if the router needs to send a packet to 192.168.1.1, it knows that that subnet is on the router's first interface, as an example. So here is what happens in the scenario where the router needs to send a packet to computer A:

1) router has a packet that it needs to deliver to 192.168.1.1
2) router determines that to get to this host it needs to send the packet on interface 1 (based on the router's routing table)
3) router checks its arp table to see if it has a MAC address for host 192.168.1.1
4) if router has MAC, it sends the packet on that interface. If it doesnt, it performs an ARP request until it gets the answer.
5) packet is own its way on that interface. This interface is connected to the switch port. The switch picks up the packet
6) Switch is a layer two device, doesnt care about the IP
7) switch looks at the packet to inspect the destination MAC.
8) Swich looks at all MAC tables to see if it can knows which port the MAC has been seen.
9) if the Switch finds the MAC in its tables, it send the packet on the correct port
10) if the switch does find the MAC, then it sends the packet on ALL of its port
11) If #9 is true, the destination computer will receive the packet
12) if #10 is true, all computers receive the packet. Each NIC will inspect the packet. The NIC that has the same MAC address will bring the packet up to the OS. All other computers will discard the packet.
13) target computer will process the packet and send a response back to the router (process is reversed now)
14) on the way back the switch has now learned (if #10 was true) about the computer's MAC, switch updates its table. Now switch nows about computer A.

so as you see, the switch is just in the middle of this path. Neither the computer, nor the router really know that the switch is in its way. The purpose of the switch is to move packets at a layer 2, unlike the hub which is layer 1 and has no knowledge of MAC addresses.

commented: One confusion, a router may have multiple ip addresses: each port ip, gateway ip, own ip, mac, ....Now, when & how to use each one differently? +0

Correction on #10

if the switch does NOT find the MAC, then it sends the packet on ALL of its port

Thanks.

2) router determines that to get to this host it needs to send the packet on interface 1 (based on the router's routing table)

how does it know about the interface 1?(explained below)

let's say we have a rotuer, and Switches are connected to that router.switch 1 and switch 2. switch 1,2 both have 10 computers on each( two LANs are connected to router through these two switches).

let's say router needs to send some data to 192.168.1.1 which on the LAN of switch 2.

does Router have a table of MACs of all the 20 computers (10 on each LAN/Switch) on both LANs to decide whether to forward packets(to 192.168.1.1 machine) to switch 2 or 1?. how does it know if 192.168.1.1 is belonged to switch 1 or switch 2? this is confusing and I don't understand how first 5 steps happen exactly.

Ok...

So first, generally if a router has more than one NIC, each NIC is on its own subnet. A router wouldnt have more than one NIC that belongs to multiple subnets. Do not confuse a traditional router with that of a consumer based internet router that has many ports on the back of the box. I think this is where your confusion is. I applogize. On an internet router that has 4 ports in the back, this internet router is actually a router with a built in switch. This type of router has only ONE subnet. You can plug additional switches in that back of this internet router. Think of the internet router as two devies, a router and a 4 port switch in one box. that 4 port switch is already wired to the router's port.

Now in this example, you have two switches plugged into the back of this internet router. OK... so far so good. 10 computers plugged into each switch. Now the router wants to send a packet to 192.168.1.1. The router has no knowledge where the computer is plugged into. The router ONLY needs to know computer1's MAC address. If it hasnt communicated with it recently, it needs to get Computer1's MAC by peforming an ARP request (dont worry about that detail for now). When the Router has Computer1's MAC, it send the packet to the switch. Keep in mind on the internet router, we are still inside the same box. Now the 4 port switch that is inside this internet router gets the packet. This 4 port switch as NO routing table. It only has a MAC table. The MAC table is populated by the switch keeping an eye on the traffic and LEARNS what ports the MAC addresses are plugged into. So, now this 4 port switch inside this internet router box has to determine where computer 1 is located.

If it already knows that the MAC was seen on PORT 1, it sends the traffic to port 1. Port 1 may have another switch connected to this internet router/switch device. That's OK. When the 10 port switch gets the packet, it does the same thing. This ten port switch now looks at its MAC tables and tries to figure out where it saw Computer1's MAC.

At any time, when a switch does not find the target MAC, it will broadcast the packet on ALL ports until it learns the MAC.

Let me know if this clarifies it, it not, we'll continue....

yup I was talking 4 ports(on the back) router with switch thing. yup that clarified well.so a router basically forwards packets to Ports,right? and it has a Table mapped, each MAC address to each port of two switches. correct?

and switches don't have MAC addresses at all?but Router do,right?

Yes, you are correct, the switch hardware that is integrated in the interet router device maintains a MAC Address table. The router just sends the packets that are destined for the internal network to the switching hardware, then the switch will forward the packets on the correct ports.

For example, If you have 10 computers on a switch and that switch is plugged into the back of the internet router, then the device will have a MAC table for port 1 with 10 MACs learned. If you have another switch with 10 computers plugged into port 2 of the internet router, it will also capture those 10 MACs and store them in the mapping table. When the router sends the packets to the switch hardware, the switch hardware will forward the packet on either port 1 or port 2 depending where it finds the destination MAC.

cool.simpler than expected ha. thank for helping ITG-JM !

So based on the discussion above,
the internet router sends in packets onto a switch on one of its interfaces (using the IP address), and switch has a list of MAC of the associated LAN (using ARP) and accordingly forwards the packet to specific host.?
correct me if I am wrong

yes teju, you are right.
and now switch update his routing table.

Good answers Jorge! I'd give you an up-vote but I see you already got a bunch for your replies to this! No sense in spoiling you... :-)

This discussion seems to suggest that switch ports do not have a dedicated MAC address. MAC addresses are assigned only for host ports. Am I correct?

Jorge: Can you please describe in detail how two routers communicate? Do they use data link layer which forwarding packet from one to another?

Every network interface of every device (router, switch port, etc.) has a unique mac address.

Routers deal with IP (layer 3 of the OSI). Local communication uses MAC address (Layer 2) unless it needs the router to get to another network.

Yes a router acts as a switch too on it's LAN ethernet port(s).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.