How does a home router and network switch work together?

nd_alpha22

Reputable
Dec 11, 2016
5
0
4,520
I have seen on the internet that one way to increase the number of LAN ports on your router is to plug an Ethernet switch to it.

But according to what i know is that a router ( home router having a combo of router+switch+AP in one unit) transfers data between devices using ip whereas a switch uses mac address form its switch table to transfer data.

Also a router runs its dhcp server and nat.

so how do devices connected to the switch get their individual ip address from the router...and how is this ip distributed using only one Ethernet cable plugged between the switch and the router.
 
Solution
Try googling ARP Address resolution protocol. It is how a router binds a MAC to an IP using a broadcast address.

Not sure what that last guy was on about with switches using layer 3. A switch is a Layer 2 device, Some switches allow limited layer 3 for management of the switch.

You can get Layer 3 switches but they are a specialized device that you will not have in your home. Layer 3 switches allow routing between networks at Layer 3 using SVI's (switched virtual interfaces) that assign IP addresses to Vlans then route between Vlans or Routed ports which assign an IP directly to a port. They are not able to do NAT, They have basic security capabilities like PVLAN ACL's and a few other things, They are usually fairly expensive and only...

kanewolf

Titan
Moderator
Switches can use the MAC layer (layer 2) or the IP address (layer 3) -- https://en.wikipedia.org/wiki/Protocol_stack
A router is a layer 3 device. It uses the IP address on the LAN to WAN boundary. On the LAN side only it is a layer 2 switch. That is why there is only one subnet on the LAN side of home routers. There is no need to deal with the IP address because only the last octet is different. It is faster to use MAC addresses in that case.
 

nd_alpha22

Reputable
Dec 11, 2016
5
0
4,520


I agree that the last octet is only different but the dhcp server does assign individual ip to connected devices ..and those connected through the switch as well..
 
You are getting into the area that will require some study to understand how machine really talk and what layer 2 and layer 3 really mean.

The answer to your question is that dhcp is a broadcast protocol when request are made for ips and ip are assigned. What makes it really confusing is DHCP uses non broadcast messages also for certain features.

Your question may seem simple but it is not really when you do not understand the underlying concepts and must learn those first.

Likely the best tool to learn some of this stuff is wireshark. You can actually see all the packets coming and going from your machine. Wire shark does a excellent job of decoding all the fields in packets.

You are just at the very start of learning how this stuff really works.
 

As already mentioned, the OSI Model with its 7 layers explains all these. Actually the first 3 layers is sufficient to explain most switches and routers.

Also a router runs its dhcp server and nat.
In a home environment, that is often true, for convenience reasons I say, and not a technical necessity.

One of the business I was in, with 300 users, the DHCP was running on a Microsoft domain server. At a later time we wanted redundancy so I ran DHCP/DNS/WINS in its own box, with a twin backup. DHCP is just a SERVICE, it can be anywhere, as long as the clients can see it.

NAT sits naturally on a router, well because NAT=change IP, but can also sit on a layer-3 switch. A layer3 switch is a more intelligent switch that can act on IP packets beyond the normal ethernet frames. You won't see layer-3 switches$$$ in homes.

so how do devices connected to the switch get their individual ip address from the router
U probably heard the term DUMB switches before... most home switches are of this type. The clients talk to the DHCP server THROUGH a switch, but the switch doesn't pay any attention to the IP information, it just passes what is called the PACKET back and forth.

and how is this ip distributed using only one Ethernet cable plugged between the switch and the router.
From a 1000 ft up, the same way the cable company is able to send you 100 TV channels through a single coax cable. The terms frames, packets, multiplexing, de-multimplexing, encapsulation, header, payload, much, much, much more fun stuff becomes knowledge.

OSI model is networking bible.
 

sma

Honorable
Mar 13, 2013
4
0
10,520
Try googling ARP Address resolution protocol. It is how a router binds a MAC to an IP using a broadcast address.

Not sure what that last guy was on about with switches using layer 3. A switch is a Layer 2 device, Some switches allow limited layer 3 for management of the switch.

You can get Layer 3 switches but they are a specialized device that you will not have in your home. Layer 3 switches allow routing between networks at Layer 3 using SVI's (switched virtual interfaces) that assign IP addresses to Vlans then route between Vlans or Routed ports which assign an IP directly to a port. They are not able to do NAT, They have basic security capabilities like PVLAN ACL's and a few other things, They are usually fairly expensive and only really used in large business/enterprise networks.

Basically what happens with your switch and router is this. The router has a WAN port, That port has your Public IP address assigned to it by your ISP. You then have your LAN side which has a private IP range ( google RFC 1918). The Router has a built in switch which connects to either your devices or another switch. Both the Routers built in switch and any other switches that you connect to it all work at Layer 2. You have DHCP that assigns private IP's to each of your computers in your house so that the computer is able to communicate at Layer 3 with the router so that it is able to then NAT that private IP to the Public IP and allows you to get onto the internet.

ARP binds MAC address's to IP address's on the router, ( http://www.erg.abdn.ac.uk/users/gorry/course/inet-pages/arp.html )
So you open a command prompt on your computer and you try to ping another computer on your local network. Your computer doesn't know who has that IP at Layer 3 so it sends an ARP request for that IP address to the broadcast mac with a source of the MAC address of your computer. By default a switch will transmit a broadcast packet to all ports on the switch except the port from which it entered the switch. The PC with that IP will detect it's IP address in the arp request and will send an ARP reply to the MAC address of your computer with a source of it's MAC and it's IP. Your computer then uses layer 2 to communicate with the other computer because you are on the same local subnet.

If you had two networks in your house on your router then it would be a different story. At that point you would need to route between those two networks and you would need to go through Layer 3 to get to the other computer on the other network. Similar process really, Open your command prompt and ping computer on other network... Your computer see's that the other computer is not on the same network as you so it sends the packet to it's default gateway with your PC's source mac and IP address. The router then detects it has an interface on the same network you are trying to get to so it does does an ARP to get the MAC to IP binding and then sends the packet to the other computer on the other network using a destination address as the MAC and IP address of the destination computer and a source address of the routers MAC but the original source computers IP address. The reason for this is so that the reply traffic will hit the router on Layer 2 and have the correct destination information available for the router to then process the reply traffic at layer three to be able to send onto the original network where you started the ping from.
 
Solution