I've been using switch of ages but have no idea how it can recognize which of its port connected to the internet source. I used to think it recognizes the first cable connected to it as the router, but then how can the switch still work after an electrical outage?
1 Answer
The switch doesn't know or care about any of that stuff.
At first, it just receives a packet on one port and sends it out every other port. That connects everything just fine but wastes capacity. So, over time, it learns the hardware addresses of the devices on its ports and when it knows which port the device with a particular hardware address is on, it sends packets bound for that hardware address out only on that port.
It's the job of each machine on the network to address any packets they want to send over the Internet to the router's hardware address. It's the router's job to address any packets received from the Internet to the correct hardware address on the local network.