Brian Ko
by Brian Ko
6 min read

Categories

  • Networking
  • OSI

Tags

  • Networking
  • Beginner

How do computer networks work? What the heck are IP addresses, switches, LANs, Routers? What do they all do?

First let’s answer the question: What is a network?

Generally, network is a ‘group or a system of interconnected people or things’. However, computer network is an interconnection of electronic devices that share resources with each other. Almost all devices are connected to some sort of network these days. Whether that’s LAN, Wifi, or cellular network, your device will have to be on a network to share data with others.

How does a network form?

For computers to talk to each other and form a network, they must follow the same rules as each other. These are what we call protocols. Set of rules governing the exchange of data between devices. To ensure that all devices follow the same protocol, the OSI model was developed in the 1970s. OSI(Open Systems Interconnection model) is a model that lays out the standards for devices to follow in order to connect to each other.

OSI Model is defined in 7 layers. (In this post, we will talk about the first two.)

  1. Physical
  2. Data Link
  3. Network
  4. Transport
  5. Session
  6. Presentation
  7. Application

The Physical Layer (1st) The first layer is about the physical connection between devices. It involves cable types (eg. ethernet/ fiber optics), how bits move in the cables, how they’re emitted/received, and everything you else need to physically transfer electronical data between one point to another.

Note: Normally signal or data can be “lost” if the cable is too long (about 100m). A Repeater’s job is to amplify the signal so it can travel further. Another note: A Hub is a multi port repeater. Whatever signal it receives from one port, it will pass it to all other ports.

The Data Link Layer(2nd) This layer controls communication between adjacent devices (Eg. Connection in LAN, PC to PC, PC to Switches/Routers, etc) and has protocol to establish/terminate connection between two nodes. Data unit at layer 2 is called a Frame.

A frame roughly looks like this:

Destination MAC Address Source MAC Address Data Frame Check Sequence

A MAC Address is an address of a device. It looks like FF:FF:FF:FF:FF:FF, where each F is a hexadecimal. Since each hex is 4 bits, a MAC address has 48 bits total.

When a device receives a frame, it will check to see if it’s destination address matches it’s own MAC address. If it sees that it matches, it’ll read the src address, the data, and the FCS.

FCS is sequence used for error detection. If frame was fully entacted, it’s hashed value should equal the FCS and if it does, we know that data hasn’t been lost or corrupted.

Devices that make up the 2nd layer:

Network Switches: (AKA switch hub, bridge or MAC bridge) that connects multiple devices. Instead of directly connecting a PC to another PC, switch is a “bridge” that connect multiple devices via an ethernet cable. A switch has a MAC address table that remembers which of its ports are connected to which MAC address(and thus the device). How does a switch know which MAC address belongs to what PC? Well, when it is unknown, the switch will flood all its port looking for that PC. If that PC exists, it will respond with a frame. The switch can read this frame’s src MAC and populate it’s table.

Hub: Again, whatever signal it receives from one port, it will pass through to all other ports. It’s different from switches as switches usually send to one address. However, switches can flood just like a hub.

Routers: More on this later, but router is like a layer 3 switch. If switches create a network by connecting local devices, routers connects those networks. Routers are connected to two or more different networks.

Concepts important in 2nd layer:

Collision domain: This is the part of the network that is prone to packet collision. Normally, data has to travel in one direction. If two devices send a frame to each other at the same time, collision can occur. Normally ports on switches prevent this but if PCs are connected via a hub, collision can occur.

Broadcast domain: This is the part of the network where broadcast is forwarded. It includes all devices that can reach other devices at layer 2. A direct connected PC, hub, and switches are all in one broadcast domain. However, router is a stopping point. Broadcasts don’t transfer through router to different networks.

LAN (Local Area Network): Network of your local network devices (PCs, hubs, switches, routers, phones) connected via ethernet or WiFi. It has an IP address that people often refer to as private IP. You need both this private IP and public IP to connect to other networks ( more info). Your home router/modem is the connection point between your LAN’s private IP and WAN’s public IP (this IP is the one that people see, given to you by your ISP)

WAN: Wide Area Network. This is network of networks. Basically the internet.

VLAN: Virtual LAN. Why? Say your switch only has 8 ports when you have 20 devices. You can make multiple VLANs with unique IP addresses so your router can distinguish it. (Note this separates the devices into different networks and they wont be able to broadcast to each other. If needed, they can be connected as if connecting different networks).

Now.. here’s a question. Does having 2 network switches make two LANs? No. Connecting a switch just expands that one network. Everything will still be under that one broadcasting domain. You can have however, multiple networks with 1 switch if you configure multiple VLANs. Doing this will create multiple broadcasting domains.

If PC1 in LAN1 or VLAN1 is trying to connect to PC2 in LAN2 or VLAN2, now the data has to traverse through the networks even if they may be on the same switch. This means connecting through Layer 3 using a router and the IP address of the networks.

Ports/Links: An endpoint of communication. Often refers to physical ethernet port of a device, but can be virtual. Ports have varying speed, slots and port number. Eg. fastEthernet 0/24. If making VLANs in 1 switch, you should assign physical(or virtual) ports to that VLAN to connect to it.

Access Port vs Trunking Port: Access ports are ports that are assigned to one VLAN. It needs to be configured, otherwise defaults to VLAN1. Trunk ports is a port that can be used for multiple VLANs. How? Each frame is tagged (802.1Q tags) and gets directed to the proper VLAN. You will need a trunk port between switches that connect several networks.

Spanning Tree Protocol: Prevents frames from looping around the network when redundant links/paths are present. As a network grows, there will be more than one path for a device to retrieve information from another device and there will exist a loop. Loops are BAD in networks. Why? If PCs continue to ask around who has x data from another PC in a loop while no one has the answer, it’ll congest the traffic and cause it to slow down or even fail. Loops can kill a network. We want to block loops to stop this from happening, and also to always use the fastest path possible to retrieve data when there are multiple routes. Spanning Tree Protocol does this by selecting root bridges, root ports, and root ports in segments that has priority path.