Switching and VLANs


Switching is a core component of networking, responsible for connecting devices within a network and efficiently forwarding data frames based on MAC addresses. VLANs (Virtual Local Area Networks) build upon switching to logically segment networks, improving performance, security, and manageability.

What is Switching?

Switches operate at Layer 2 of the OSI model, forwarding Ethernet frames based on MAC addresses. They maintain a MAC address table, mapping MAC addresses to specific switch ports, which allows them to send traffic only to the intended recipient instead of broadcasting it to all connected devices.

Types of Switching

What are VLANs?

A VLAN (Virtual Local Area Network) is a logical grouping of devices in a network, regardless of their physical location. VLANs segment a network into isolated sections, allowing devices in one VLAN to communicate only with others in the same VLAN unless explicitly permitted through routing.

Let's take a look at what a network would look like without VLANs.

What we have here are 5 different, logical and physical networks. The HR workstation cannot talk to the executive workstation, R&D cannot talk to Engineering, etc. Everyone is on their own island. While this might be the intended results, it would be expensive. If this was a single office, the switch closet would need to have 5 physical switches. We'd also need a router with 5 physical interfaces. This also equates to cost. Now imagine trying to manage 5 different networks. You have to stage 5 sets of updates, troubleshooting would take longer, etc.

So how can we make this more affordable and easier to manage without compromising our intended results? VLANs! Lets take a look at our network with VLANs.

Now we have a single office switch and each workstation is now connected to a respective VLAN. Even in this configuration, the workstations cannot talk to each other directly as there is no router. But you can see that there are 5 independent networks on a single switch. See how great VLANs are?

Benefits of VLANs

Configuring VLANs

Here’s an example of VLAN configuration on a Cisco switch:

# Create VLANs
Switch(config)# vlan 10
Switch(config-vlan)# name Accounting
Switch(config)# vlan 20
Switch(config-vlan)# name Sales

# Assign ports to VLANs
Switch(config)# interface FastEthernet0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config)# interface FastEthernet0/2
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 20

# Configure a trunk port
Switch(config)# interface GigabitEthernet0/1
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk allowed vlan 10,20

In this example:

Trunking and VLAN Tagging

Trunking allows multiple VLANs to be carried over a single link between switches. VLAN tagging uses the IEEE 802.1Q standard to add a VLAN ID to each Ethernet frame, ensuring that frames are correctly forwarded to their respective VLANs.

Key Trunking Concepts

Inter-VLAN Routing

While VLANs isolate traffic, devices in different VLANs often need to communicate. Inter-VLAN routing is used to route traffic between VLANs, typically achieved through a Layer 3 device like a router or Layer 3 switch.

Here’s an example of inter-VLAN routing configuration on a Layer 3 switch:

# Enable routing
Switch(config)# ip routing

# Create VLAN interfaces
Switch(config)# interface vlan 10
Switch(config-if)# ip address 192.168.10.1 255.255.255.0
Switch(config)# interface vlan 20
Switch(config-if)# ip address 192.168.20.1 255.255.255.0

Best Practices for VLANs

Advanced VLAN Topics

Once you’re comfortable with the basics, explore these advanced VLAN concepts:

Tools for Learning Switching and VLANs

Here are some tools to practice and explore switching and VLAN configurations:

Common Troubleshooting Tips

If VLANs or switches aren’t working as expected, try these steps:

Switching and VLANs are foundational concepts in networking. By mastering these, you’ll be equipped to design and manage scalable, efficient, and secure networks for any environment.