437 words
2 minutes
LAYER 2 Vlan, Spanning-tree, Trunk, EtherChannel, and Dot1Q Encapsulation
2021-09-14
2025-01-12

VLANs#

VLANs allow a switch to be divided into multiple parts.

  • Enhanced security, management, lower costs.
  • Limits broadcast domain > better performance.

There are two ways to create a VLAN:

vlan 10

Create VLAN 10.

int f0/1
switchport access vlan 10
% Access VLAN does not exist. Creating vlan 10

The f0/1 interface now has access to VLAN 10.

The no prefix allows you to delete a VLAN:

no vlan 10

Spanning-tree#

The spanning-tree prevents broadcast loops and assigns a path cost and priority to each VLAN.
It organizes an election based on each device’s BIDs (bridge ID) and MAC addresses.

NOTE

The lower the value, the higher the chance of the switch being elected as the “root bridge.”

TIP

The root bridge must be traversed to exit the local network.

You can set the priority of a VLAN:

Switch(config)#spanning-tree vlan 10 priority 8000
% Bridge Priority must be in increments of 4096.
% Allowed values are:
0 4096 8192 12288 16384 20480 24576 28672
32768 36864 40960 45056 49152 53248 57344 61440
NOTE

The BID must be one of the values listed above (power of 2).

  • You can force a VLAN to use a specific “root bridge,” regardless of BID:
spanning-tree vlan 10 root primary
  • If the root bridge fails, a backup can take over:
spanning-tree vlan 10 root secondary

Trunk#

The trunk allows one or more VLANs to be transmitted between multiple devices.
It effectively adds more ports to the primary switch.

Physical ViewLogical View

To configure a trunk link, configure the interface (the port) with these commands:

int f0/1
switchport mode trunk
TIP

If the configured devices are recent, the device on the other side of the trunk link can detect this link and configure itself automatically.

EtherChannel/PortChannel#

EtherChannel enables link aggregation (up to 8 links).
This increases bandwidth and provides redundancy/fault tolerance.

Example of a logical EtherChannel link

  • Select the interface range:
int range f0/1-2
  • Create EtherChannel link #1 on the interfaces:
channel-group 1 mode on

Here, “mode on” indicates manual mode.
You need to repeat these commands on the second switch.

TIP

Both physical links are treated as a single logical link: EtherChannel #1.

Dot1Q Encapsulation#

Encapsulation allows multiple VLANs to be routed over a single physical link.
The router tags frames to identify VLANs.
To do this, “sub-interfaces” need to be created.

int g0/0/0.10
  • Encapsulate frames for VLAN 10, according to IEEE 802.1Q standard.
encapsulation dot1Q 10
  • Define the IP address of the LAN interface for the specified VLAN.
ip address 192.168.10.1 255.255.255.0
  • 192.168.10.1 is the gateway for devices on VLAN 10.
WARNING

Don’t forget to enable the physical interface: g0/0/0

TIP

If you have multiple VLANs to configure, the commands are the same.
Just adapt them for your configuration.

Example of configuring Dot1Q encapsulation for VLAN 20:

int g0/0/0.20
encapsulation dot1Q 20
ip address 192.168.20.1 255.255.255.0
WARNING

Don’t forget to enable the physical interface: g0/0/0

Dot1Q Command Summary#

Copy/paste these lines (adapting to your configuration) into your terminal:

conf t
int g0/0/0.10
encapsulation dot1Q 10
ip address 192.168.10.1 255.255.255.0
no shut
LAYER 2 Vlan, Spanning-tree, Trunk, EtherChannel, and Dot1Q Encapsulation
https://xsec.fr/posts/networking/layer-2/
Author
Xsec
Published at
2021-09-14
License
CC BY-NC-SA 4.0