I understand the differences between a switch and a router, but I don't understand the supposedly common practice of using a switch to extend/expand the number of ports provided by a router and where each device connected to the switch gets its own LAN IP address.

The switch and router operate on different layers (assuming the switch is not multi-layered) and hence I don't understand how it works.

Picture this scenario:

Router connects LAN to the WAN (public internet). Switch is connected to one of the router LAN ports. Devices (e.g. computers, laptops, etc.) are connected to the switch. Say there is device A connected to the switch and it wants to talk to device B (also connected to the switch). I understand that a switch allows the two devices to communicate without involving the router, but that is via MAC addresses (data-link layer). What if I want them to communicate using their LAN IP addresses, i.e. so I can use simple TCP socket programming?

Device A could send some data to Device B via a TCP socket, but how does the data get from Device A to the router and back to Device B, via the switch in both cases? The switch only knows MAC addresses, not IP addresses.

  • Downvote and give no reason why... seriously? – pleasedesktop Mar 31 '15 at 0:17

This is a simplified version of what happens:

The switch (assuming not a layer-3 switch) only involves itself with MAC addresses. This is where ARP comes into play. The sending PC will ARP, using the layer-3 address, and the receiving PC with that layer-3 address will respond with its layer-2 address. The sending PC then encapsulates the layer-3 packets into layer-2 frames, and the switch will switch the layer-2 frames.

| improve this answer | |
  • Thank you! I completely forgot about ARP, makes perfect sense now. I would upvote your answer, but I don't have enough rep. – pleasedesktop Mar 31 '15 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.