Network Technology Basics · Topic 2 of 2

Switching and Routing Basics

Learn MAC learning and flooding, VLANs and 802.1Q tags, access, trunk and hybrid ports, routing tables, route preference, static routes and VLANIF.

  • 6 min
In a nutshell
  • Switches learn source MAC addresses, forward known unicast and flood broadcast and unknown unicast.
  • 802.1Q tag: 4 bytes, 12-bit VLAN ID, usable range 1 to 4094; VLAN 1 is the default.
  • Huawei port types: access (one untagged VLAN), trunk (many tagged VLANs), hybrid (per VLAN choice).

What it is

Switching moves Ethernet frames between hosts in the same Layer 2 network, using MAC addresses. VLANs split one physical switch network into several separate broadcast domains.

Routing moves IP packets between different networks. A router looks up the destination address in its routing table and sends the packet to the next hop.

Host in VLAN 10Access switchforward by MACLayer 3 switch or routerroute by IPAccess switchHost in VLAN 20

How it works

How a switch forwards frames

A switch keeps a MAC address table that maps MAC addresses to ports. It handles every frame in three steps.

StepWhat the switch does
LearnRecords the frame's source MAC address and the port it arrived on
ForwardSends a frame for a known unicast MAC out of that one port
FloodSends broadcast, unknown unicast and (by default) multicast frames out of all other ports in the VLAN

Entries that are not refreshed age out, after 300 seconds by default on Huawei switches. A switch port is its own collision domain, but all ports in one VLAN share one broadcast domain.

VLANs

A VLAN is a logical Layer 2 network. Hosts in different VLANs cannot talk directly, even on the same switch; their traffic must be routed. VLANs limit broadcasts and separate traffic.

IEEE 802.1Q marks frames with a 4-byte VLAN tag inserted after the source MAC address. The tag holds a 12-bit VLAN ID, so IDs run from 0 to 4095, and 1 to 4094 can be used. VLAN 1 is the default VLAN on Huawei switches.

Port type (Huawei)Frames it sendsTypical connection
AccessUntagged, one VLAN onlyPCs and servers that do not tag
TrunkTagged for many VLANs; only the PVID's VLAN is sent untaggedSwitch to switch, switch to virtualization host
HybridTagged or untagged per VLAN, as configuredMixed cases; Huawei specific

The PVID (port default VLAN ID) is the VLAN an untagged incoming frame is placed in.

Example on a Huawei switch (VRP):

[Huawei] vlan batch 10 20
[Huawei] interface GigabitEthernet0/0/1
[Huawei-GigabitEthernet0/0/1] port link-type access
[Huawei-GigabitEthernet0/0/1] port default vlan 10
[Huawei-GigabitEthernet0/0/1] quit
[Huawei] interface GigabitEthernet0/0/24
[Huawei-GigabitEthernet0/0/24] port link-type trunk
[Huawei-GigabitEthernet0/0/24] port trunk allow-pass vlan 10 20

In FusionCompute, each port group on a distributed virtual switch can carry a VLAN ID. The host uplinks then connect to physical trunk ports that allow those VLANs.

The routing table

A router builds its routing table from three sources.

SourceHow the route appears
Direct routesAutomatically, for the subnets of the router's own up interfaces
Static routesConfigured by hand by the administrator
Dynamic routesLearned from routing protocols such as RIP, OSPF, IS-IS and BGP

Each entry holds the destination and mask, the protocol, the preference, the cost, the next hop and the outbound interface. On Huawei devices display ip routing-table shows it.

Choosing a route

The router picks a route in a fixed order.

Packet arrivesLongest prefix matchmost specific route winsSame prefix from several sourceslowest preference winsSame protocollowest cost winsForward to next hop
Route sourceDefault preference on Huawei
Direct0
OSPF10
IS-IS15
Static60
RIP100
OSPF ASE (external)150
BGP255

Lower preference is more trusted. Cost (metric) compares routes from the same protocol only.

Static and default routes

A static route names the destination, its mask and the next hop. A default route, 0.0.0.0/0, matches every destination and is used only when no more specific route exists.

[Huawei] ip route-static 10.2.2.0 24 192.168.1.2
[Huawei] ip route-static 0.0.0.0 0 203.0.113.1

Routing between VLANs

Each VLAN is its own subnet, so traffic between VLANs needs a Layer 3 hop. On a Huawei Layer 3 switch, a VLANIF interface gives a VLAN an IP address, which hosts use as their gateway.

[Huawei] interface Vlanif 10
[Huawei-Vlanif10] ip address 192.168.10.1 24

A worked example

PC A (192.168.10.5, VLAN 10) sends to PC B (192.168.20.5, VLAN 20). PC A sees a different subnet and sends the frame to its gateway, VLANIF 10 at 192.168.10.1.

The Layer 3 switch looks up 192.168.20.0/24, finds the direct route through VLANIF 20, and forwards the packet into VLAN 20. A static route to 192.168.0.0/16 or a default route would lose to this /24, the longest match.

How the exam asks about this

  • "What does a switch do with a frame whose destination MAC address is not in its MAC table?" → It floods the frame out of all other ports in the same VLAN.
  • "How many bits is the VLAN ID in an 802.1Q tag?" → 12 bits, giving usable VLANs 1 to 4094.
  • "A router has routes to 10.0.0.0/8 and 10.1.1.0/24. Which does it use for 10.1.1.9?" → 10.1.1.0/24, the longest prefix match.

What to remember for the exam

  • Switches learn source MAC addresses, forward known unicast and flood broadcast and unknown unicast.
  • 802.1Q tag: 4 bytes, 12-bit VLAN ID, usable range 1 to 4094; VLAN 1 is the default.
  • Huawei port types: access (one untagged VLAN), trunk (many tagged VLANs), hybrid (per VLAN choice).
  • Route selection: longest prefix first, then lowest preference, then lowest cost.
  • Huawei preferences: direct 0, OSPF 10, static 60, RIP 100; the default route is 0.0.0.0/0.
Watch out

Preference and cost are different. Preference compares routes from different protocols; cost compares routes within one protocol. Neither overrides the longest prefix match.

Common mistakes

Thinking a switch learns destination addresses. A switch learns only source MAC addresses. Destinations are looked up, never learned.

Thinking VLANs on one switch can talk directly. Different VLANs are different broadcast domains and subnets. Their traffic must pass a router or a VLANIF interface.

Choosing the route with the best preference first. The router first takes the most specific prefix. Preference only breaks ties between routes to the same prefix.

Check yourself

  • What is a PVID used for on a Huawei switch port?

    It is the default VLAN of the port. Untagged frames that arrive on the port are placed in that VLAN.

  • Which route does a Huawei router prefer for the same prefix: a static route or an OSPF route?

    The OSPF route, because its default preference of 10 is lower than the static route's 60.

  • What gives a VLAN an IP gateway on a Huawei Layer 3 switch?

    A VLANIF interface configured with an IP address in that VLAN's subnet.

Topic 2 of 2 in Network Technology Basics

Test yourself on Network Technology Basics

The full Huawei H13-511 question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Huawei. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.