Deep-Learning Handbook · CCNA 200-301

CCNA 200-301
Deep Learning Handbook

A complete study guide to passing the Cisco CCNA certification and truly understanding modern networking principles. Rewritten from the Cisco public exam blueprint and official documentation, covering network fundamentals, switching, routing, IP services, WAN, security, and automation.

How to use: Chapters are ordered by exam weight. Sections marked high-frequency must be mastered; memory are mnemonic aids; commands are must-know CLI. Practice hands-on with Packet Tracer / GNS3.

Core Important Awareness Exam weight tiers

Deep-Learning Handbook · CCNA 200-301

CCNA 200-301
深度学习手册

一份面向通过思科 CCNA 认证、并真正理解现代网络原理的完整学习指南。基于思科公开考试大纲与官方文档重写,覆盖网络基础、交换、路由、IP 服务、WAN、安全与自动化。

使用建议:本手册按考试权重排列。标注 高频 的章节务必吃透;记忆 为速记口诀;命令 为必背 CLI。建议配合 Packet Tracer / GNS3 动手验证。

核心 重要 了解 考试权重分级

1OSI / TCP-IP Reference Model

Core Understanding the layered model is the foundation of all networking knowledge — it appears in almost every exam and is a prerequisite for every later chapter. If you only "memorize the seven layer names," you have not learned it. You must understand why we layer, what each layer does, and how data flows between layers.

1.1 Why Layering (understand the motivation first)

Networking is extremely complex: from electrical signals to application data, involving countless protocols, devices, and vendors. If all logic were crammed into one blob, any change would ripple everywhere. The essence of layering is divide and conquer:

  • Single responsibility per layer: each layer does only its own job and provides a standard interface to adjacent layers — layers are decoupled.
  • Vendor interoperability: as long as everyone follows the standard interface at each layer, vendor A's NIC can plug into vendor B's switch and run vendor C's application — this is what "open systems" means.
  • Independent evolution: upgrading an application-layer protocol (e.g., HTTP/2) does not require reworking the physical layer; changing fiber media does not affect upper-layer logic.
  • Easier troubleshooting: when a fault occurs, you locate it layer by layer, top-down or bottom-up — this is a network engineer's core working method, and both exams and interviews love to ask about it.

Two terms you must distinguish (exams love to split hairs):

  • Interconnectivity: being physically and methodologically connected — e.g., "two machines linked by a cable, data can travel from one node to another."
  • Interoperability: different vendors, different operating systems, different languages can mutually understand the data — e.g., a program on Windows and one on Linux communicate normally.

1.2 The OSI Seven-Layer Model, Layer by Layer

The OSI (Open Systems Interconnection) model is the de jure standard published by ISO (International Organization for Standardization) in 1984. The real world runs TCP/IP (the de facto standard), but OSI is the "anatomical chart" for understanding network responsibilities — used in both exams and troubleshooting.

LayerNamePDUCore responsibilityTypical protocolsTypical devices
7ApplicationDataNetwork service interface for applications; identifies communication peersHTTP, FTP, SMTP, DNS, Telnet, DHCP— (software)
6PresentationDataData format conversion, encryption, compression; ensures "the peer can understand"SSL/TLS, JPEG, ASCII, MPEG— (software)
5SessionDataEstablish, manage, terminate sessions; dialog control (who talks first)NetBIOS, RPC, SQL sessions— (software)
4TransportSegmentEnd-to-end connection; reliable delivery; flow control; port addressingTCP, UDP— (firewalls sometimes)
3NetworkPacketLogical addressing (IP); routing; fragmentationIP, ICMP, ARP, OSPF, RIPRouter
2Data LinkFramePhysical addressing (MAC); error detection; media access controlEthernet, PPP, HDLC, 802.11Switch, NIC
1PhysicalBitTransmit raw bitstream; electrical/mechanical/timing specsRJ-45, fiber, twisted pairHub, repeater, transceiver
PDU naming rule: each time data passes a layer, a header is added and the name changes — this is encapsulation in action. Layer 4 calls it a Segment, Layer 3 a Packet, Layer 2 a Frame, Layer 1 Bits. Layers 5-7 are collectively Data.

1.2.1 Layer-by-layer detail (exam deep-dive)

  • Layer 1 Physical: only cares about bits. Defines voltage levels, signal timing, connector shapes, pinouts (T568A/B), max distances. No addressing — it doesn't know "who sends to whom."
  • Layer 2 Data Link: groups bits into frames, addresses within the same physical segment (broadcast domain) using MAC addresses. Detects errors (FCS/CRC) and drops damaged frames. Split into LLC and MAC sublayers (see Chapter 2).
  • Layer 3 Network: addresses across networks (logical networks) using IP addresses and performs routing — "where does the packet go next." Routers care only about the destination IP, not TCP ports (that's Layer 4's job).
  • Layer 4 Transport: uses port numbers to distinguish different applications (processes) on the same host. TCP provides reliability, ordering, flow control; UDP provides best-effort.
  • Layers 5-7: Session manages "start/stop of the conversation," Presentation manages "the form of data (encryption/encoding)," Application manages "what service the user gets." In reality these three are usually merged in applications (e.g., HTTP + encryption live together in a browser).
Mnemonic: top-down "All People Seem To Need Data Processing" — initials A P S T N D P. Bottom-up: Physical, Data Link, Network, Transport, Session, Presentation, Application.

1.3 Encapsulation & De-encapsulation (the life of data)

Encapsulation: as data travels down the sender's stack, each layer adds its own header (and sometimes a trailer, e.g., Ethernet FCS) in front of the previous layer's data. De-encapsulation: the receiver goes up, peeling and checking each layer's header phases and passing the "payload" upward.

A real example — you browse http://www.example.com:

[Application] HTTP request message (GET / HTTP/1.1 + headers)
    ↓ handed to transport
[Transport]  Add TCP header (src port 54321, dst port 80, seq, window...) → Segment
    ↓ handed to network
[Network]    Add IP header (src 192.168.1.10, dst 93.184.216.34) → Packet
    ↓ handed to data link
[Data Link]  Add Ethernet header (src MAC, dst MAC = gateway's MAC) + FCS → Frame
    ↓ handed to physical
[Physical]   Become electrical/optical signals → Bits on the wire

At the far end, de-encapsulation in reverse: Physical receives bits → Data Link strips the MAC header, checks FCS → Network strips the IP header, checks if the destination IP is itself → Transport strips the TCP header and delivers to the process listening on port 80 (the web server).

Three high-frequency points: ① each layer only understands its own header, treating upper/lower content as a "transparent payload"; ② MAC addresses change at every hop (rewritten hop-by-hop by routers), while IP addresses stay the same end-to-end; ③ a router performs "de-encapsulate to Layer 3, then re-encapsulate" (strip MAC, look at IP, consult routing table, rewrite MAC, send out) — this is the key to understanding "routing."

1.4 Peer-to-Peer Communication

Another meaning of layering: only peers "talk" to each other. The sender's Layer 4 and the receiver's Layer 4 "logically communicate directly" (relayed through lower layers) — this is peer communication. Example: the TCP three-way handshake is a "conversation" between the two endpoints' transport layers; OSPF Hellos are a conversation between two routers' network-layer routing processes. Lower layers are just "couriers" that carry the upper-layer message unchanged.

Conceptually, each layer believes it is "directly connected" to its peer at the far end, relying on the services of the layer below. This is the Service Access Point (SAP) concept — each layer provides services to the layer above through a SAP.

1.5 The TCP/IP Model (the real-world standard)

TCP/IP is the de facto standard — the protocol stack the Internet actually runs. It merges the OSI seven layers into 4 (some textbooks teach 5, splitting the network access layer into data link + physical):

TCP/IP LayerOSI layersCore responsibilityTypical protocols
Application5+6+7Services for applications, incl. format & encryptionHTTP, HTTPS, DNS, DHCP, SMTP, FTP, SNMP
Transport4End-to-end reliable/best-effort delivery, port addressingTCP, UDP
Internet3Logical addressing & routingIP, ICMP, ARP, OSPF, EIGRP
Network Access1+2Physical transmission & frame encapsulationEthernet, PPP, 802.11
How to use the two models: describe with OSI (seven layers explain more clearly); classify protocols with TCP/IP (four layers). Many questions ask "which TCP/IP layer does XX belong to" — answer by the 4-layer scheme, not the 7-layer one.

1.6 Device-to-Layer Mapping (memorize this table)

DeviceLayerForwarding basisSplits collision domainsSplits broadcast domains
Repeater / HubL1None (regenerates signal, floods all ports)No (all ports one collision domain)No
Bridge / SwitchL2MAC address tableYes (one per port)No (one broadcast domain by default; VLANs can split)
RouterL3IP routing tableYesYes
FirewallL3-4 (some to L7)5-tuple / sessionYesYes
Wireless AP (bridge mode)L2MACYesNo

Collision domain: the set of devices that can "collide" if they transmit simultaneously. Each switch port is its own collision domain; full-duplex has no collisions. Broadcast domain: the set of devices a broadcast frame (dst MAC all-FF) can reach. Routers naturally isolate broadcast domains; switches need VLANs to do so.

1.7 Chapter Self-Test

Q1. What is application data called at the transport layer? At the network layer? At the data link layer?
Ans: Segment → Packet → Frame.

Q2. At which layer do a switch, router, and hub work? What do they forward on?
Ans: Switch L2 (MAC table); Router L3 (IP routing table); Hub L1 (no forwarding basis, broadcasts).

Q3. Data goes from host A to host B through 3 routers. How many times do the IP address and MAC address change?
Ans: IP never changes (end-to-end); MAC changes every hop (4 hops = 4 changes).

Q4. Which OSI layer handles encryption and compression? Which handles port addressing?
Ans: Presentation (L6) encryption/compression; Transport (L4) port addressing.

Q5. The TCP/IP "Application" layer corresponds to which OSI layers?
Ans: Layers 5+6+7 (Session + Presentation + Application).

1OSI / TCP-IP 参考模型

核心 理解分层模型是所有网络知识的地基,几乎每场考试都考,且是后续所有章节的概念前提。这一章如果只是"背七层名字",等于没学——你必须理解为什么分层、每层干什么、数据在层间怎么流动。

1.1 为什么要分层(先理解动机,再背结论)

网络极其复杂:从物理电信号到应用数据,涉及大量协议、设备和厂商。如果所有逻辑揉成一坨,任何改动都会牵一发动全身。分层的本质是分而治之(divide and conquer):

  • 每层职责单一:每层只做自己那一件事,并向上下层提供标准接口,层与层之间解耦。
  • 厂商可互操作:只要大家都遵守每层的标准接口,A厂商的网卡可以接B厂商的交换机、跑C厂商的应用——这就是"开放系统"的意义。
  • 可独立演进:升级应用层协议(如HTTP/2)不需要重做物理层;换光纤介质也不影响上层逻辑。
  • 便于排错:故障发生时可以从上到下(或从下到上)逐层定位——这是网络工程师的核心工作方法,考试和面试都爱问。

两个必须区分的术语(考试常抠字眼):

  • 互通性 / 互连性(Interconnectivity):物理上和信息传输方法上能连通——例如"用网线把两台机器连起来、数据能从一个节点传到另一个节点"。
  • 互操作性(Interoperability):不同厂商、不同操作系统、不同语言的计算机之间能互相理解数据——例如Windows和Linux上的两个程序能正常通信。

1.2 OSI 七层模型逐层精讲

OSI(Open Systems Interconnection)是 ISO(国际标准化组织)1984 年发布的法定标准(de jure standard)。现实世界跑的是 TCP/IP(事实标准),但 OSI 是理解网络职责划分的"解剖学图谱",考试和排错都要用它。

层名称PDU核心职责典型协议典型设备
7应用层 Application数据 Data为应用软件提供网络服务接口;识别通信对象HTTP, FTP, SMTP, DNS, Telnet, DHCP—(软件)
6表示层 Presentation数据 Data数据格式转换、加密、压缩;保证"对方能看懂"SSL/TLS, JPEG, ASCII, MPEG—(软件)
5会话层 Session数据 Data建立、管理、终止会话;对话控制(谁先说)NetBIOS, RPC, SQL会话—(软件)
4传输层 Transport段 Segment端到端连接;可靠传输;流量控制;端口寻址TCP, UDP—(防火墙有时归此层)
3网络层 Network包 Packet逻辑寻址(IP);路由选择;分片重组IP, ICMP, ARP, OSPF, RIP路由器
2数据链路层 Data Link帧 Frame物理寻址(MAC);差错检测;介质访问控制Ethernet, PPP, HDLC, 802.11交换机、网卡
1物理层 Physical比特 Bit传输原始比特流;电气/机械/时序规范RJ-45, 光纤, 双绞线集线器、中继器、收发器
PDU 名称变化规律:数据每经过一层,报头增加、名字改变——这是"封装"的直接体现。第4层叫段,第3层叫包,第2层叫帧,第1层叫比特。第5-7层统称数据。

1.2.1 逐层细节(考试深挖点)

  • 第1层物理层:只关心比特流。定义电压高低、信号时序、接口形状、线序(如T568A/B)、最大传输距离。没有地址概念,不知道"谁发给谁"。
  • 第2层数据链路层:把比特组成帧,用 MAC 地址 在同一物理网段(广播域)内寻址。负责差错检测(FCS/CRC),发现损坏帧就丢弃。分 LLC 和 MAC 两个子层(见第2章)。
  • 第3层网络层:用 IP 地址 在跨网段(逻辑网络)寻址,负责路由选择——"包下一跳去哪"。路由器只关心目的IP,不关心TCP端口(第4层的事)。
  • 第4层传输层:用 端口号 区分同一台主机上的不同应用(进程)。TCP 提供可靠、有序、流量控制;UDP 提供尽力而为。
  • 第5-7层:会话层管"对话的起止",表示层管"数据的形态(加密/编码)",应用层管"为用户提供什么服务"。现实中这3层通常合并在应用里(如浏览器里HTTP+加密都在)。
记忆口诀:从上到下 "All People Seem To Need Data Processing"(所有人似乎都需要数据处理)——首字母 A P S T N D P。中文版:应-表-会-传-网-数-物。反着背(从下到上):物-数-网-传-会-表-应。

1.3 封装与解封装(数据的一生)

封装(Encapsulation):发送方数据从上往下走,每一层在上一层数据前添加自己的报头(Header),有的层还加尾部(如以太网 FCS)。解封装(De-encapsulation):接收方从下往上,每层剥离并检查属于自己的报头,把"净载荷"交给上一层。

下面用一个真实例子串起来:你在浏览器访问 http://www.example.com 时数据怎么走。

[应用层]  HTTP 请求报文(GET / HTTP/1.1 + 头部)
    ↓ 交给传输层
[传输层]  加 TCP 头(源端口54321,目的端口80,序号,窗口…)→ 段 Segment
    ↓ 交给网络层
[网络层]  加 IP 头(源IP 192.168.1.10,目的IP 93.184.216.34)→ 包 Packet
    ↓ 交给数据链路层
[链路层]  加以太网头(源MAC,目的MAC=网关的MAC)+ 尾部FCS → 帧 Frame
    ↓ 交给物理层
[物理层]  变成电信号/光信号 → 比特 Bit 上线传输

到达对端后反向解封装:物理层收到比特→链路层剥MAC头检查FCS→网络层剥IP头看目的IP是否自己→传输层剥TCP头交给对应的端口(80)上的进程(Web服务器)。

三个高频考点:① 每一层只认自己的报头,对上下层内容视为"透明载荷";② MAC地址在每一跳都会变(源/目的MAC随路由器逐跳改写),IP地址在端到端之间不变;③ 路由器做"解封装到第3层再重新封装"(剥MAC、看IP、查路由表、换新MAC发出)——这是理解"路由"的关键。

1.4 对等通信(Peer-to-Peer Communication)

分层的另一层含义:只有同层才能"对话"。发送方的第4层和接收方的第4层"逻辑上直接通信"(中间经过下层的中转),这叫对等通信。例如:TCP 三次握手是两端传输层之间的"对话";OSPF Hello 是两端网络层路由进程的"对话"。下层只是"跑腿的",把上层报文原样搬运。

概念上:每一层都以为自己在和对端同层"直连",实际依赖下层提供的服务。这叫服务原语 / 服务接口(Service Access Point,SAP)——每层通过 SAP 向上一层提供服务。

1.5 TCP/IP 模型(现实标准)

TCP/IP 是事实标准(de facto standard)——Internet 实际运行的协议栈。它把 OSI 七层合并为 4 层(也有教材按 5 层讲,把"网络接入层"拆成链路层和物理层):

TCP/IP 层对应 OSI 层核心职责典型协议
应用层5+6+7为应用提供服务,含格式与加密HTTP, HTTPS, DNS, DHCP, SMTP, FTP, SNMP
传输层4端到端可靠/尽力传输,端口寻址TCP, UDP
网际层3逻辑寻址与路由IP, ICMP, ARP, OSPF, EIGRP
网络接入层1+2物理传输与帧封装Ethernet, PPP, 802.11
两种模型怎么用:考试描述用 OSI(七层讲得清楚);实际协议归类用 TCP/IP。很多题会问"XX协议属于TCP/IP哪一层"——答案按4层归,不是按7层归。

1.6 设备与层的对应(必背表)

设备工作层转发依据是否分割冲突域是否分割广播域
中继器/集线器 Hub第1层无(再生信号广播所有口)否(所有口在同一冲突域)否
网桥/交换机 Switch第2层MAC 地址表是(每端口一个冲突域)否(默认一个广播域,VLAN可分割)
路由器 Router第3层IP 路由表是是
防火墙 Firewall3-4层(部分到7层)五元组/会话是是
无线AP(桥接模式)第2层MAC是否

冲突域:两台设备同时发数据会"撞车"的范围。交换机每端口独立冲突域,全双工下无冲突。广播域:广播帧(目的MAC全FF)能到达的范围。路由器天然隔离广播域;交换机要用 VLAN 才能隔离。

1.7 本章自测(先做,再看答案)

Q1. 应用层数据在传输层被称为什么?在网络层?在链路层?
答:段(Segment)→ 包(Packet)→ 帧(Frame)。

Q2. 交换机、路由器、集线器分别工作在哪一层?转发依据是什么?
答:交换机第2层(MAC表);路由器第3层(IP路由表);集线器第1层(无转发依据,广播)。

Q3. 数据从主机A到主机B,途中经过3台路由器。请问IP地址和MAC地址分别改变几次?
答:IP地址不改变(端到端);MAC地址每跳都变(4跳=变4次)。

Q4. OSI 模型中哪一层负责加密和压缩?哪一层负责端口寻址?
答:表示层(第6层)加密压缩;传输层(第4层)端口寻址。

Q5. TCP/IP 模型的"应用层"对应 OSI 的哪几层?
答:第5+6+7层(会话+表示+应用)。

2Ethernet & the Data Link Layer

Core Ethernet is the de facto standard for almost all LANs, and the switch is its core device. This chapter is the prerequisite for switching (Chapters 5-8). After this chapter you should be able to answer: what is inside a frame? How is a MAC address structured? What does a switch forward on?

2.1 The Two Sublayers of the Data Link Layer

The data link layer (Layer 2) is subdivided into two sublayers, per the IEEE 802 family of standards:

  • LLC (Logical Link Control) — the upper sublayer, interfaces with Layer 3, identifies the upper-layer protocol type (IPv4 or IPv6), and provides a uniform interface via SAP (Service Access Point). Its core value: letting Layer 2 "generically" carry multiple Layer-3 protocols.
  • MAC (Media Access Control) — the lower sublayer, responsible for two big jobs: ① physical addressing (source/destination MAC addressing in frames); ② media access control (deciding "who may transmit on a shared medium" — the collision-avoidance mechanism CSMA/CD or CSMA/CA).

You must clearly distinguish the two media access mechanisms:

MechanismFull nameHow it worksUsed by
CSMA/CDCarrier Sense Multiple Access / Collision DetectionListen before send, listen while sending, back off and retransmit after a collisionWired Ethernet (half-duplex era)
CSMA/CACarrier Sense Multiple Access / Collision AvoidanceListen before send, wait actively (DIFS + random backoff), confirm with ACK, avoid collisionsWireless (802.11)
Why can't wireless use CD? A wireless device cannot "listen while transmitting" (its own signal drowns out incoming signals), and there is the "hidden node" problem (A can hear B, C can hear B, but A and C cannot hear each other). So wireless uses CA (avoid), wired half-duplex uses CD (detect). Modern switched networks are full-duplex, so CSMA/CD is no longer needed — exams love this point.

2.2 The Ethernet Frame Structure (tear a frame apart)

The 802.3 Ethernet frame (base frame, no VLAN tag) consists of these fields — exams often test "what does each field do":

FieldLengthPurpose
Preamble7 bytesClock synchronization so the receiver can "align" the bitstream (not part of the frame)
SFD (Start Frame Delimiter)1 byteMarks the frame start (10101011)
Destination MAC6 bytesReceiver (unicast / multicast / broadcast)
Source MAC6 bytesSender
Length / Type2 bytes≤1500 means length (802.3); ≥1536 means upper-layer protocol type (0x0800=IPv4, 0x0806=ARP, 0x86DD=IPv6)
Payload46-1500 bytesUpper-layer data (Layer-3 packet); padded if under 46 bytes
FCS (Frame Check Sequence)4 bytesCRC check; the receiver drops damaged frames

Minimum frame size is 64 bytes (excluding preamble): dst 6 + src 6 + type 2 + data 46 + FCS 4 = 64. Why 64? So that in half-duplex a collision can always be detected — the sender must still be transmitting when the signal reaches the far end and returns (the round-trip time, RTT). This is the classic CSMA/CD derivation; exams sometimes ask "why is the minimum frame 64 bytes."

2.3 The Ethernet Standard Family (speed × media)

IEEE 802.3 defines the physical layer and the MAC part of the data link layer. Naming rule: speed + BASE (baseband) + media. T = twisted pair, SX = short-wavelength multimode fiber, LX = long-wavelength single-mode fiber, SR/LR = 10G fiber (short/long reach).

NameSpeedMediaMax distanceCommon interface
10BASE-T10 MbpsCat3+ twisted pair100 mRJ-45
100BASE-TX100 MbpsCat5 twisted pair100 mRJ-45
1000BASE-T1 GbpsCat5e/6 twisted pair100 mRJ-45
1000BASE-SX1 GbpsMultimode fiber220-550 mLC/SC
1000BASE-LX1 GbpsSingle/multimode fiber~5 km (SMF) / 550 m (MMF)LC/SC
10GBASE-T10 GbpsCat6a/7 twisted pair100 m (Cat6a) / 55 m (Cat6)RJ-45
10GBASE-SR10 GbpsMultimode fiber~300 mLC
10GBASE-LR10 GbpsSingle-mode fiber~10 kmLC
Memory: twisted pair is always 100 m max; fiber depends on wavelength (SX short/multimode-near, LX long/single-mode-far). Gigabit copper needs Cat5e; 10G copper needs Cat6a.

2.4 Twisted Pair & Pinouts (hands-on knowledge)

Twisted pair cabling has two termination styles:

  • Straight-through: same pinout at both ends (both T568A or both T568B). Used between unlike devices: PC↔switch, switch↔router, PC↔hub.
  • Crossover: T568A at one end, T568B at the other (pins 1-3, 2-6 swapped). Used between like devices: PC↔PC, switch↔switch, PC↔router. Modern devices have Auto-MDIX, so crossover cables are rarely needed, but the exam still covers them.

T568B pinout: white-orange, orange, white-green, blue, white-blue, green, white-brown, brown (remember "orange, green, blue, brown").

2.5 MAC Address Deep Dive (physical address)

A MAC address is 48 bits (6 bytes) in hexadecimal, burned into the NIC ROM, used for Layer-2 frame addressing. Formats: 00:1A:2B:3C:4D:5E (colon), 001A.2B3C.4D5E (Cisco dotted), or 00-1A-2B-3C-4D-5E (hyphen).

  • First 24 bits (3 bytes) = OUI (Organizationally Unique Identifier), assigned by IEEE to vendors — the first 3 bytes identify the vendor.
  • Last 24 bits (3 bytes) = vendor-assigned serial number (unique per NIC).
  • Least significant bit of byte 1 (I/G bit): 0 = unicast, 1 = multicast.
  • Second-least significant bit (U/L bit): 0 = globally unique (factory), 1 = locally administered (changeable, e.g., MAC randomization).
  • Broadcast address: FF:FF:FF:FF:FF:FF (all 48 bits 1), reaches all hosts in the broadcast domain.
  • Common multicast MACs: 01:00:5E:xx:xx:xx (IPv4 multicast), 01:80:C2:00:00:00 (STP BPDUs), 01:80:C2:00:00:08 (PAgP), 01:00:0C:CC:CC:CC (CDP/VTP).
Common confusions: ① MAC is a "flat" address (no hierarchy), IP is "hierarchical" (network + host) — so MAC tables cannot aggregate but IP routes can; ② switches forward on MAC, routers forward on IP; ③ within a broadcast domain you communicate by MAC directly; across broadcast domains you must pass routers, changing MAC every hop.

2.6 Switch vs Hub vs Router (deep comparison)

DeviceOSI layerForwarding basisCollision domainsBroadcast domainsLearns addresses
HubL1None (regenerates signal, floods all ports)1 (all ports share)1No
SwitchL2MAC address tableOne per port (full-duplex = none)1 (VLANs can split)Yes (learns MACs)
RouterL3IP routing tableOne per interfaceOne per interface (isolates)Yes (learns routes)

Collision domain: the set of devices that could "collide" if they transmit at the same time. A hub puts all ports in one collision domain; a switch gives each port its own (full-duplex eliminates collisions entirely). Broadcast domain: the set of devices a broadcast frame can reach. Routers create one per interface (natural isolation); switches do not isolate by default (except with VLANs).

2.7 The Switch MAC Table & Forwarding Process (walk through one example)

A switch boots with an empty MAC table. Here is a complete walk-through (4 PCs connected to SW1's F0/1-F0/4):

1. PC-A (F0/1) sends a frame to PC-C (F0/3):
   - SW1 checks the source MAC: not in table → learn it (F0/1 port)
   - SW1 checks the destination MAC 0000.3333.CCCC: not in table → flood to all ports (except F0/1)
   - PC-C receives it (it is the addressee); the other ports drop it
2. PC-C replies to PC-A:
   - SW1 learns PC-C's MAC (F0/3 port)
   - SW1 checks destination 0000.1111.AAAA: in table now → forward only out F0/1 (no flood)
3. From now on, PC-A ↔ PC-C traffic is forwarded precisely, not disturbing other ports

Three behaviors summarized: unknown unicast / broadcast → flood; known unicast → forward precisely; destination on the receiving port → drop. MAC table entries age out after 300 seconds (5 min) by default to avoid stale entries.

Memory: a switch is a "learning device" — it learns from source addresses and forwards on destination addresses; if it hasn't learned, it floods. That is the whole secret of Layer-2 switching.

2以太网与数据链路层

核心 以太网是绝大多数局域网的事实标准,交换机是其核心设备。本章是交换技术(第5-8章)的前提。学完本章你要能回答:一个帧里有什么?MAC地址怎么构成?交换机凭什么转发?

2.1 数据链路层的两个子层

数据链路层(第2层)细分为两个子层,这个划分是 IEEE 802 系列标准的约定:

  • LLC(Logical Link Control,逻辑链路控制)——上面那层,负责与网络层(第3层)交互,识别上层协议类型(如IPv4还是IPv6),通过 SAP(服务访问点) 提供统一接口。它的核心价值:让第2层可以"通用地"承载多种第3层协议。
  • MAC(Media Access Control,介质访问控制)——下面那层,负责两件大事:① 物理寻址(源/目的MAC地址的封装与识别);② 介质访问控制(决定"谁能在共享介质上发送"——即冲突避免机制 CSMA/CD 或 CSMA/CA)。

介质访问控制两种机制必须分清:

机制全称工作原理用于
CSMA/CD载波侦听多路访问 / 冲突检测先听后发,边发边听,冲突后随机退避重发有线以太网(半双工时代)
CSMA/CA载波侦听多路访问 / 冲突避免先听后发,发前主动等待(DIFS+随机退避),用ACK确认,尽量避免冲突无线(802.11)
为什么无线不能用 CD?无线设备无法"边发边听"(自己发射的信号会淹没收到的信号),而且存在"隐藏节点"问题(A能听到B、C能听到B,但A和C互相听不到)。所以无线用 CA(避免),有线半双工用 CD(检测)。现代交换网络全双工后,CSMA/CD 已不再需要——考试爱考这一点。

2.2 以太网帧结构(把帧拆开看)

802.3 以太网帧(不带VLAN标签的基础帧)由以下字段组成,考试常考"各字段作用":

字段长度作用
前导码 Preamble7字节同步时钟,让接收方"对齐"比特流(非帧内容)
SFD 帧起始定界符1字节标记帧开始(10101011)
目的MAC6字节接收者(单播/多播/广播)
源MAC6字节发送者
长度/类型 Type2字节≤1500表示长度(802.3);≥1536表示上层协议类型(如0x0800=IPv4,0x0806=ARP,0x86DD=IPv6)
数据 Payload46–1500字节上层载荷(第3层包);不足46字节要填充
FCS 帧校验4字节CRC校验,接收方发现损坏即丢弃

帧最小64字节(不含前导码):目的6+源6+类型2+数据46+FCS4=64。为什么最小64?为了保证半双工下"冲突能被检测到"——信号传到最远端再返回的往返时间(RTT)内必须发完,否则发方无法感知冲突。这是 CSMA/CD 的经典推导,考试偶尔考"最小帧长为什么是64字节"。

2.3 Ethernet 标准家族(速率×介质)

IEEE 802.3 定义了物理层和数据链路层 MAC。命名规则:速率 + BASE(基带)+ 介质。T=双绞线,SX=短波多模光纤,LX=长波单模光纤,SR/LR=10G光纤(短/长距离)。

名称速率介质最大距离常见接口
10BASE-T10 MbpsCat3+ 双绞线100 mRJ-45
100BASE-TX100 MbpsCat5 双绞线100 mRJ-45
1000BASE-T1 GbpsCat5e/6 双绞线100 mRJ-45
1000BASE-SX1 Gbps多模光纤220–550 mLC/SC
1000BASE-LX1 Gbps单模/多模光纤~5 km(单模)/550m(多模)LC/SC
10GBASE-T10 GbpsCat6a/7 双绞线100 m(Cat6a)/55m(Cat6)RJ-45
10GBASE-SR10 Gbps多模光纤~300 mLC
10GBASE-LR10 Gbps单模光纤~10 kmLC
记忆:双绞线一律100米封顶;光纤看波长(SX短/多模近,LX长/单模远)。千兆铜线用Cat5e,万兆铜线用Cat6a。

2.4 双绞线与线序(动手知识)

双绞线分两种接法:

  • 直通线(Straight-through):两端线序相同(都T568A或都T568B)。用于不同类型的设备:PC↔交换机、交换机↔路由器、PC↔集线器。
  • 交叉线(Crossover):一端T568A一端T568B(1-3、2-6对调)。用于同类设备:PC↔PC、交换机↔交换机、PC↔路由器。现代设备有 Auto-MDIX 自动识别,交叉线已很少需要,但考试仍考。

T568B 线序:白橙-橙-白绿-蓝-白蓝-绿-白棕-棕(记住"橙绿蓝棕"的配色规律)。

2.5 MAC 地址(物理地址)深解

MAC 地址是 48 位(6 字节) 的十六进制地址,烧录在网卡(NIC)ROM 中,用于第2层帧寻址。书写格式:00:1A:2B:3C:4D:5E(冒号)、001A.2B3C.4D5E(Cisco点分)或 00-1A-2B-3C-4D-5E(连字符)。

  • 前 24 位(3字节)= OUI(Organizationally Unique Identifier,组织唯一标识符),由 IEEE 分配给厂商——看到前3字节就能知道是哪家厂商(如 00:1A:2B 是某厂商)。
  • 后 24 位(3字节)= 厂商自定的序列号(NIC 唯一)。
  • 第1字节最低位(I/G位):0 = 单播(发给一个主机)、1 = 多播/组播(发给一组主机)。
  • 第1字节次低位(U/L位):0 = 全局唯一(出厂),1 = 本地管理(可改,如MAC随机化)。
  • 广播地址:FF:FF:FF:FF:FF:FF(48位全1),发给广播域内所有主机。
  • 常见组播 MAC 示例:01:00:5E:xx:xx:xx(IPv4组播映射),01:80:C2:00:00:00(STP BPDU 目的MAC),01:80:C2:00:00:08(PAgP),01:00:0C:CC:CC:CC(CDP/VTP)。
易混点:① MAC 是"平面"地址(无层次),IP 是"层次"地址(网络+主机)——所以 MAC 表不能聚合、IP 路由可以聚合;② 交换机转发看 MAC,路由器转发看 IP;③ 同一广播域内用 MAC 直接通信,跨广播域必须经路由器、每跳换 MAC。

2.6 交换机 vs 集线器 vs 路由器(深比)

设备OSI层转发依据冲突域广播域是否学习地址
集线器 Hub第1层无(物理层再生信号,广播到所有口)1个(所有口共享)1个否
交换机 Switch第2层MAC 地址表每端口1个(全双工无冲突)1个(VLAN可分割)是(动态学习MAC)
路由器 Router第3层IP 路由表每接口1个每个接口1个(隔离)是(学路由)

冲突域:可能发生"同时发送撞车"的设备集合。集线器所有口一个冲突域;交换机每个口独立冲突域,全双工下彻底消除冲突。广播域:广播帧能到达的设备集合。路由器每接口一个广播域,天然隔离;交换机默认不隔离广播(除非配VLAN)。

2.7 交换机的 MAC 地址表与转发流程(模拟一次)

交换机启动时 MAC 表为空。看一个完整流程(4台PC接在SW1的F0/1-F0/4):

1. PC-A(F0/1) 发帧给 PC-C(F0/3):
   - SW1 查源MAC:表中无 0000.1111.AAAA → 学进表(F0/1口)
   - SW1 查目的MAC 0000.3333.CCCC:表里没有 → 泛洪到所有口(除F0/1)
   - PC-C 收到(它就是要找的人),其他口丢弃
2. PC-C 回帧给 PC-A:
   - SW1 学进 PC-C 的 MAC(F0/3口)
   - SW1 查目的 0000.1111.AAAA:表里有了 → 只从 F0/1 转发(不再泛洪)
3. 此后 PC-A ↔ PC-C 的帧都精确转发,不打扰其他口

三种行为总结:未知单播/广播 → 泛洪;已知单播 → 精确转发;目的在接收口上 → 丢弃(目的和源在同一个口,说明目的在本地)。MAC 表老化默认 300 秒(5分钟),防止陈旧条目占用表项。

记忆:交换机是"学习型设备"——看源地址学、看目的地址转;学不到的泛洪。这就是"二层交换"的全部秘密。

3Network Layer · IP Addressing & Subnetting

Core IP addressing and subnetting are the heaviest CCNA exam topics — calculation questions are almost guaranteed, and it is the foundation of all network troubleshooting. This chapter must be drilled to "reflex level": given an IP+mask, compute the network address, broadcast address, usable range, and subnet count within seconds.

3.1 IPv4 Address Structure (solidify the basics)

An IPv4 address is a 32-bit binary number written in dotted decimal (4 octets, 8 bits each, range 0-255). It has two parts: Network bits (which network are you in) + Host bits (which host are you within that network). The Subnet Mask marks network bits with consecutive 1s and host bits with 0s.

IP     :  192.168.10.5
Binary :  11000000.10101000.00001010.00000101
Mask   :  255.255.255.0   = /24
Mask binary: 11111111.11111111.11111111.00000000
               ←—— 24 network bits ——→ ←8 host bits→

Network address = IP AND Mask = 192.168.10.0  (host bits all 0)
Broadcast address = network + host bits all 1 = 192.168.10.255
Usable hosts = 192.168.10.1 - 192.168.10.254  (254 total)
The only correct way to compute a network address: AND the IP and mask — 1 AND 1 = 1, everything else = 0. Mental shortcut: where the mask is 255, keep the IP as-is; where the mask is 0, set to 0; where the mask is intermediate (like 240), align to the block size. That mental shortcut is the key to exam-speed subnetting — see 3.4.

3.2 Binary ↔ Decimal Conversion (must be fluent)

Each octet's bit weights (high to low):

128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
 1    1    0    0    1    0   1   0   = 128+64+8+2 = 202

Must-memorize decimal values (instant exam recall):

Binary (ones)DecimalMeaning
10000000128/25 mask last octet
11000000192/26 mask last octet
11100000224/27 mask last octet
11110000240/28 mask last octet
11111000248/29 mask last octet
11111100252/30 mask last octet
11111111255full octet

Power table (memorize to 2^10): 2^0=1, 2^1=2, 2^2=4, 2^3=8, 2^4=16, 2^5=32, 2^6=64, 2^7=128, 2^8=256, 2^9=512, 2^10=1024. Subnetting uses 2^n and 2^m-2 every day.

3.3 Address Classes (Classful) & Default Masks

Historically the first octet determined 5 classes. Although we now use classless (CIDR), the class concept is still exam fundamentals:

ClassFirst octet binaryFirst octet decimalDefault maskNetworks/hostsUse
A0xxxxxxx1-126255.0.0.0 (/8)126 nets / 16,777,214 hostsVery large
B10xxxxxx128-191255.255.0.0 (/16)16,384 nets / 65,534 hostsMedium
C110xxxxx192-223255.255.255.0 (/24)2,097,152 nets / 254 hostsSmall
D1110xxxx224-239— (multicast)—Multicast
E1111xxxx240-255— (reserved)—Research
Must-know traps: ① 127.0.0.0/8 is the loopback range (self-test), NOT part of class A's usable networks — so class A is 1-126, not 1-127; ② first octet 0 (0.0.0.0) means "this network / unspecified", not usable; ③ 224+ is multicast, cannot be assigned to hosts; ④ 169.254.0.0/16 is APIPA (automatic link-local addressing when DHCP fails).

3.4 Subnetting Core Skill (the most important section)

Subnetting: "borrow" host bits to become subnet bits, splitting one network into multiple logical subnets. Goals: segment by department/floor, shrink broadcast domains, save addresses, simplify routing.

Two golden formulas (memorize blindfolded):

Number of subnets          = 2^n        (n = host bits borrowed)
Usable hosts per subnet    = 2^m - 2    (m = remaining host bits, minus 2 for network+broadcast)

Step-by-step problem-solving flow (the fixed exam pattern):

Look at the mask, count borrowed bits: convert mask to binary, count the extra 1s beyond the default mask (/8,/16,/24) = n.
Subnets = 2^n.
Usable hosts per subnet = 2^m - 2 (m = number of 0s in the mask).
Block size (increment) = 256 - the decimal value of the "non-255" octet. E.g., /26 mask 255.255.255.192 → block = 256-192 = 64.
List subnets starting at 0, adding the block each time: 0, 64, 128, 192. Each subnet's network address = block start, broadcast = next block start - 1, usable = in between.
Align the IP to the nearest block start — that is its subnet.
Instant-recall rule: "Block size = 256 - mask's last octet". Mask last octet 192→block 64; 240→16; 224→32; 248→8; 252→4. Subnets start at 0 and add the block. The largest block start ≤ the IP is that IP's network address.

3.4.1 Full example: subnet a network (work through it)

Problem: company has 192.168.10.0/24, needs 6 departments, each ≤ 25 hosts. How?

① Need ≥6 subnets: 2^n ≥ 6 → n = 3 (2^3 = 8 subnets, enough)
② Borrow 3 bits → mask /27 (255.255.255.224), 5 host bits left
③ Usable hosts per subnet = 2^5 - 2 = 30 ≥ 25 ✓
④ Block size = 256 - 224 = 32
⑤ Subnet table:
   Subnet 0:  192.168.10.0   broadcast 192.168.10.31   usable .1-.30
   Subnet 1:  192.168.10.32  broadcast 192.168.10.63   usable .33-.62
   Subnet 2:  192.168.10.64  broadcast 192.168.10.95   usable .65-.94
   Subnet 3:  192.168.10.96  broadcast 192.168.10.127  usable .97-.126
   Subnet 4:  192.168.10.128 broadcast 192.168.10.159  usable .129-.158
   Subnet 5:  192.168.10.160 broadcast 192.168.10.191  usable .161-.190
   Subnet 6:  192.168.10.192 broadcast 192.168.10.223  usable .193-.222
   Subnet 7:  192.168.10.224 broadcast 192.168.10.255  usable .225-.254

3.4.2 Full example: given an IP, find the three essentials

Problem: IP 172.16.35.123, mask 255.255.240.0 (/20). Find network, broadcast, usable range.

① Mask 255.255.240.0 → third octet is 240, block = 256-240 = 16
② Third octet 35 aligns to a multiple of 16: 16×2=32 ≤ 35 < 48=16×3 → third octet = 32
③ Network address = 172.16.32.0
④ Broadcast = network + block - 1 (affects the 240 octet and below)
   = 172.16.(32+16-1).255 = 172.16.47.255
⑤ Usable range = 172.16.32.1 ~ 172.16.47.254
⑥ Usable hosts = 2^(32-20) - 2 = 2^12 - 2 = 4094

3.4.3 Special mask quick table (within /24)

MaskCIDRBorrow nSubnets 2^nUsable hosts 2^m-2Block size
255.255.255.0/2401254256
255.255.255.128/2512126128
255.255.255.192/26246264
255.255.255.224/27383032
255.255.255.240/284161416
255.255.255.248/2953268
255.255.255.252/3066424
Exam reminder: a /30 subnet (4 addresses, 2 usable) is specifically for point-to-point links (router-to-router), wasting nothing — the classic "why /30" question. /31 and /32 are special (/31 for point-to-point without broadcast, /32 for single-host routes); know them, don't overthink.

3.5 VLSM (Variable-Length Subnet Masks)

VLSM: use different length masks within one major network, allocating addresses by each subnet's actual need to avoid waste. Allocation order: start with the subnet needing the most hosts, use the biggest block, then work down (large block first).

Example: 192.168.1.0/24 must serve: A=50 hosts, B=25, C=10, D=2.

① A(50)  needs 2^6-2=62 → /26, block 64 → 192.168.1.0/26  (.0-.63)
② B(25)  needs 2^5-2=30 → /27, block 32 → 192.168.1.64/27 (.64-.95)
③ C(10)  needs 2^4-2=14 → /28, block 16 → 192.168.1.96/28 (.96-.111)
④ D(2)   needs 2^2-2=2  → /30, block 4  → 192.168.1.112/30 (.112-.115)
Rest from .116 onward reserved for future growth (blocks must align)

3.6 CIDR & Route Summarization (Supernetting)

CIDR (Classless Inter-Domain Routing): slash notation (/8~/32) replaces classful A/B/C limits. It enables two powers:

  • VLSM: different prefix lengths inside one network (see 3.5).
  • Route summarization (supernetting): merge multiple contiguous small networks into one larger route entry, shrinking the routing table. E.g., four /24s (192.168.0.0, .1.0, .2.0, .3.0) summarize to 192.168.0.0/22.

Summary rule: find the common prefix bits. 192.168.0.0/24 = 11000000.10101000.00000000..., 192.168.3.0/24 shares the first 22 bits → summarize as /22.

3.7 ARP & ICMP (the network layer's left and right hands)

Not addressing per se, but they are the protocols IP works with — exams love them:

  • ARP (Address Resolution Protocol): given a destination IP, find the destination's MAC within the same broadcast domain. Process: check ARP cache → if absent, broadcast "who is 192.168.1.1?" → the target unicasts a reply → cache it (timeout ~2-4 min; Cisco default 4 hours). ARP sits between L2 and L3 (works at the link layer, serves the network layer). When crossing networks, the frame's destination MAC is the gateway's MAC, NOT the destination host's MAC — the most common misconception.
  • ICMP (Internet Control Message Protocol): error reporting and network diagnostics. ping uses ICMP Echo Request/Reply; traceroute uses ICMP TTL-exceeded. ICMP carries no user data; it is IP's "messenger."

3.8 Chapter Self-Test (subnet questions must be 100%)

Q1. How many subnets in 192.168.1.0/26? Usable hosts per subnet? Network and broadcast of the 2nd subnet?
Ans: 2 borrowed → 4 subnets; hosts 2^6-2=62; 2nd (index 1) = 192.168.1.64, broadcast 192.168.1.127.

Q2. IP 10.10.10.100 mask 255.255.255.240 — network address?
Ans: block 16, 100 aligns to 96 → 10.10.10.96.

Q3. Connecting two routers — which mask wastes the least addresses?
Ans: /30 (255.255.255.252), 2 usable hosts.

Q4. 172.16.5.0/24 split into 5 subnets of ≤20 hosts — mask?
Ans: 20 hosts needs 2^5-2=30 → 5 host bits → /27 (255.255.255.224), subnets 2^3=8≥5.

Q5. Host A (192.168.1.10/24) reaches host B (192.168.2.20/24) — whose MAC is the destination in the frame?
Ans: the default gateway's MAC — cross-network frames use the gateway as destination MAC.

3网络层 · IP 编址与子网

核心 IP 编址与子网划分是 CCNA 最重头的考点,几乎必考计算题,也是所有网络排错的基础。这一章必须练到"条件反射"级:给一个 IP+掩码,几秒钟内算出网络号、广播号、可用范围、子网数量。

3.1 IPv4 地址结构(先把基础夯实)

IPv4 地址是 32 位二进制数,用点分十进制表示(4个八位组,每组8位,范围0-255)。它天生分两部分:网络位(Network bits,标识"你在哪个网络")+ 主机位(Host bits,标识"你是这个网络里的第几台主机")。子网掩码(Subnet Mask) 用连续的1标记网络位、0标记主机位。

IP     :  192.168.10.5
二进制 :  11000000.10101000.00001010.00000101
掩码   :  255.255.255.0   = /24
掩码二进制: 11111111.11111111.11111111.00000000
               ←—— 24位网络位 ——→ ←8位主机位→

网络地址 = IP AND 掩码 = 192.168.10.0     (主机位全0)
广播地址 = 网络地址+主机位全1 = 192.168.10.255
可用主机 = 192.168.10.1 - 192.168.10.254  (共254个)
计算网络地址的唯一正确方法:把 IP 和掩码做逻辑与(AND)运算——1 AND 1 = 1,其余=0。也可以心算:掩码是255的位,IP原样保留;掩码是0的位,全部置0;掩码介于中间的位(如240),按块大小对齐。后者是考试秒算的关键,见3.4。

3.2 二进制↔十进制转换(必须熟练)

八位二进制每一位的权重(从高位到低位):

128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
 1    1    0    0    1    0   1   0   = 128+64+8+2 = 202

几个必背的十进制值(考试秒用):

二进制(1的个数)十进制含义
10000000128/25 掩码末位
11000000192/26 掩码末位
11100000224/27 掩码末位
11110000240/28 掩码末位
11111000248/29 掩码末位
11111100252/30 掩码末位
11111111255整段

幂次表(背到2^10):2^0=1, 2^1=2, 2^2=4, 2^3=8, 2^4=16, 2^5=32, 2^6=64, 2^7=128, 2^8=256, 2^9=512, 2^10=1024。子网计算里 2^n 和 2^m-2 天天用。

3.3 地址类别(Classful)与默认掩码

早期按首八位划分5类。现在虽然用无类(CIDR),但类别概念仍是考试基础:

类首八位二进制首八位十进制默认掩码网络数/主机数用途
A0xxxxxxx1–126255.0.0.0 (/8)126网 / 16,777,214主机超大型网络
B10xxxxxx128–191255.255.0.0 (/16)16,384网 / 65,534主机中型网络
C110xxxxx192–223255.255.255.0 (/24)2,097,152网 / 254主机小型网络
D1110xxxx224–239—(组播)—组播 Multicast
E1111xxxx240–255—(保留)—实验研究
必背陷阱:① 127.0.0.0/8 是环回地址(本机自测),不属于A类可用网络——所以A类网络是1-126,不是1-127;② 首字节0(0.0.0.0)表示"本网络/未指定",不能用;③ 224+是组播,不能配主机;④ 169.254.0.0/16 是 APIPA(DHCP 失败时 Windows 自动配置的链路本地地址)。

3.4 子网划分核心技能(重点中的重点)

子网划分:把一个大网络的主机位"借"几位出来当子网位,从而拆成多个逻辑子网。目的:按部门/楼层隔离、减少广播域、节省地址、简化路由。

两条黄金公式(必须闭眼能背):

子网数量        = 2^n        (n = 从主机位借用的位数)
每个子网可用主机数 = 2^m - 2    (m = 剩余的主机位数,减2去掉网络号和广播号)

一步步的解题流程(考试固定套路):

看掩码,确定借了几位:把掩码换算成二进制,数从默认掩码(/8,/16,/24)往后多出的1的个数 = n。
算子网数:2^n 个。
算每个子网可用主机:2^m - 2(m = 32 - 掩码位数 - 0;更直接:m = 掩码中0的个数)。
算块大小(增量):块大小 = 256 - 掩码中"非255"那一段的十进制值。例如 /26 掩码 255.255.255.192 → 块大小 = 256-192 = 64。
列出子网:从0开始,每块加一次:0、64、128、192(/26在第四段)。每个子网的网络号=块起点,广播号=下一块起点-1,可用主机=中间。
把 IP 对齐到最近的块起点,即得该 IP 所属子网。
秒算口诀:"块大小 = 256 - 掩码末位"。看到掩码末位是192→块64;240→块16;224→块32;248→块8;252→块4。子网从0开始每次加块大小。比 IP 小的最近的块起点 = 该IP的网络号。

3.4.1 完整例题:划分子网(跟着算一遍)

题目:公司拿到 192.168.10.0/24,要分成6个部门,每部门不超过25台主机。怎么划?

① 需要≥6个子网:2^n ≥ 6 → n = 3(2^3=8个子网,够)
② 借3位后掩码 /27(255.255.255.224),主机位剩5位
③ 每子网可用主机 = 2^5-2 = 30台 ≥ 25 ✓
④ 块大小 = 256 - 224 = 32
⑤ 子网表:
   子网0:  192.168.10.0   广播192.168.10.31   可用 .1-.30
   子网1:  192.168.10.32  广播192.168.10.63   可用 .33-.62
   子网2:  192.168.10.64  广播192.168.10.95   可用 .65-.94
   子网3:  192.168.10.96  广播192.168.10.127  可用 .97-.126
   子网4:  192.168.10.128 广播192.168.10.159  可用 .129-.158
   子网5:  192.168.10.160 广播192.168.10.191  可用 .161-.190
   子网6:  192.168.10.192 广播192.168.10.223  可用 .193-.222
   子网7:  192.168.10.224 广播192.168.10.255  可用 .225-.254

3.4.2 完整例题:给定IP求三要素

题目:IP 172.16.35.123,掩码 255.255.240.0(/20),求网络号、广播号、可用范围。

① 掩码 255.255.240.0 → 第三段是240,块大小 = 256-240 = 16
② 第三段 35 对齐到16的倍数:16×2=32 ≤ 35 < 48=16×3 → 该子网第三段=32
③ 网络号 = 172.16.32.0
④ 广播号 = 网络号 + 块-1(只作用于240那段所在段及以下)
   = 172.16.(32+16-1).255 = 172.16.47.255
⑤ 可用范围 = 172.16.32.1 ~ 172.16.47.254
⑥ 可用主机数 = 2^(32-20) - 2 = 2^12 - 2 = 4094

3.4.3 特殊掩码值速查表(/24网段内)

掩码CIDR借位n子网数2^n可用主机2^m-2块大小
255.255.255.0/2401254256
255.255.255.128/2512126128
255.255.255.192/26246264
255.255.255.224/27383032
255.255.255.240/284161416
255.255.255.248/2953268
255.255.255.252/3066424
考点提醒:/30 子网(4个地址,2个可用)专门用于点对点链路(路由器和路由器之间),不浪费地址——这是最常考的"为什么用/30"。/31 和 /32 是特殊用途(/31用于点对点无广播,/32是单主机路由),考试了解即可。

3.5 VLSM 变长子网掩码(考点)

VLSM:同一主网络内使用不同长度的子网掩码,按各子网实际需求分配地址,避免浪费。划分顺序:从需求主机数最多的子网开始,用最大的块,逐级往下分(大块优先,先大后小)。

例题:192.168.1.0/24 要分:A子网50台、B子网25台、C子网10台、D子网2台。

① A(50台) 需要2^6-2=62 → /26,块64 → 192.168.1.0/26 (用.0-.63)
② B(25台) 需要2^5-2=30 → /27,块32 → 192.168.1.64/27 (用.64-.95)
③ C(10台) 需要2^4-2=14 → /28,块16 → 192.168.1.96/28 (用.96-.111)
④ D(2台)  需要2^2-2=2  → /30,块4  → 192.168.1.112/30 (用.112-.115)
剩余 192.168.1.116 之后 留给未来扩展(块起点要对齐)

3.6 CIDR 与路由聚合(超网 Supernetting)

CIDR(无类域间路由):用斜杠前缀(/8~/32)表示掩码,取代有类别的ABC类限制。它带来两大能力:

  • VLSM:在一个网络内用不同前缀长度(见3.5)。
  • 路由聚合(超网):把多个连续的小网络合并成一个大的网络条目,缩小路由表。例如四个 /24(192.168.0.0、.1.0、.2.0、.3.0)聚合为 192.168.0.0/22。

聚合规则:找这些网络的共同前缀位。192.168.0.0/24 = 11000000.10101000.00000000...,192.168.3.0/24 前22位相同 → 聚合为 /22。

3.7 ARP 与 ICMP(网络层的左右手)

虽然不属于编址,但它们是 IP 工作的配套协议,考试常考:

  • ARP(地址解析协议):已知目的IP,查同一广播域内的目的MAC。过程:查ARP缓存→没有则广播"谁是192.168.1.1?"→目标单播回复→缓存(超时约2-4分钟,Cisco默认4小时)。ARP是第2/3层之间的协议(工作在链路层,服务网络层)。跨网段通信时,帧的目的MAC是网关的MAC,不是目的主机的MAC——这是最常见的理解误区。
  • ICMP(网际控制报文协议):用于差错报告与网络诊断。ping 用 ICMP Echo Request/Reply;traceroute 用 ICMP TTL超时。ICMP 不承载用户数据,是 IP 的"信使"。

3.8 本章自测(子网题必须全对)

Q1. 192.168.1.0/26 有多少个子网?每个子网可用主机数?第2个子网的网络号和广播号?
答:借2位→4个子网;主机2^6-2=62;第2个子网(索引1)= 192.168.1.64,广播 192.168.1.127。

Q2. IP 10.10.10.100 掩码 255.255.255.240,求网络号。
答:块大小=16,100对齐到96 → 网络号 10.10.10.96。

Q3. 需要连接两台路由器,用哪个掩码最省地址?
答:/30(255.255.255.252),2个可用主机。

Q4. 172.16.5.0/24 要分5个子网各不超过20台主机,掩码多少?
答:20台需2^5-2=30 → 主机位5 → 掩码/27(255.255.255.224),子网数2^3=8≥5。

Q5. 主机A(192.168.1.10/24)访问主机B(192.168.2.20/24),帧的目的MAC是谁的?
答:默认网关(路由器接口)的MAC——跨网段通信目的MAC是网关。

4Transport & Application Layers

Core The TCP vs UDP distinction is a must-know; memorize common port numbers. The transport layer is the first "end-to-end" layer — it manages application-to-application conversation, not network-to-network.

4.1 What the Transport Layer Actually Does

The network layer (IP) delivers a packet to "the destination host," but a host runs dozens of applications — browser, mail, game... Which process gets the packet? That is what the transport layer solves with port numbers. IP addresses "which machine"; ports address "which application on that machine." Together they form the Socket = IP:port (e.g., 192.168.1.10:80).

TCP and UDP are the exam's core comparison — you must understand the mechanisms, not just memorize the chart.

4.2 TCP Deep Dive (the mechanisms of reliability)

TCP provides connection-oriented, reliable, ordered byte-stream delivery. Its reliability is not "automatic" — a set of mechanisms guarantees it:

MechanismPurposeImplementation
Three-way handshakeEstablish connection; both confirm "you hear me, I hear you"SYN → SYN-ACK → ACK
Sequence & ACK numbersOrdering, no dup, no lossOne number per byte; ACK carries "next expected sequence"
ACK (acknowledgment)Receiver confirms receiptACK on data; retransmit on timeout
Timeout retransmissionLoss recoverySender keeps an RTO timer
Sliding windowFlow controlReceiver advertises window size; sender sends at most "window" unacknowledged bytes
Congestion controlAvoid network congestionSlow start, congestion avoidance, fast retransmit, fast recovery
Four-way teardownGraceful closeFIN → ACK → FIN → ACK

4.2.1 The three-way handshake (why three?)

Client                                  Server
   |------ SYN(seq=x) ------->|  ① Client: I want to connect
   |<--- SYN-ACK(seq=y,ack=x+1)-| ② Server: received, agreed (and syncs its seq)
   |------ ACK(ack=y+1) ----->|  ③ Client: confirmed, start data
   ===== connection established =====

Why three? TCP is full-duplex — both sides must confirm "the peer can receive and send." Two handshakes cannot confirm "the client's receiving ability" (the server does not know the client got its SYN-ACK); four is redundant. The third ACK lets the server confirm the client is ready. Exams love: "why not two?" — answer: to prevent a stale connection request arriving late from creating a spurious connection (the classic "two-way handshake error" problem).

4.2.2 Sliding window (flow control core)

The receiver advertises its receive window (rwnd) in ACKs — "you may send at most this many bytes before I need to process them." The sender transmits within the window without waiting for each ACK (pipelining), dramatically boosting throughput. The window size changes dynamically: bigger when processing fast, smaller when overwhelmed. This is end-to-end flow control, distinct from network congestion control (cwnd) — exams distinguish them.

4.3 UDP Deep Dive (the cost of simplicity)

UDP is connectionless, unreliable, best-effort datagram delivery: no handshake, no ACK, no retransmit, no ordering. Benefits: small overhead (8-byte header vs TCP's 20), low latency, no connection-management burden. Fits: real-time voice/video (a lost frame is fine; retransmission causes lag), DNS (one question/answer), DHCP (broadcast scenario), SNMP, online games.

One-liner: TCP for "must be complete and accurate" (files, web, mail); UDP for "must be fast and can tolerate loss" (voice, video, DNS).

4.4 TCP vs UDP — the ultimate comparison table (memorize this)

DimensionTCPUDP
ConnectionConnection-oriented (3-way handshake)Connectionless
ReliabilityReliable (ACK + retransmit)Unreliable (best-effort)
OrderingOrdered bytes (sequence numbers)No ordering guarantee
Flow controlYes (sliding window)No
Congestion controlYes (slow start, etc.)No
Header20 bytes (more with options)8 bytes
Delivery modelByte streamDatagram (each independent)
Speed/overheadSlow / highFast / low
Typical appsHTTP, FTP, SMTP, SSH, TelnetDNS, DHCP, VoIP, video, SNMP, games

4.5 Port Numbers (memorize this table — instant exam points)

PortProtocolTransportOne-line purpose
20/21FTPTCPFile transfer (20 data / 21 control)
22SSHTCPSecure remote management (encrypted)
23TelnetTCPRemote management (plaintext, insecure)
25SMTPTCPSending mail
53DNSUDP/TCPName resolution (UDP queries, TCP zone transfers)
67/68DHCPUDP67 server / 68 client
69TFTPUDPTrivial file transfer (no auth)
80HTTPTCPWeb plaintext
110POP3TCPReceive mail (download then offline)
143IMAPTCPReceive mail (online management)
161/162SNMPUDP161 queries / 162 traps
443HTTPSTCPEncrypted web (HTTP + TLS)
3389RDPTCPWindows remote desktop
Memory: Web 80/443; mail "send 25, receive 110/143"; DNS 53 (UDP); FTP 20/21; remote "SSH 22 (encrypted), Telnet 23 (plaintext), RDP 3389". Ports < 1024 = well-known; 1024-49151 = registered; 49152+ = dynamic/private (client source ports).

4.6 Common Application-Layer Protocols, One by One

  • HTTP/HTTPS: request-response model. HTTP is stateless (cookies maintain sessions); HTTPS = HTTP + TLS. Methods: GET (read), POST (write), PUT (update), DELETE (delete). Status codes: 200 OK, 301/302 redirect, 403 forbidden, 404 not found, 500 server error.
  • DNS: name → IP. Resolution order: local cache → hosts file → local DNS server → root/TLD/authoritative (recursive or iterative). Record types: A (IPv4), AAAA (IPv6), CNAME (alias), MX (mail server), NS (name server), PTR (reverse), TXT (text/SPF). DNS queries default UDP/53; zone transfers (master-slave sync) use TCP/53.
  • DHCP: automatic IP assignment, UDP 67/68, four steps DORA (Discover→Offer→Request→Ack). Lease renewal (T1 = 50% of lease renews, T2 = 87.5% rediscover). See Chapter 12.
  • FTP/TFTP: FTP uses TCP (21 control + 20 data in active mode; passive uses a random data port), supports auth and directory browsing. TFTP uses UDP/69, minimal, no auth, used for IOS upgrades.
  • SMTP/POP3/IMAP: SMTP sends (TCP/25); POP3 downloads and removes (110); IMAP keeps mail on the server for multi-device sync (143).
  • SNMP: network device management. Manager polls Get (161); devices send Traps (162). Based on MIB. Versions v1/v2c (plaintext community) / v3 (encrypted auth).
  • Telnet/SSH: device remote management. Telnet plaintext (23); SSH encrypted (22, the modern must).
Security stance (exam view): Telnet, TFTP, SNMPv1/v2c, HTTP are plaintext/weak-auth — production should use SSH, HTTPS, SNMPv3. CCNA tests "know what to use and what to abandon."

4.7 Chapter Self-Test

Q1. Which protocol uses UDP? A. FTP B. HTTP C. DNS D. SMTP
Ans: C (DNS default UDP/53).

Q2. The three messages of the TCP handshake, in order?
Ans: SYN → SYN-ACK → ACK.

Q3. Which port maps to SSH? Why is it better than Telnet?
Ans: 22; SSH encrypts, Telnet is plaintext.

Q4. HTTPS port and the two protocols it builds on?
Ans: 443; HTTP + TLS/SSL.

Q5. What problem does the sliding window solve?
Ans: Flow control — the receiver advertises a window to throttle the sender and prevent receive-buffer overflow.

4传输层与应用层

核心 TCP 与 UDP 的区分是必考点;端口号需记忆常用项。传输层是"端到端"的第一层——它管的是应用与应用的对话,而不是网络与网络的对话。

4.1 传输层到底在干什么

网络层(IP)负责把包送到"目的主机",但主机上跑着几十上百个应用——浏览器、邮件、游戏……包到达主机后该交给哪个进程?这就是传输层用端口号(Port)解决的事。IP 寻址"哪台机器",端口寻址"机器上的哪个应用"。两者合称"套接字(Socket)"= IP:端口(如 192.168.1.10:80)。

传输层两大协议 TCP / UDP 是考试对比题的核心。必须从机制上理解差异,而不是死背特性表。

4.2 TCP 深入(可靠传输的机制)

TCP 提供面向连接、可靠、有序的字节流传输。它的可靠性不是"理所当然",而是由一组机制保证的:

机制作用实现方式
三次握手建立连接,双方确认"你听得到我、我听得到你"SYN → SYN-ACK → ACK
序号与确认号保证有序、不重不漏每个字节一个序号;ACK携带"期望的下一个序号"
确认应答 ACK接收方确认收到收到数据回ACK;超时未确认则重传
超时重传丢包恢复发送方维护重传计时器(RTO)
滑动窗口流量控制接收方通告窗口大小,发送方最多发"窗口"个未确认字节
拥塞控制避免网络拥塞慢启动、拥塞避免、快重传、快恢复
四次挥手优雅关闭连接FIN → ACK → FIN → ACK

4.2.1 三次握手(为什么是三次)

客户端                              服务器
   |------ SYN(seq=x) ------->|  ① 客户端:我要连接
   |<--- SYN-ACK(seq=y,ack=x+1)-| ② 服务器:收到,我同意(并同步自己的序号)
   |------ ACK(ack=y+1) ----->|  ③ 客户端:确认收到,开始传数据
   ===== 连接建立 =====

为什么必须三次?因为 TCP 是全双工——双方都要确认"对方能收能发"。两次握手无法确认"客户端的接收能力"(服务器发SYN-ACK后不知道客户端是否收到);四次又多余。第三次 ACK 让服务器确认客户端已就绪。考试爱问:"为什么不是两次?"——答案:防止已失效的连接请求报文突然又传到服务器,造成资源浪费(经典的"两次握手可能建立错误连接"问题)。

4.2.2 滑动窗口(流量控制核心)

接收方在 ACK 里通告自己的接收窗口(rwnd)——"你最多还能发这么多字节给我,别撑爆我的缓冲区"。发送方只能在窗口内连续发送,不必等每个 ACK(流水线),吞吐量大幅提升。窗口大小动态变化:处理得过来就扩大,处理不过来就缩小。这是"端到端流量控制",与网络的拥塞控制(cwnd)是两回事,考试要分清。

4.3 UDP 深入(简单高效的代价)

UDP 是无连接、不可靠、尽力而为的数据报协议:不握手、不确认、不重传、不排序。好处是开销小(8字节头 vs TCP 20字节头)、延迟低、无连接管理负担。适合:实时语音/视频(丢几帧无妨,重传反而更卡)、DNS 查询(一次一问一答)、DHCP(广播场景)、SNMP、在线游戏。

一句话记忆:TCP 管"必须完整准确"的事(文件、网页、邮件),UDP 管"必须快、能容忍丢"的事(语音、视频、DNS)。

4.4 TCP vs UDP 终极对比表(背这张就够)

维度TCPUDP
连接面向连接(三次握手)无连接
可靠性可靠(ACK+重传)不可靠(尽力而为)
有序性字节有序(序号)无顺序保证
流量控制有(滑动窗口)无
拥塞控制有(慢启动等)无
报文头20字节(选项可更大)8字节
传输方式字节流(Stream)数据报(Datagram,每报独立)
速度/开销慢/高快/低
典型应用HTTP, FTP, SMTP, SSH, TelnetDNS, DHCP, VoIP, 视频, SNMP, 游戏

4.5 端口号(背这张表,考试直接得分)

端口协议传输层一句话用途
20/21FTPTCP文件传输(20数据/21控制)
22SSHTCP安全远程管理(加密)
23TelnetTCP远程管理(明文,不安全)
25SMTPTCP发邮件
53DNSUDP/TCP域名解析(查询用UDP,区域传送用TCP)
67/68DHCPUDP67服务器/68客户端
69TFTPUDP简单文件传输(无认证)
80HTTPTCP网页明文
110POP3TCP收邮件(下载后离线)
143IMAPTCP收邮件(在线管理)
161/162SNMPUDP161查询/162陷阱
443HTTPSTCP网页加密(HTTP+TLS)
3389RDPTCPWindows远程桌面
记忆口诀:Web 80/443;邮件"发25收110/143";DNS 53(UDP);FTP 20/21;远程"SSH 22(加密)、Telnet 23(明文)、RDP 3389"。端口 < 1024 = 知名端口(Well-known),1024-49151 = 注册端口,49152+ = 动态/私有端口(客户端源端口通常在此)。

4.6 常见应用层协议逐个讲

  • HTTP/HTTPS:Web 请求-响应模型。HTTP 无状态(用Cookie维持会话),HTTPS = HTTP + TLS 加密。请求方法:GET(读)、POST(写)、PUT(更新)、DELETE(删)。状态码:200 OK、301/302 重定向、403 禁止、404 找不到、500 服务器错误。
  • DNS:域名→IP。解析顺序:本地缓存→hosts文件→本地DNS服务器→根/顶级/权威服务器(递归或迭代)。记录类型:A(IPv4)、AAAA(IPv6)、CNAME(别名)、MX(邮件服务器)、NS(域名服务器)、PTR(反向)、TXT(文本/SPF)。DNS 查询默认 UDP/53,区域传送(主备同步)用 TCP/53。
  • DHCP:自动分配IP,UDP 67/68,四步 DORA(Discover→Offer→Request→Ack)。租期可续约(T1=50%租期续租,T2=87.5%重新发现)。详见第12章。
  • FTP/TFTP:FTP 用 TCP(21控制+20数据,主动模式;被动模式数据端口随机),支持认证、目录浏览。TFTP 用 UDP/69,极简、无认证,用于网络设备IOS升级。
  • SMTP/POP3/IMAP:SMTP 发信(TCP/25),POP3 下载即走(110),IMAP 服务器保留邮件支持多设备同步(143)。
  • SNMP:网络设备管理。Manager 轮询 Get(161)、设备主动发 Trap(162);基于 MIB(管理信息库)组织数据;版本 v1/v2c(明文community)/v3(加密认证)。
  • Telnet/SSH:设备远程管理。Telnet 明文(23),SSH 加密(22,现代必须)。
安全提醒(考试立场):Telnet、TFTP、SNMPv1/v2c、HTTP 都是明文/弱认证,生产环境应替换为 SSH、HTTPS、SNMPv3。CCNA 考的就是"知道什么该用、什么该弃"。

4.7 本章自测

Q1. 以下哪个协议用 UDP?A. FTP B. HTTP C. DNS D. SMTP
答:C(DNS默认UDP/53)。

Q2. TCP 三次握手的三个报文依次是?
答:SYN → SYN-ACK → ACK。

Q3. 哪个端口对应 SSH?它比 Telnet 好在哪?
答:22;SSH加密传输,Telnet明文。

Q4. HTTPS 使用的端口和它基于哪两个协议?
答:443;HTTP + TLS/SSL。

Q5. 滑动窗口解决什么问题?
答:流量控制——接收方通告窗口,控制发送速度,避免接收缓冲溢出。

5Switch Basics & VLAN

Core Switching is the backbone of CCNA, and VLAN is the core switching concept — guaranteed exam material. After this chapter you should be able to: explain the switch's three forwarding behaviors, say why VLANs exist, configure VLANs, and manage a switch.

5.1 The Switch's Three Forwarding Behaviors (understand the principle before the commands)

A switch maintains a MAC address table (CAM table). On receiving a frame it does three steps: learn the source address → look up the destination → decide. There are only three decisions:

BehaviorTriggerAction
ForwardDestination MAC in table, port ≠ receiving portSend out that port only (precise forwarding)
FloodDestination MAC unknown, or destination is broadcast/multicastSend out all ports (except the receiving port)
DropDestination MAC in table, port = receiving port (destination is local)Drop silently

Details: MAC entries age out after 300 seconds (5 min) by default; CAM capacity varies by model (e.g., ~8K entries on a 2960). Flooding is how a Layer-2 network "learns" addresses — the first communication relies on it, then precise forwarding takes over.

SW1# show mac address-table
VLAN  Mac Address        Type      Ports
----  ----------------   --------  -----
1     0000.1111.AAAA     DYNAMIC   Fa0/1
1     0000.3333.CCCC     DYNAMIC   Fa0/3
1     0000.5555.EEEE     DYNAMIC   Fa0/2

5.2 What Is a VLAN (understand the "why" first)

VLAN (Virtual Local Area Network): logically grouping ports on one or more switches, where each group is an independent Layer-2 broadcast domain. By default all ports on a switch are in VLAN 1 (one broadcast domain). VLANs slice one physical network into multiple logical networks.

Four core motivations (answer "benefits of VLANs" with these):

  • Broadcast isolation: broadcasts in one VLAN do not reach other VLANs, limiting the blast radius of broadcast storms.
  • Enhanced security: sensitive departments (finance) are logically isolated; no access without routing.
  • Simpler management & troubleshooting: group by department/floor/function regardless of physical location (the same VLAN can span multiple switches).
  • Performance: smaller broadcast domains → less irrelevant traffic → more usable bandwidth.
Key understanding: VLANs are Layer-2 isolation. Hosts in the same VLAN communicate at Layer 2 directly; cross-VLAN traffic MUST pass through Layer 3 (a router or Layer-3 switch) — one of the most important concepts in the whole book. VLANs isolate broadcast domains, not collision domains (those are already isolated per port by the switch).

5.3 VLAN Ranges (memorize the numbers)

RangeNameNotes
0, 4095ReservedSystem-reserved, unusable
1DefaultFactory default; cannot be renamed or deleted; all ports start here; default native VLAN
2-1001NormalNormal create/delete VLANs; names configurable
1002-1005NormalReserved for FDDI/Token Ring (exam awareness)
1006-4094ExtendedNeeds VTP transparent mode; not present by default

VLAN IDs run 1-4094 (0 and 4095 reserved). 802.1Q uses 12 bits for the VLAN ID, hence 4096 theoretical VLANs.

5.4 Port Modes: Access vs Trunk (must be crystal clear)

ModeConnects toVLANs carriedBehavior
AccessEnd devices (PC, printer, IP phone)1 (tagged with its access VLAN)Untagged frames in → tagged with the access VLAN; frames of other VLANs → dropped
TrunkSwitch-to-switch, switch-to-routerMany (all by default)Frames carry 802.1Q tags; the native VLAN is untagged
Memory: access connects "people," trunk connects "switches." Access belongs to one VLAN; trunk is the "multi-VLAN highway."

5.5 Configuring VLANs (step-by-step + verification output)

Commands

SW1# configure terminal
SW1(config)# vlan 10                      ← create VLAN 10
SW1(config-vlan)# name SALES              ← name it (optional, recommended)
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# name FINANCE
SW1(config-vlan)# exit
SW1(config)# interface f0/1               ← enter the port
SW1(config-if)# switchport mode access    ← set access mode
SW1(config-if)# switchport access vlan 10 ← assign to VLAN 10
SW1(config-if)# exit
SW1(config)# interface range f0/2-10      ← batch-select ports 2-10
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# switchport access vlan 20
SW1(config-if-range)# exit
SW1(config)# end
SW1# show vlan brief                      ← verify

Verification output (learn to read it):

SW1# show vlan brief
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/11, Fa0/12, ... (unassigned)
10   SALES                            active    Fa0/1
20   FINANCE                          active    Fa0/2, Fa0/3, ... Fa0/10
1002 fddi-default                     act/unsup
...

Delete: no vlan 10 (removes access assignments; ports return to VLAN 1). VLAN 1 cannot be deleted.

5.6 Basic Switch Management (every device needs this)

Commands Configure a manageable switch from zero:

enable
configure terminal
hostname SW1                        # 1. Hostname
enable secret cisco123              # 2. Encrypted privileged password (avoid enable password)
service password-encryption         # 3. Encrypt all plaintext passwords in config
banner motd #UNAUTHORIZED ACCESS PROHIBITED#  # 4. Login banner
line console 0                      # 5. Console password
  password cisco
  login
  logging synchronous
line vty 0 4                        # 6. Remote (SSH/Telnet) password
  password cisco
  login
interface vlan 1                    # 7. Management IP (SVI)
  ip address 192.168.1.2 255.255.255.0
  no shutdown
ip default-gateway 192.168.1.1      # 8. Default gateway (for cross-subnet management)
end
copy running-config startup-config  # 9. Save config (always!)
Three must-remembers: ① enable secret stores a hash and beats enable password (plaintext) — when both are set, secret wins; ② switch ports are all up by default — shutdown idle ports for security; ③ always copy running-config startup-config (or write) so config survives reboot.

5.7 Common Troubleshooting (exam lab mindset)

  • PC can't get IP / no connectivity: check port status (show interfaces status) → check no shutdown → check access vlan pairing.
  • Same-VLAN but no connectivity: check both access VLANs match, cable/port up, MAC table has entries.
  • Cross-VLAN "not working" is normal: it needs Layer-3 routing, not a config error (unless you configured SVI + Layer-3 interface).
  • Port err-disabled: possibly port security, BPDU guard, or UDLD — show interfaces status shows the cause; fix it, then shutdown + no shutdown to recover.

5交换机基础与 VLAN

核心 交换是 CCNA 的支柱,VLAN 是交换的核心概念。必考。学完本章要能:说清交换机三种转发行为、VLAN 为什么存在、怎么配 VLAN、怎么管理交换机。

5.1 交换机的三种转发行为(先懂原理再配命令)

交换机维护一张 MAC 地址表(CAM表),收到帧后执行三步:学源地址 → 查目的地址 → 决策。决策只有三种:

行为触发条件动作
转发 Forward目的MAC在表中,且对应端口≠接收端口只从该端口发出(精确转发)
泛洪 Flood目的MAC未知(表中没有)或目的MAC是广播/组播从所有端口发出(除接收端口)
丢弃 Drop目的MAC在表中,且对应端口=接收端口(目的就在本地)直接丢弃,不再发出

细节补充:MAC 表条目默认老化 300 秒(5分钟),无流量自动清除;Cisco 交换机 MAC 表容量因型号而异(如 2960 约8K条)。泛洪是二层网络"学地址"的机制——第一次通信都靠它,学完后才精确转发。

SW1# show mac address-table
VLAN  Mac Address        Type      Ports
----  ----------------   --------  -----
1     0000.1111.AAAA     DYNAMIC   Fa0/1
1     0000.3333.CCCC     DYNAMIC   Fa0/3
1     0000.5555.EEEE     DYNAMIC   Fa0/2

5.2 什么是 VLAN(先理解为什么)

VLAN(Virtual Local Area Network,虚拟局域网):把一台或多台交换机上的端口逻辑分组,每个组是一个独立的第2层广播域。默认情况下交换机所有端口在 VLAN 1(一个广播域)。VLAN 把一个物理网络切成多个逻辑网络。

四个核心动机(考试问"VLAN的好处"就答这些):

  • 隔离广播域:VLAN 间的广播不会互相传播,减少广播风暴影响范围。
  • 增强安全:敏感部门(财务)与普通部门逻辑隔离,未经路由无法互访。
  • 简化管理与排错:按部门/楼栋/业务逻辑分组,不受物理位置限制(同一VLAN可以跨多台交换机)。
  • 性能优化:缩小广播域→减少无关流量→提高可用带宽。
关键理解:VLAN 是第2层的隔离。同一 VLAN 内可以直接二层通信;跨 VLAN 必须经过第3层(路由器或三层交换机)——这是全书最重要的概念之一。VLAN 隔离广播域,但不隔离冲突域(冲突域已被交换机的每个端口天然隔离)。

5.3 VLAN 的范围(背数字)

VLAN范围名称说明
0, 4095保留系统保留,不可用
1默认 Default出厂默认VLAN,不能改名、不能删除;所有端口初始在此;native VLAN默认
2–1001普通 Normal正常创建/删除的VLAN;可配置名称
1002–1005普通保留给 FDDI/令牌环(考试了解)
1006–4094扩展 Extended需 VTP 透明模式;默认不存在于所有交换机

VLAN 编号范围 1-4094(0和4095保留)。802.1Q 用 12 位表示 VLAN ID,所以理论最多 4096 个。

5.4 端口模式:Access 与 Trunk(必须分清)

模式连接对象承载VLAN数行为
Access 接入终端设备(PC、打印机、IP电话)1个(打上该VLAN的ID)收到无标签帧→打上access VLAN标签;收到其他VLAN帧→丢弃
Trunk 主干交换机之间、交换机-路由器多个(默认全部)帧带802.1Q标签传输,native VLAN不打标签
记忆:access 连"人",trunk 连"交换机"。access 只属于一个 VLAN,trunk 是"多VLAN的高速公路"。

5.5 配置 VLAN(逐步命令 + 验证输出)

命令 完整配置流程:

SW1# configure terminal
SW1(config)# vlan 10                      ← 创建VLAN 10
SW1(config-vlan)# name SALES              ← 命名(可选,建议起名便于管理)
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# name FINANCE
SW1(config-vlan)# exit
SW1(config)# interface f0/1               ← 进入端口
SW1(config-if)# switchport mode access    ← 设为access
SW1(config-if)# switchport access vlan 10 ← 划入VLAN 10
SW1(config-if)# exit
SW1(config)# interface range f0/2-10      ← 批量选择端口2-10
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# switchport access vlan 20
SW1(config-if-range)# exit
SW1(config)# end
SW1# show vlan brief                      ← 验证

验证输出(理解它):

SW1# show vlan brief
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/11, Fa0/12, ... (未分配的)
10   SALES                            active    Fa0/1
20   FINANCE                          active    Fa0/2, Fa0/3, ... Fa0/10
1002 fddi-default                     act/unsup
...

删除:no vlan 10(会移除该VLAN下所有access端口分配,端口回到VLAN 1)。VLAN 1 不能删。

5.6 交换机基本管理配置(每台设备都要会)

命令 从零配置一台可管理的交换机:

enable
configure terminal
hostname SW1                        # 1. 主机名
enable secret cisco123              # 2. 特权加密密码(enable password明文,勿用)
service password-encryption         # 3. 加密所有明文密码(存配置时)
banner motd #UNAUTHORIZED ACCESS PROHIBITED#  # 4. 登录横幅
line console 0                      # 5. 控制台密码
  password cisco
  login
  logging synchronous
line vty 0 4                        # 6. 远程(SSH/Telnet)密码
  password cisco
  login
interface vlan 1                    # 7. 管理IP(SVI)
  ip address 192.168.1.2 255.255.255.0
  no shutdown
ip default-gateway 192.168.1.1      # 8. 默认网关(跨网段管理用)
end
copy running-config startup-config  # 9. 保存配置(必做!)
三个必须牢记:① enable secret 存的是哈希,比 enable password(明文)安全,两者都配时 secret 优先;② 交换机默认所有接口开启,安全上应 shutdown 闲置口;③ 每次改完配置要 copy running-config startup-config(或 write)保存,重启不丢。

5.7 常见问题排错(考实验题思路)

  • PC 拿不到 IP / 不通:查端口状态(show interfaces status)→ 查是否 no shutdown → 查 access vlan 是否配对。
  • 同VLAN不通:查两端 access vlan 是否一致、查线缆/端口 up、查 MAC 表是否有条目。
  • 跨VLAN不通是正常的:需要三层路由,不是配置错误(除非配了 SVI + 三层接口)。
  • 端口 err-disabled:可能被端口安全、BPDU guard、UDLD 关闭,show interfaces status 看原因,修复后 shutdown + no shutdown 恢复。

6Trunk · 802.1Q · DTP

Core Trunks carry VLANs between switches — a must-know. After this chapter: explain why trunks tag frames, how 802.1Q tags, what the native VLAN is, and how DTP modes negotiate.

6.1 Why Trunk (think about the problem first)

Two switches need to carry multiple VLANs between them. If each cable carried one VLAN, 10 VLANs would need 10 cables — absurd. The solution: one cable carries all VLANs, and a "tag" identifies which VLAN each frame belongs to. That cable is the Trunk.

A host in VLAN 10 on switch 1 sends to a host in VLAN 10 on switch 2: the frame leaves switch 1's trunk port tagged "VLAN 10"; switch 2's trunk port receives it, sees tag 10, strips it, and forwards only to VLAN 10 access ports locally. Frames of other VLANs mixed on the same cable never interfere.

One-liner: Access ports tag frames in; trunk ports carry tagged frames. Trunk is the "one cable, many VLANs" mechanism; the tag is the "whose is whose" marker.

6.2 The 802.1Q Tag (industry standard — must-know)

IEEE 802.1Q is the only industry-standard trunk encapsulation (Cisco's proprietary ISL is obsolete; the new exam only covers 802.1Q). It inserts a 4-byte tag after the source MAC:

Original Ethernet frame:
[Dst MAC 6B][Src MAC 6B][Type 2B][Payload 46-1500B][FCS 4B]

802.1Q frame:
[Dst MAC 6B][Src MAC 6B][TPID 2B][TCI 2B][Type 2B][Payload][FCS (recomputed)]

TPID = 0x8100 (2 bytes): marks "this is an 802.1Q tagged frame"
TCI  = 2 bytes, containing:
  - PCP (3 bits): priority (0-7, for QoS)
  - DEI (1 bit): drop eligible
  - VID (12 bits): VLAN ID (0-4095, usable 1-4094)

Key points:

  • The tag sits after the source MAC, before the Type field; the original 2-byte Type/Length position is taken by TPID, so the real upper-layer Type shifts 4 bytes later.
  • After inserting the tag, the FCS must be recomputed (the frame changed).
  • Max frame size grows from 1518 to 1522 bytes (4-byte tag); MTU adjusts accordingly.

6.3 Native VLAN — the most confusing point

A trunk has one special VLAN: the Native VLAN (default VLAN 1). Rule: native-VLAN frames travel the trunk UNtagged; every other VLAN is tagged.

Why does it exist? — compatibility with devices/protocols that don't support 802.1Q (some CDP, VTP, DTP, and STP BPDUs travel untagged).

Three must-know traps: ① both trunk ends must agree on the native VLAN — a mismatch causes "VLAN leakage" (one side's native traffic is treated as another VLAN by the far end) plus security risk; ② you can change the native VLAN (e.g., to VLAN 99 — safer, preventing attackers from abusing the default VLAN 1); ③ the classic question "which VLAN's frames are untagged on a trunk?" — the Native VLAN.

6.4 DTP (Dynamic Trunking Protocol) — Cisco-proprietary negotiation

DTP is a Cisco-proprietary protocol that lets adjacent ports auto-negotiate whether to become a trunk. It runs on a direct link, sending DTP frames (dst MAC 01:00:0C:CC:CC:CC) periodically.

ModeBehaviorActively negotiatesResult
accessForce access portNoPeer also access → access link
dynamic desirableActively "invites" the peer to trunkYesPeer auto/desirable/trunk → becomes trunk
dynamic autoPassively waitsNoPeer desirable/trunk → trunk; peer auto → stays access
trunkForce trunkYesPeer non-access → trunk
nonegotiateDTP fully disabledNoBoth ends must be configured manually (e.g., to non-Cisco)
Memory: desirable is active, auto is passive — "one active side is enough to become a trunk"; two autos never negotiate (both wait). Cisco switches default to dynamic auto (2960) or dynamic desirable (some models) — new deployments should be explicit.
Security: DTP is the entry point for "VLAN hopping" attacks — an attacker sets their port to desirable and may negotiate the link into trunk mode, reaching every VLAN. Production should explicitly switchport mode access or trunk + switchport nonegotiate, disabling DTP.

6.5 Configuring Trunk (complete commands + verification)

Commands

SW1(config)# interface g0/1
SW1(config-if)# switchport mode trunk          # trunk mode (implicitly enables DTP negotiation)
# more formally (encapsulation first):
SW1(config-if)# switchport trunk encapsulation dot1q   # 802.1Q encapsulation (older multi-encap platforms)
SW1(config-if)# switchport mode trunk
# optional: restrict allowed VLANs
SW1(config-if)# switchport trunk allowed vlan 10,20,30   # only these VLANs
# optional: change native VLAN
SW1(config-if)# switchport trunk native vlan 99
# optional: disable DTP
SW1(config-if)# switchport nonegotiate
SW1(config-if)# no shutdown
SW1(config-if)# end
SW1# show interfaces trunk                     # verify
SW1# show interfaces trunk allowed-vlan        # allowed list

Reading the verification output:

SW1# show interfaces trunk
Port        Mode         Encapsulation  Status        Native vlan
Gi0/1       on           802.1q         trunking      99
...
Port        Vlans allowed on trunk
Gi0/1       10,20,30
Port        Vlans allowed and active in management domain
Gi0/1       10,20,30

Troubleshooting: ① both ends' modes must be compatible (trunk + trunk/dynamic work); ② native VLAN must match; ③ the allowed list must cover the VLANs that need to communicate; ④ Status must read trunking to be up — not-trunking means negotiation failed.

6.6 Router-on-a-Stick — inter-VLAN routing

Inter-VLAN communication needs Layer 3. The classic approach: Router-on-a-Stick — one trunk link to the router; the router creates subinterfaces, one per VLAN, each in a different subnet.

R1(config)# interface g0/0.10           # subinterface .10 for VLAN 10
R1(config-subif)# encapsulation dot1Q 10 # tag 802.1Q, VID=10
R1(config-subif)# ip address 192.168.10.1 255.255.255.0   # VLAN 10 gateway
R1(config-subif)# exit
R1(config)# interface g0/0.20           # subinterface .20 for VLAN 20
R1(config-subif)# encapsulation dot1Q 20
R1(config-subif)# ip address 192.168.20.1 255.255.255.0   # VLAN 20 gateway
R1(config-subif)# exit
R1(config)# interface g0/0
R1(config-if)# no shutdown             # physical port must be up (no IP needed; subinterfaces handle it)

# switch side: the port to the router must be a trunk
SW1(config)# interface g0/24
SW1(config-if)# switchport mode trunk
Memory: Router-on-a-Stick = one trunk + multiple subinterfaces (one per VLAN). Each subinterface needs encapsulation dot1Q <VID> + the VLAN's gateway IP. Modern enterprises use Layer-3 switch SVIs (more efficient), but ROAS is a classic exam item.

6.7 Chapter Self-Test

Q1. Which VLAN's frames are untagged on a trunk?
Ans: the Native VLAN (default VLAN 1, changeable).

Q2. Where is the 802.1Q tag inserted, and how many bytes?
Ans: after the source MAC, before the Type field; 4 bytes (TPID 2B + TCI 2B).

Q3. Which DTP modes actively negotiate? Which pair never becomes a trunk?
Ans: dynamic desirable and trunk are active; two dynamic auto (both passive) never trunk.

Q4. In Router-on-a-Stick, does the physical router interface need an IP?
Ans: No — IPs go on the subinterfaces.

Q5. Why disable DTP in production?
Ans: to prevent VLAN hopping — an attacker negotiates a trunk and reaches all VLANs.

6Trunk · 802.1Q · DTP

核心 Trunk 让 VLAN 跨交换机传递,是必考点。学完本章要能:解释 Trunk 为什么需要打标签、802.1Q 怎么打标签、Native VLAN 是什么、DTP 各模式怎么协商。

6.1 为什么要 Trunk(先想清楚问题)

两台交换机之间要传递多个 VLAN 的流量。如果每根线只传一个 VLAN,那10个VLAN要10根线——荒谬。解决办法:一根线传所有 VLAN,用"标签"区分每帧属于哪个 VLAN。这根线就是 Trunk(主干链路)。

接入交换机1的VLAN 10主机发给接入交换机2的VLAN 10主机:帧从交换机1的Trunk口出去时,打上"VLAN 10"的标签;交换机2的Trunk口收到,看到标签是10,剥掉标签,只转发给本机VLAN 10的access端口。其他VLAN的帧即使混在同一根线上,也互不干扰。

一句话:Access 口打标签进、Trunk 口带标签走。Trunk 是"多VLAN共用一根线的机制",标签是"区分谁的机制"。

6.2 802.1Q 标签(行业标准,必考)

IEEE 802.1Q 是唯一的行业标准 Trunk 封装(Cisco 私有 ISL 已废弃,新版考试只考 802.1Q)。它在以太网帧的源MAC之后插入 4 字节标签:

原始以太网帧:
[目的MAC 6B][源MAC 6B][类型2B][数据46-1500B][FCS 4B]

802.1Q 帧:
[目的MAC 6B][源MAC 6B][TPID 2B][TCI 2B][类型2B][数据][FCS(重算)]

TPID = 0x8100 (2字节): 标识"这是802.1Q标签帧"
TCI  = 2字节, 其中:
  - PCP (3位): 优先级(0-7, 用于QoS)
  - DEI (1位): 丢弃优先级
  - VID (12位): VLAN ID (0-4095, 实际可用1-4094)

关键点:

  • 标签插在源MAC之后、类型字段之前,原来2字节的"类型/长度"字段位置被TPID占用,所以真正的上层类型字段往后移了4字节。
  • 插入标签后,FCS 必须重新计算(帧变了)。
  • 帧最大长度从 1518 变成 1522 字节(4字节标签),MTU 相应提到 1504 或 1500(取决于实现)。

6.3 Native VLAN(本征VLAN)——最容易混的点

Trunk 链路上有一个特殊VLAN:Native VLAN(默认 VLAN 1)。规则:Native VLAN 的帧在 Trunk 上不打标签,其他 VLAN 都打标签。

为什么存在?——为了兼容不支持 802.1Q 的老设备/协议(如某些 CDP、VTP、DTP、STP BPDU 报文,它们不带标签传输)。

三个必考陷阱:① Trunk 两端 Native VLAN 必须一致,不一致会导致"VLAN 泄漏"(一端的 native 流量被另一端当别的VLAN处理)和安全风险;② Native VLAN 可以改(如改成 VLAN 99,更安全,防止攻击者利用默认VLAN 1);③ 考试常问"Trunk上哪个VLAN的帧不打标签?"——Native VLAN。

6.4 DTP(动态Trunk协议)——Cisco 私有协商

DTP(Dynamic Trunking Protocol) 是 Cisco 私有协议,让相邻端口自动协商要不要成为 Trunk。它工作在一根直连链路上,周期性发 DTP 帧(目的MAC 01:00:0C:CC:CC:CC)。

模式行为主动发起协商协商结果
access强制接入端口否对方也access→接入链路
dynamic desirable主动"勾引"对方成trunk是对方auto/desirable/trunk→成为trunk
dynamic auto被动等对方来协商否对方desirable/trunk→成为trunk;对方auto→仍是access
trunk强制trunk是对方非access→成为trunk
nonegotiate完全禁用DTP否必须手动配置两端(常用于连非Cisco设备)
记忆:desirable 主动、auto 被动——"一方主动就能成trunk";两端都auto就协商不成(都等对方)。Cisco 交换机默认 dynamic auto(2960默认)或 dynamic desirable(部分型号),新设备建议显式配置。
安全:DTP 是"VLAN 跳转攻击"的入口——攻击者把自己端口设 desirable,可能把链路协商成 trunk,从而访问所有 VLAN。生产环境应 显式 switchport mode access 或 trunk + switchport nonegotiate,禁用 DTP。

6.5 配置 Trunk(完整命令 + 验证)

命令

SW1(config)# interface g0/1
SW1(config-if)# switchport mode trunk          # 设为trunk(同时隐式启用DTP协商)
# 或更规范(含封装):
SW1(config-if)# switchport trunk encapsulation dot1q   # 封装802.1Q(仅需在支持多封装的老平台)
SW1(config-if)# switchport mode trunk
# 可选: 限制允许的VLAN
SW1(config-if)# switchport trunk allowed vlan 10,20,30   # 只允许这3个VLAN
# 可选: 改native VLAN
SW1(config-if)# switchport trunk native vlan 99
# 可选: 禁用DTP
SW1(config-if)# switchport nonegotiate
SW1(config-if)# no shutdown
SW1(config-if)# end
SW1# show interfaces trunk                     # 验证
SW1# show interfaces trunk allowed-vlan        # 看允许列表

验证输出解读:

SW1# show interfaces trunk
Port        Mode         Encapsulation  Status        Native vlan
Gi0/1       on           802.1q         trunking      99
...
Port        Vlans allowed on trunk
Gi0/1       10,20,30
Port        Vlans allowed and active in management domain
Gi0/1       10,20,30

排错要点:① 两端 mode 必须兼容(一方trunk+另一方trunk/dynamic都行);② 两端 Native VLAN 必须相同;③ 允许列表要覆盖需要通信的VLAN;④ 看 Status 是 trunking 才算 up,not-trunking 表示协商失败。

6.6 路由器单臂路由(Router-on-a-Stick)——跨VLAN路由

VLAN 间通信需要第3层。经典做法之一:单臂路由——用一条 Trunk 链路连接交换机和路由器,路由器接口划分子接口(subinterface),每个子接口对应一个 VLAN,配不同网段IP。

R1(config)# interface g0/0.10           # 子接口.10 对应 VLAN 10
R1(config-subif)# encapsulation dot1Q 10 # 打802.1Q标签, VID=10
R1(config-subif)# ip address 192.168.10.1 255.255.255.0   # VLAN 10的网关
R1(config-subif)# exit
R1(config)# interface g0/0.20           # 子接口.20 对应 VLAN 20
R1(config-subif)# encapsulation dot1Q 20
R1(config-subif)# ip address 192.168.20.1 255.255.255.0   # VLAN 20的网关
R1(config-subif)# exit
R1(config)# interface g0/0
R1(config-if)# no shutdown             # 物理口必须up(无需IP, 子接口处理)

# 交换机侧: 连路由器的端口必须是trunk
SW1(config)# interface g0/24
SW1(config-if)# switchport mode trunk
记忆:单臂路由 = 一条 trunk + 多个子接口(每个VLAN一个子接口)。子接口要 encapsulation dot1Q <VID> + 配该VLAN网关IP。现代企业多用三层交换机 SVI(更高效),但单臂路由是经典考点。

6.7 本章自测

Q1. Trunk 链路上哪个 VLAN 的帧不打标签?
答:Native VLAN(默认VLAN 1,可改为其他)。

Q2. 802.1Q 标签插在帧的什么位置?共几字节?
答:源MAC之后、类型字段之前;4字节(TPID 2B + TCI 2B)。

Q3. DTP 的哪个模式会主动发起协商?两端都什么模式时无法成为trunk?
答:dynamic desirable 和 trunk 主动;两端都 dynamic auto(都被动)时协商失败。

Q4. 单臂路由中,路由器物理接口要不要配IP?
答:不需要,IP 配在子接口上。

Q5. 为什么生产环境要禁用 DTP?
答:防止 VLAN 跳转攻击——攻击者通过协商成trunk访问所有VLAN。

7STP Spanning Tree Protocol

Core STP prevents Layer-2 loops in switched networks — a must-know, commonly testing root bridge election, port states, and port roles. After this chapter: name loop's three sins, elect root/root-port/designated-port by the rules, draw the port state machine, and explain why RSTP is fast.

7.1 Why STP (the three sins of a loop)

Redundant design creates physical loops in switched networks. A loop's three catastrophic consequences:

ProblemMechanismConsequence
Broadcast stormBroadcast frames replicate and circle the loop endlesslyBandwidth instantly saturated, host CPUs overloaded, network paralysis
MAC table thrashThe same MAC is received on multiple ports repeatedly; entries flip-flopSwitch cannot forward correctly; frames misdelivered
Duplicate framesThe same frame arrives at the destination via different pathsReceiver sees duplicate frames; upper-layer protocols break

STP (Spanning Tree Protocol): logically block some redundant ports, pruning the physical loop into a loop-free logical tree, while keeping redundant paths as backups — when the primary path fails, the backup activates automatically. A classic "use space for safety" design.

7.2 BPDU & Bridge ID (STP's communication language)

Switches exchange BPDUs (Bridge Protocol Data Units). BPDUs use multicast MAC 01:80:C2:00:00:00, sent every 2 seconds by default (Hello Time).

Each switch has a Bridge ID:

Bridge ID = Priority (2 bytes, default 32768) + MAC address (6 bytes)
Example: 32768.aaaa.bbbb.cccc
Comparison: priority first (smaller wins), then MAC (smaller wins)

IEEE later extended it to: priority + extended system ID (VLAN number) + MAC. Priority is configurable in multiples of 4096 (0-61440).

7.3 The STP Election Trio (exam core — memorize)

Elect the Root Bridge: the switch with the smallest Bridge ID network-wide. Every port on the root bridge is a Designated Port (DP), in forwarding state.
Each non-root switch elects a Root Port (RP): its port with the lowest cost to the root (the shortest path to the root).
Each link elects a Designated Port (DP): the end closer to the root is the DP; the other end, if neither RP nor DP, is blocked.

Three iron rules: ① all root ports on the root bridge are DPs; ② every non-root switch has exactly one RP; ③ on every link, one end is DP, the other is RP or blocked. Port cost table (memorize):

Bandwidth802.1D cost802.1t (new) cost
10 Mbps1002,000,000
100 Mbps19200,000
1 Gbps420,000
10 Gbps22,000

7.4 Port State Machine (802.1D — memorize the order)

Blocking → Listening → Learning → Forwarding
   ↑_______________________________________|
        (back to blocking when link/root changes)

Disabled (shutdown or failed port)

Default timers:
  Blocking: 20 sec (Max Age, BPDU aging)
  Listening: 15 sec (Forward Delay, wait for BPDU convergence)
  Learning: 15 sec (Forward Delay, learn MACs, no forwarding)
  Forwarding: normal operation
  Total: about 50 seconds from blocking to forwarding
StateSend/receive BPDULearn MACsForward data
BlockingReceive onlyNoNo
ListeningYesNoNo
LearningYesYesNo
ForwardingYesYesYes
DisabledNoNoNo
Exam point: 802.1D converges in about 50 seconds (20+15+15) — too slow, which is why RSTP replaced it. Exams ask "blocking to forwarding — which states, how long each."

7.5 Port Roles & RSTP (802.1w — the modern default)

RSTP collapses 802.1D's five states into three (Discarding, Learning, Forwarding) and adds port roles:

RoleMeaning
RootSame as 802.1D
DesignatedSame as 802.1D
AlternateBackup to the Root Port — takes over immediately if the primary root port fails
BackupBackup to the Designated Port (redundant port to the same segment)
DisabledNot participating

Why RSTP is fast:

  • Proposal/Agreement handshake: handshake-style negotiation, no timer waits — converges in seconds.
  • Edge ports: ports to end devices go straight to forwarding, no wait — but if a BPDU arrives they revert to normal ports (BPDU Guard can prevent this).
  • Alternate ports take over instantly: when a root port fails, the Alternate enters forwarding immediately, no recomputation.
  • Backward compatible with 802.1D (BPDU version negotiation).
Memory: RSTP converges in about 6 seconds (3×2s Hello) vs 802.1D's ~50s. Cisco defaults to Rapid PVST+ (one RSTP instance per VLAN).

7.6 STP Enhancements (frequently tested)

FeatureWhat it doesKey command
PortFastAccess ports skip listening/learning, go straight to forwardingspanning-tree portfast
BPDU GuardPortFast port that receives a BPDU → err-disable (blocks forged-root attacks)spanning-tree bpduguard enable
Root GuardPrevents a port from becoming a root port (protects the root's status)spanning-tree guard root
Loop GuardPrevents "no-BPDU misjudgment" on a unidirectional link from creating a loopspanning-tree guard loop
UDLDDetects unidirectional links (fiber TX/RX one-way)udld enable
BPDU FilterPortFast port discards BPDUs outrightspanning-tree bpdufilter enable
Security combo: standard access port = access + PortFast + BPDU Guard — prevents users from plugging in a switch and altering the STP topology.

7.7 Configuration & Verification (with output reading)

SW1(config)# spanning-tree mode rapid-pvst      # Rapid PVST+ (modern default)
SW1(config)# spanning-tree vlan 10 root primary  # force root for VLAN 10 (lowers priority)
SW1(config)# spanning-tree vlan 10 priority 4096 # manual priority (smaller = more likely root)
SW1(config)# interface f0/1
SW1(config-if)# switchport mode access
SW1(config-if)# spanning-tree portfast           # access port fast forward
SW1(config-if)# spanning-tree bpduguard enable   # block forged BPDUs
SW1(config-if)# end

SW1# show spanning-tree                          # core verification
VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4096
             Address     aaaa.bbbb.cccc           ← root bridge MAC (yours or someone else's)
             Cost        0                       ← cost to root (0 on the root itself)
  Bridge ID  Priority    4096
             Address     aaaa.bbbb.cccc
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Desg FWD 19        128.1     P2p Edge    ← edge port forwarding
Fa0/2            Root FWD 19        128.2     P2p         ← root port forwarding
Fa0/3            Altn BLK 19        128.3     P2p         ← alternate port blocked

SW1# show spanning-tree summary

How to read the output: compare Root ID vs Bridge ID to see if you are the root; read each port's Role (Root/Desg/Altn/Back) and Sts (FWD/BLK); Edge means PortFast.

7.8 Chapter Self-Test

Q1. How is the root bridge elected in STP?
Ans: smallest Bridge ID (priority first, then MAC).

Q2. On a non-root switch, which port has the lowest cost to the root?
Ans: the Root Port.

Q3. 802.1D blocking→forwarding: which states, how long?
Ans: blocking→listening→learning→forwarding, ~50 sec (20+15+15).

Q4. Why is RSTP faster than 802.1D?
Ans: proposal/agreement handshake, edge ports straight to forwarding, alternate ports take over instantly — ~6 sec.

Q5. What STP features should an access port to a PC have?
Ans: PortFast (skip listening/learning) + BPDU Guard (block forged BPDUs).

7STP 生成树协议

核心 STP 防止交换网络中的第2层环路,是必考点,常考根桥选择、端口状态与角色。学完本章要能:说出环路的三宗罪、按规则选出根桥/根端口/指定端口、画出端口状态机、讲清 RSTP 快在哪。

7.1 为什么需要 STP(环路的三宗罪)

冗余设计会让交换网络出现物理环路。环路的三个灾难性后果:

问题机制后果
广播风暴广播帧沿环路不断复制、转圈网络带宽被瞬间打满,主机CPU过载,网络瘫痪
MAC 表抖动同一MAC从多个端口反复收到,表项来回改写交换机无法正确转发,帧被错误投递
重复帧同一帧沿不同路径到达目的地多次接收方收到多个相同帧,上层协议出错

STP(Spanning Tree Protocol,生成树协议):逻辑上阻塞某些冗余端口,把物理环路剪成一棵无环的逻辑树,同时保留冗余路径作为备份——主路径断时自动启用备份。这是"用空间换安全"的经典设计。

7.2 BPDU 与桥 ID(STP 的通信语言)

交换机之间用 BPDU(Bridge Protocol Data Unit) 交换 STP 信息。BPDU 目的MAC是 STP 组播 01:80:C2:00:00:00,默认每 2 秒发一次(Hello Time)。

每台交换机有一个 桥 ID(Bridge ID):

桥 ID = 优先级(2字节, 默认32768) + MAC地址(6字节)
例如: 32768.aaaa.bbbb.cccc
比较规则: 先比优先级(小者优), 再比MAC(小者优)

IEEE 后来扩展为:优先级 + 扩展系统ID(VLAN号) + MAC。优先级可配置为 4096 的倍数(0-61440)。

7.3 STP 选举三步曲(考试核心,必须背)

选根桥(Root Bridge):全网桥 ID 最小的交换机。根桥上的所有端口都是指定端口(DP),处于转发态。
每台非根桥选根端口(Root Port):自己到达根桥开销(Cost)最小的端口(走哪条路去根桥最近)。
每条链路上选指定端口(Designated Port):链路上离根桥最近的一端是 DP;另一端如果既不是RP也不是DP,则阻塞(Blocking)。

三条铁律记住:① 根桥上全是 DP;② 每台非根桥有且只有一个 RP;③ 每条链路两端,一端DP、另一端RP或阻塞。端口成本(Cost)表(必背):

带宽802.1D Cost802.1t(新标准) Cost
10 Mbps1002,000,000
100 Mbps19200,000
1 Gbps420,000
10 Gbps22,000

7.4 端口状态机(802.1D,必背顺序)

阻塞 Blocking → 监听 Listening → 学习 Learning → 转发 Forwarding
   ↑_______________________________________________|
        (链路/根桥变化时回到阻塞)

禁用 Disabled (shutdown 或故障端口)

各状态默认时间:
  阻塞: 持续20秒 (Max Age, BPDU老化)
  监听: 15秒 (Forward Delay, 等BPDU收敛)
  学习: 15秒 (Forward Delay, 学MAC但不转发)
  转发: 正常工作
  合计: 从阻塞到转发约 50 秒
状态收/发BPDU学MAC转发数据
阻塞 Blocking收(不发)否否
监听 Listening收/发否否
学习 Learning收/发是否
转发 Forwarding收/发是是
禁用 Disabled否否否
考点:802.1D 收敛约 50 秒(20+15+15)——太慢,是它被 RSTP 取代的根本原因。考试爱问"从阻塞到转发经过哪些状态、各多久"。

7.5 端口角色与 RSTP(802.1w,现代默认)

RSTP 把 802.1D 的5个状态精简为3个(丢弃 Discarding、学习、转发),并新增端口角色:

角色说明
根端口 Root同802.1D
指定端口 Designated同802.1D
替代端口 Alternate根端口的备份——主根端口断时立即接管
备份端口 Backup指定端口的备份(连同一网段的冗余口)
禁用 Disabled不参与

RSTP 快在哪:

  • 建议/同意机制(Proposal/Agreement):握手式协商,不等计时器,收敛秒级。
  • 边缘端口(Edge Port):连终端的口直接进转发态,无需等待——但若收到BPDU会自动变回普通口(BPDU Guard 可防止)。
  • 替代端口即时接管:根端口失效时,Alternate 端口立即进入转发,无需重新计算。
  • 保留 802.1D 兼容模式(BPDU 版本协商)。
记忆:RSTP 收敛约 6 秒(3×2秒Hello)vs 802.1D 约 50 秒。Cisco 默认用 Rapid PVST+(每VLAN一个RSTP实例)。

7.6 STP 的增强特性(考试常考)

特性作用关键命令
PortFast接入端口跳过监听/学习,直接转发(连PC)spanning-tree portfast
BPDU GuardPortFast口收到BPDU→端口err-disable(防伪造根桥攻击)spanning-tree bpduguard enable
Root Guard防止端口成为根端口(保护根桥地位)spanning-tree guard root
Loop Guard防单向链路故障造成"无BPDU误判"导致环路spanning-tree guard loop
UDLD检测单向链路(光纤收发单向)udld enable
STP PortFast BPDU FilterPortFast口直接丢弃BPDUspanning-tree bpdufilter enable
安全组合:接入端口标准配置 = access + PortFast + BPDU Guard——防止用户私接交换机改变STP拓扑。

7.7 配置与验证(含输出解读)

SW1(config)# spanning-tree mode rapid-pvst      # 用Rapid PVST+ (现代默认)
SW1(config)# spanning-tree vlan 10 root primary  # 强制成为VLAN 10根桥(自动降优先级)
SW1(config)# spanning-tree vlan 10 priority 4096 # 手动设优先级(越小越可能当根)
SW1(config)# interface f0/1
SW1(config-if)# switchport mode access
SW1(config-if)# spanning-tree portfast           # 接入口快速转发
SW1(config-if)# spanning-tree bpduguard enable   # 防伪造BPDU
SW1(config-if)# end

SW1# show spanning-tree                          # 核心验证
VLAN0010
  Spanning tree enabled protocol rstp
  Root ID    Priority    4096
             Address     aaaa.bbbb.cccc           ← 根桥MAC(可能是自己或别人)
             Cost        0                       ← 到根桥的开销(根桥上=0)
  Bridge ID  Priority    4096
             Address     aaaa.bbbb.cccc
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Desg FWD 19        128.1     P2p Edge    ← 边缘端口转发
Fa0/2            Root FWD 19        128.2     P2p         ← 根端口转发
Fa0/3            Altn BLK 19        128.3     P2p         ← 替代端口阻塞

SW1# show spanning-tree summary

输出解读要点:看 Root ID 与 Bridge ID 是否相同判断自己是不是根桥;看每口 Role(Root/Desg/Altn/Back)和 Sts(FWD/BLK);Edge 表示PortFast。

7.8 本章自测

Q1. STP 中根桥怎么选?
答:桥ID最小(优先级小者优,其次MAC小者优)。

Q2. 非根桥上,到根桥开销最小的端口是什么?
答:根端口(Root Port)。

Q3. 802.1D 端口从阻塞到转发经过哪几个状态?约需多久?
答:阻塞→监听→学习→转发,约50秒(20+15+15)。

Q4. RSTP 相比 802.1D 快在哪?
答:建议/同意握手、边缘端口直通、替代端口即时接管,收敛约6秒。

Q5. 交换机连接PC的端口应配什么STP特性?
答:PortFast(跳过监听/学习)+ BPDU Guard(防伪造BPDU关端口)。

8EtherChannel · Link Aggregation

Important Bundling multiple physical links into one logical link for more bandwidth and redundancy. After this chapter: explain why plain multi-links get wasted by STP, how EtherChannel solves it, and how to configure LACP and PAgP.

8.1 Why EtherChannel (see the pain point first)

Two switches connected by two cables — what happens? — STP blocks one (to prevent loops) and the other sits idle; bandwidth does not double. If you disable STP, loop storms appear instantly. The pain: redundancy yes, bandwidth wasted.

EtherChannel solves it: bundle 2-8 physical links into one logical port (port-channel). STP treats it as one logical link — no block, no loop; all physical links forward simultaneously, bandwidth adds up (8×1G=8G), and if one link fails the rest keep working (failover).

  • Bandwidth aggregation: logical bandwidth = sum of members (up to 8).
  • Link redundancy: a single physical link failure shifts traffic to the others, millisecond failover.
  • Load balancing: a hash (src/dst MAC, src/dst IP, or combinations) spreads flows across members.
Note: EtherChannel does not guarantee per-flow load balancing — the same "source-destination" pair typically sticks to one link (by hash). It balances "flow sets," not "packets within one flow." Exams occasionally test this detail.

8.2 Member Port Consistency (why channels fail to come up)

All members of an EtherChannel must be identically configured, or the channel fails:

  • Same speed and duplex (e.g., all 1G full)
  • Same switchport mode (all access or all trunk)
  • Same VLAN config (access: same VLAN; trunk: same allowed list and native VLAN)
  • Similar STP config (PortFast etc. as consistent as possible)

Inconsistent ports may go suspended — visible in the show output.

8.3 Negotiation Protocols: LACP vs PAgP (memorize the comparison)

ProtocolStandardModesWhen to use
LACPIEEE 802.3ad (standard, recommended)active (sends LACP PDUs) / passive (waits)Cross-vendor, new deployments
PAgPCisco proprietarydesirable (sends PAgP PDUs) / auto (waits)Cisco-to-Cisco legacy

Mode combination results (exam focus):

One end \ otheractivepassiveon
active✔ negotiates✔ negotiates✔ (on doesn't ask)
passive✔ negotiates✘ both passive, fails✔
on✔✔✔ forced bundle (no negotiation)
Memory: active/desirable = active; passive/auto = passive. At least one active end is needed to negotiate. on = no-negotiation hard bundle (both ends on). Recommended: LACP active-active.

8.4 Configuring EtherChannel (complete commands + verification)

Commands LACP:

SW1(config)# interface range g0/1-4          # pick 4 physical links
SW1(config-if-range)# channel-group 1 mode active   # join channel group 1, LACP active
SW1(config-if-range)# exit
SW1(config)# interface port-channel 1        # enter the logical port
SW1(config-if)# switchport mode trunk        # channel type (match the members)
SW1(config-if)# switchport trunk allowed vlan 10,20,30
SW1(config-if)# exit
# peer SW2 configures identically: channel-group 1 mode active

SW1# show etherchannel summary               # core verification
Flags:  D - down        P - bundled in port-channel
        I - stand-alone s - suspended        H - Hot-standby (LACP only)
        R - Layer3      S - Layer2
Group  Port-channel  Protocol    Ports
------+-------------+-----------+-----------------------------------------------
1      Po1(SU)        LACP       Gi0/1(P)  Gi0/2(P)  Gi0/3(P)  Gi0/4(P)
                    ^^^^
           SU = Layer-2 channel Up (S=Layer2, U=Up) — the key thing to look for
           each port (P) = bundled successfully

SW1# show etherchannel port-channel          # logical port details
SW1# show etherchannel load-balance          # load-balance algorithm (default src-dst-mac)
Troubleshooting: ① look for Po1(SU) in show etherchannel summary; ② a port showing I (stand-alone) or s (suspended) means member config mismatch or negotiation failure; ③ both ends must use the same protocol (LACP↔LACP or PAgP↔PAgP; on works with anything); ④ check member port consistency.

8.5 Load-Balancing Methods (awareness, occasionally tested)

Global config: port-channel load-balance <method>. Common: src-mac, dst-mac, src-dst-mac (default, hashes both), src-ip, dst-ip, src-dst-ip. Layer-3 traffic: hash on IP; Layer-2 traffic: hash on MAC.

8.6 Chapter Self-Test

Q1. Why not just disable STP and use multiple parallel links for more bandwidth?
Ans: Layer-2 loops (broadcast storm, MAC thrash, duplicate frames). EtherChannel bundles the links into one logical link instead.

Q2. What are LACP's active/passive modes?
Ans: active (initiates) / passive (waits).

Q3. What happens if both ends are passive?
Ans: negotiation fails; the channel doesn't come up (neither sends PDUs).

Q4. What happens if one link in an EtherChannel fails?
Ans: traffic shifts to the other members (redundancy); the channel keeps working.

Q5. Which command shows the channel state? What does SU mean?
Ans: show etherchannel summary; S=Layer-2, U=Up — Po1(SU) means the Layer-2 channel is up.

8EtherChannel · 链路聚合

重要 把多条物理链路绑成一条逻辑链路,增加带宽并提供冗余。学完本章要能:解释为什么普通多链路被STP浪费、EtherChannel 怎么解决、LACP 和 PAgP 怎么配。

8.1 为什么需要 EtherChannel(先理解痛点)

两台交换机之间拉两根线会怎样?——STP 会阻塞一根(防环路),另一根空转,带宽没有翻倍。如果直接禁用STP,环路风暴立刻出现。痛点:冗余有了,带宽浪费了。

EtherChannel(以太通道) 的解法:把 2~8 条物理链路捆绑成一个逻辑端口(port-channel)。STP 把它当作一条逻辑链路——不阻塞、不环路,所有物理链路同时转发,带宽叠加(8×1G=8G),一条断掉其他照常(故障转移)。

  • 带宽叠加:逻辑带宽 = 成员链路之和(最高8条)。
  • 链路冗余:单条物理链路故障,流量自动切到其余链路,切换毫秒级。
  • 负载均衡:按哈希算法(源/目的MAC、源/目的IP、或两者组合)把流量分散到各成员链路。
注意:EtherChannel 不保证单条流(flow)的负载均衡——同一个"源-目的"对通常固定走一条链路(按哈希),它均衡的是"流集合",不是"单流的包"。考试偶尔考这个细节。

8.2 成员端口的一致性要求(配置失败的常见原因)

EtherChannel 内所有成员端口必须配置完全一致,否则通道起不来:

  • 相同的速率和双工模式(如都是 1G 全双工)
  • 相同的 Switchport 模式(都是 access 或都是 trunk)
  • 相同的 VLAN 配置(access:同一VLAN;trunk:相同的 allowed 列表和 native VLAN)
  • 相同的 STP 配置(PortFast 等尽量一致)

不一致时,端口可能变成 suspended(挂起),show 输出里能看到。

8.3 协商协议:LACP vs PAgP(必背对比)

协议标准模式何时用
LACPIEEE 802.3ad(标准,推荐)active(主动发LACP报文)/ passive(被动等)跨厂商设备、新部署
PAgPCisco 私有desirable(主动发PAgP报文)/ auto(被动等)Cisco-to-Cisco 老环境

模式组合结果(考试重点):

一端 \ 另一端activepassiveon
active✔ 协商成功✔ 协商成功✔(on不问)
passive✔ 协商成功✘ 都不主动,失败✔
on✔✔✔ 强制捆绑(不协商)
记忆:active/desirable = 主动;passive/auto = 被动。至少一端主动才能协商成。on = 无协商硬绑(两端都要on)。推荐 LACP active-active。

8.4 配置 EtherChannel(完整命令 + 验证)

命令 LACP 配置:

SW1(config)# interface range g0/1-4          # 选4条物理链路
SW1(config-if-range)# channel-group 1 mode active   # 加入通道组1, LACP主动
SW1(config-if-range)# exit
SW1(config)# interface port-channel 1        # 进入逻辑口
SW1(config-if)# switchport mode trunk        # 通道类型(与成员口一致)
SW1(config-if)# switchport trunk allowed vlan 10,20,30
SW1(config-if)# exit
# 对端SW2同样配置: channel-group 1 mode active

SW1# show etherchannel summary               # 核心验证
Flags:  D - down        P - bundled in port-channel
        I - stand-alone s - suspended        H - Hot-standby (LACP only)
        R - Layer3      S - Layer2
Group  Port-channel  Protocol    Ports
------+-------------+-----------+-----------------------------------------------
1      Po1(SU)        LACP       Gi0/1(P)  Gi0/2(P)  Gi0/3(P)  Gi0/4(P)
                    ^^^^
           SU = 二层通道 Up (S=Layer2, U=Up), 关键看这个
           每口 (P) = bundled 成功捆绑

SW1# show etherchannel port-channel          # 查看逻辑口详情
SW1# show etherchannel load-balance          # 负载均衡算法(默认src-dst-mac)
排错:① 看 show etherchannel summary 里 Po1(SU) 的 S 和 U;② 某口是 I(stand-alone)或 s(suspended)说明成员配置不一致或协商失败;③ 两端协议必须匹配(LACP↔LACP 或 PAgP↔PAgP,on 可配任何);④ 检查成员口配置一致性。

8.5 负载均衡方式(了解,偶尔考)

全局配置:port-channel load-balance <method>。常用:src-mac(按源MAC)、dst-mac、src-dst-mac(默认,两者哈希)、src-ip、dst-ip、src-dst-ip。三层流量建议按IP哈希,二层流量按MAC哈希。

8.6 本章自测

Q1. 为什么不用禁用STP+多链路并联来加带宽?
答:会产生二层环路(广播风暴、MAC抖动、重复帧),必须用EtherChannel把多链路捆成一条逻辑链路。

Q2. LACP 的主动/被动模式分别叫什么?
答:active(主动)/ passive(被动)。

Q3. 两端都 passive 会发生什么?
答:协商失败,通道起不来(都不主动发报文)。

Q4. EtherChannel 里一条链路断了会怎样?
答:流量自动转移到其他成员链路(冗余),通道继续工作。

Q5. 用什么命令看通道状态?SU 代表什么?
答:show etherchannel summary;S=二层、U=Up,Po1(SU)=二层通道已启用。

9Static & Default Routes

Core Routing is one of CCNA's two pillars; static routing is the foundation — guaranteed. After this chapter: read a routing table, memorize administrative distances, configure static/default/floating-static routes, and troubleshoot "why doesn't it work."

9.1 The Essence of Routing (build the mental model first)

Routing: the router uses the routing table to decide "out which interface does this packet go, and who is the next hop." Routers look only at the destination IP — not the source, not TCP ports, not who the user is.

A route entry has four elements (memorize): destination network/mask + next hop (or exit interface) + administrative distance (AD) + metric.

R1# show ip route
Codes: C - connected, S - static, R - RIP, O - OSPF, D - EIGRP...

Gateway of last resort is 192.168.1.254 to network 0.0.0.0

      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, GigabitEthernet0/0
L        192.168.1.1/32 is directly connected, GigabitEthernet0/0
S        192.168.2.0/24 [1/0] via 192.168.1.2
                         ^^^  ^  ^
                    AD=1, metric=0, next hop=192.168.1.2
O        10.0.0.0/24 [110/2] via 192.168.3.1, 00:12:34, GigabitEthernet0/1
S*       0.0.0.0/0 [1/0] via 192.168.1.254        ← default route (asterisk)
                           ^^^  ^  ^
                     C=connected, L=local, S=static, O=OSPF, S*=default

Know the codes: C (connected), L (local/interface IP), S (static), S* (default route), O (OSPF), R (RIP), D (EIGRP).

9.2 Administrative Distance (AD) — memorize the table

A router may learn the same destination from multiple sources (static, OSPF, connected...). AD expresses the trustworthiness of a route source; smaller is more trusted. The source with the smallest AD goes into the routing table.

Route sourceADNotes
Connected0Directly attached networks — most trusted
Static1Manually configured
EIGRP summary5Summary route
EIGRP90Cisco proprietary (awareness for newer CCNA)
OSPF110Link-state
RIP120Distance-vector
Unreachable255Not used
Memory: 0 connected, 1 static, 90 EIGRP, 110 OSPF, 120 RIP — "0 1 90 110 120" as a chant. Smaller AD wins; with equal AD, compare metric (also smaller wins).

9.3 Route Decision Logic (three comparisons, in order)

Longest prefix match: when a destination IP matches multiple entries, the one with the longest mask (most specific) wins. E.g., to reach 192.168.1.5 with both 192.168.1.0/24 and 192.168.1.0/28 in the table, take /28.
Compare AD: same prefix length, smaller AD wins.
Compare metric: same source (equal AD), smaller metric (cost/hops) wins.
Classic trap: longest match beats AD. Even if OSPF (AD 110) has a /28 and a static (AD 1) has a /24 matching the same IP, the OSPF /28 wins — because "specificity" outranks "trustworthiness." Exams love this trap.

9.4 Configuring Static Routes (complete commands)

Commands Two syntaxes — master both:

# Syntax 1: next-hop IP (recommended, works across multiple hops)
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.1.2
#        [destination]    [mask]       [next-hop IP]

# Syntax 2: exit interface (common on point-to-point links, e.g., serial)
R1(config)# ip route 192.168.2.0 255.255.255.0 serial0/0/0

# Default route: destination 0.0.0.0/0, "everything not matched goes here"
R1(config)# ip route 0.0.0.0 0.0.0.0 192.168.1.254

# Floating static route (backup): set a higher AD; it only activates when the primary fails
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.1.2        # primary (AD=1)
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.9.2 200   # backup (AD=200)

# Delete: prefix with no
R1(config)# no ip route 192.168.2.0 255.255.255.0 192.168.1.2

# Verify
R1# show ip route static      # static routes only
R1# show ip route             # all

9.5 The Static Route Trap: one-way config doesn't work

Static routes are one-way — they only affect the router that has them. If A has a route to B's network but B has no route back to A, then A→B works and B→A doesn't. For two-way communication, configure both sides. This is the classic lab trap: configuring one side and calling it "broken."

How to tell: when a packet reaches the far router, that router consults its routing table for the return path; without one it drops the packet (or uses a default route). ping proves one-way reachability only; two-way requires return routes on both ends.

9.6 Typical Default-Route Scenarios

  • Stub network: one exit only — point all traffic at the exit router with a default route instead of hundreds of detail routes.
  • Internet egress: on the border router, ip route 0.0.0.0 0.0.0.0 <ISP peer IP>.
  • The router sends "everything unknown" to its default gateway (analogous to a host's default gateway concept).

Note the distinction: default route (0.0.0.0/0) vs a host's default gateway — same concept (the exit for unknown destinations), one on a router, one on a PC.

9.7 Troubleshooting Flow (lab mindset)

① ping destination → works?
② traceroute hop by hop → where does it break?
③ On the breaking router:
   show ip route  → is there a matching route?
     Yes → is the next hop reachable (ping it)?
     No  → configure static/default route
④ Check the far end's return route (the most common miss!)
⑤ Check ACL/NAT interference

9.8 Chapter Self-Test

Q1. Administrative distances of OSPF and static?
Ans: OSPF=110, static=1.

Q2. A static /24 and an OSPF /28 both match the destination. Which wins?
Ans: the OSPF /28 — longest prefix match outranks AD.

Q3. How do you write a default route?
Ans: ip route 0.0.0.0 0.0.0.0 <next-hop>.

Q4. What makes a floating static route a backup?
Ans: a larger AD (e.g., 200) — it enters the table only when the primary fails.

Q5. A has a route to B's network, B has none back. Does A ping B? B ping A?
Ans: A→B yes (A has the forward route); B→A no (B lacks the return route) — routing must be two-way.

9静态路由与默认路由

核心 路由是 CCNA 两大支柱之一,静态路由是基础,必考。学完本章要能:读懂路由表、背出管理距离、配静态/默认/浮动静态路由、判断"为什么不通"。

9.1 路由的本质(先建立心智模型)

路由(Routing):路由器根据路由表(Routing Table)决定"数据包从哪个接口出去、下一跳给谁"的过程。路由器只看目的IP——不关心源IP、不关心TCP端口、不关心用户是谁。

路由表条目包含四个要素(背):目的网络/掩码 + 下一跳(或出接口)+ 管理距离(AD)+ 度量(Metric)。

R1# show ip route
Codes: C - connected, S - static, R - RIP, O - OSPF, D - EIGRP...

Gateway of last resort is 192.168.1.254 to network 0.0.0.0

      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, GigabitEthernet0/0
L        192.168.1.1/32 is directly connected, GigabitEthernet0/0
S        192.168.2.0/24 [1/0] via 192.168.1.2
                         ^^^  ^  ^
                    AD=1, 度量=0, 下一跳=192.168.1.2
O        10.0.0.0/24 [110/2] via 192.168.3.1, 00:12:34, GigabitEthernet0/1
S*       0.0.0.0/0 [1/0] via 192.168.1.254        ← 默认路由(星号*)
                           ^^^  ^  ^
                     C=直连, L=本地, S=静态, O=OSPF, S*=默认

Codes 要认全:C(直连)、L(本地/接口IP)、S(静态)、S*(默认路由)、O(OSPF)、R(RIP)、D(EIGRP)。

9.2 管理距离(AD,Administrative Distance)——必背表

同一路由器可能从多个来源学到同一目的网络(静态、OSPF、直连…)。AD 表示路由来源的可信度,值越小越可信。选 AD 最小的来源放进路由表。

路由来源AD说明
直连 Connected0接口直接相连的网络,最可信
静态 Static1手工配置
EIGRP 汇总5汇总路由
EIGRP90Cisco 私有(较新CCNA了解即可)
OSPF110链路状态
RIP120距离向量
不可达255不使用
记忆:0直连、1静态、90 EIGRP、110 OSPF、120 RIP——"0 1 90 110 120"顺口溜。AD 小者优先,同AD比度量(metric),度量也是小者优先。

9.3 路由决策逻辑(三个比较,顺序不能乱)

最长前缀匹配:目的IP匹配多个条目时,掩码最长(最具体)的条目优先。例:去 192.168.1.5,表里有 192.168.1.0/24 和 192.168.1.0/28,走 /28(更具体)。
比 AD:前缀长度相同,AD 小者入选。
比度量:来源相同(AD相同),度量(cost/跳数)小者入选。
经典易错:最长匹配优先于 AD。就算 OSPF(AD 110)的 /28 和静态(AD 1)的 /24 同时匹配,也是 OSPF 的 /28 优先——因为"具体性"高于"可信度"。考试最爱挖这个坑。

9.4 配置静态路由(完整命令)

命令 两种写法,必须都掌握:

# 写法1: 指定下一跳IP(推荐,可跨越多跳)
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.1.2
#        [目的网络]     [掩码]       [下一跳IP]

# 写法2: 指定出接口(点对点链路常用,如串口)
R1(config)# ip route 192.168.2.0 255.255.255.0 serial0/0/0

# 默认路由: 目的0.0.0.0/0, "所有没匹配的路由都走这里"
R1(config)# ip route 0.0.0.0 0.0.0.0 192.168.1.254

# 浮动静态路由(备份): AD设大些, 主路由失效才启用
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.1.2         # 主(AD=1)
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.9.2 200    # 备(AD=200)

# 删除: 前面加 no
R1(config)# no ip route 192.168.2.0 255.255.255.0 192.168.1.2

# 验证
R1# show ip route static      # 只看静态路由
R1# show ip route             # 全部

9.5 静态路由的通病:单向配置不通(双向路由)

静态路由是单向的——只影响配置它的那台路由器。A 配了到B网络的路由,B 没配到A网络的路由,则 A→B 通、B→A 不通。要双向通信,两端都要配。这是实验题最常挖的坑:配了单边就说"不通"。

判断方法:数据包到达对端路由器后,对端查路由表找回程路由;没有就直接丢弃(或走默认路由)。ping 只能证明单向通,双向通必须看两端的回程。

9.6 默认路由的典型场景

  • 末梢网络(Stub Network):只有一个出口的网络,用默认路由把所有流量指向出口路由器——不用配上百条明细。
  • 出口到Internet:边界路由器上 ip route 0.0.0.0 0.0.0.0 运营商对端IP。
  • 路由器把"所有未知目的"都交给默认网关(类似主机的 default gateway 概念)。

注意区分:默认路由(0.0.0.0/0)vs 主机的默认网关——概念一样(都指"去未知网络的出口"),一个配在路由器、一个配在PC。

9.7 排错流程(实验题必备思路)

① ping 目的IP → 通?不通?
② 逐跳 traceroute → 断在哪一跳?
③ 在断的那台路由器:
   show ip route <目的IP> → 有没有匹配路由?
     有 → 看下一跳可达吗(ping下一跳)?
     没有 → 配静态/默认路由
④ 检查对端回程路由(最常见遗漏!)
⑤ 检查ACL/NAT是否拦截

9.8 本章自测

Q1. OSPF 和静态路由的管理距离分别是多少?
答:OSPF=110,静态=1。

Q2. 到同一网络同时有静态(/24)和 OSPF(/28)路由,实际用哪条?
答:OSPF 的 /28——最长前缀匹配优先于 AD。

Q3. 默认路由怎么写?
答:ip route 0.0.0.0 0.0.0.0 <下一跳>。

Q4. 浮动静态路由靠什么实现备份?
答:把备用路由的 AD 设大(如200),主路由失效才进路由表。

Q5. A配了去B网的路由,B没配去A网的路由,A ping B通吗?B ping A呢?
答:A→B通(A有去程);B→A不通(B没回程)——路由必须双向。

10OSPF Dynamic Routing

Core OSPF is the representative link-state protocol; CCNA focuses on single-area OSPFv2. After this chapter: explain link-state vs distance-vector, how OSPF builds neighbors/adjacencies/DR, configure single-area OSPF, and troubleshoot it.

10.1 Why Dynamic Routing

Static routing suits small networks, but at scale (dozens or hundreds of routers) it becomes unmaintainable: adding a link means reconfiguring a pile of routers, topology changes need manual rework, and errors creep in. Dynamic routing protocols let routers exchange information, compute routes, and adapt on their own.

The two big families (a must-know comparison):

TypeRepresentativesPrincipleProsCons
Distance VectorRIP, EIGRP (hybrid)"Hears from neighbors" — advertises its own table to neighbors, accumulates by hop/metric — "routing by rumor"Simple, light on resourcesSlow convergence, loop risk (needs split horizon / poison reverse)
Link StateOSPF, IS-IS"Sees the whole map" — collects all link states (LSDB), computes shortest paths itself with SPFFast convergence, loop-free, VLSM/CIDR supportCPU/memory heavy, needs hierarchy (areas)
One-liner: distance-vector "trusts the neighbors" (hearsay); link-state "sees the full map" (computes itself). OSPF is link-state; RIP is distance-vector.

10.2 How OSPF Works (neighbor → adjacency → LSDB → SPF → table)

Become neighbors: after the interface is up, send periodic Hello packets (multicast 224.0.0.5). Matching Hello parameters (area ID, Hello/Dead timers, authentication) → neighbor state 2-Way.
Build adjacencies: neighbors exchange LSAs (Link State Advertisements) — each router describes its directly connected links, interfaces, networks, and metrics. All LSAs merge into the LSDB (Link State Database) (state Full, exchange complete).
Run SPF: each router runs Dijkstra's algorithm on its LSDB, rooted at itself, computing the shortest-path tree and generating the routing table.
Maintain: Hello keeps it alive (10s; Dead 40s); topology changes trigger incremental LSA updates and full convergence.

Neighbor states to know: 2-Way (neighbors established, no LSA exchange yet), Full (adjacency complete, LSDB synchronized) — in show ip ospf neighbor, Full is the healthy state.

10.3 Key OSPF Parameters (memorize the numbers)

ParameterValueNotes
Administrative distance110Route trustworthiness
Hello intervalEthernet 10 s (point-to-point 10s, NBMA 30s)Periodic keepalive
Dead interval40 s (4× Hello)Neighbor declared dead after silence
Multicast addresses224.0.0.5 (all OSPF routers) / 224.0.0.6 (DR/BDR)Targets for Hello/LSA
Metric cost10^8 / bandwidth (bps)Smaller is better; manually adjustable
Area0 = backboneCCNA only tests single-area (all in Area 0)

Cost examples: 100 Mbps → cost 1 (10^8/10^8), 1 Gbps → cost 1 (10^8/10^9, rounds to 1), 10 Mbps → cost 10. Exams test "how to compute cost and how changing it affects path selection."

10.4 Router ID Selection (a must-know rule)

The Router ID uniquely identifies the OSPF process (32-bit, looks like an IP). Selection priority:

Manually configured router-id (highest priority — recommended, use a loopback).
Highest loopback interface IP (logical, stable, never goes down).
Highest active physical interface IP.

Important: once the Router ID is chosen it is "locked" — changing interface IPs later does not change it unless you clear ip ospf process or restart OSPF. DR/BDR election prefers the higher Router ID.

10.5 DR / BDR (the multi-access network mechanism)

On a broadcast multi-access network (Ethernet), if every router formed adjacencies with every other, N routers would need N(N-1)/2 adjacencies — wasteful. OSPF elects:

  • DR (Designated Router): represents the segment, exchanges LSAs with everyone (all routers sync only with the DR).
  • BDR (Backup Designated Router): backup; takes over instantly if the DR fails.
  • Other routers (DROTHER) form Full adjacencies only with DR/BDR; between themselves they stay at 2-Way (neighbors, no LSA exchange).

Election rules (memorize): highest interface priority first (default 1; 0 = never participate) → tie-break by highest Router ID. DR/BDR election is non-preemptive — a better new router does not replace an elected one (unless the whole network restarts).

Point: DR/BDR exist only on multi-access networks (Ethernet); point-to-point links have no DR/BDR (e.g., two routers serial-connected). Exams ask "when do DR/BDR exist."

10.6 Configuring Single-Area OSPF (complete commands + verification)

Commands

R1(config)# router ospf 1              # start OSPF process 1 (process ID is local; peers may differ)
R1(config-router)# router-id 1.1.1.1   # manually set the Router ID (recommended)
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0   # advertise the interface's network
R1(config-router)# network 192.168.12.0 0.0.0.255 area 0  # wildcard mask!
R1(config-router)# exit

# Note: network advertises "the network the interface is in"; wildcard = inverted mask
# 255.255.255.0 → 0.0.0.255 ; 255.255.255.128 → 0.0.0.127

R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 192.168.12.0 0.0.0.255 area 0
R2(config-router)# network 192.168.2.0 0.0.0.255 area 0

# Verify
R1# show ip ospf neighbor           # neighbor state (Full = OK)
R1# show ip ospf interface          # Hello/Dead, area, cost
R1# show ip route ospf              # OSPF-learned routes
R1# show ip ospf database           # LSDB
R1# clear ip ospf process           # reset OSPF (must do after changing Router ID)

Neighbor verification output:

R1# show ip ospf neighbor
Neighbor ID  Pri  State      Dead Time  Address        Interface
2.2.2.2        1  FULL/DR    00:00:35   192.168.12.2   GigabitEthernet0/0
                        ^^^^
               FULL = adjacency complete, /DR = peer is the DR

10.7 OSPF Troubleshooting (lab mindset)

① show ip ospf neighbor → is there a neighbor? What state?
   - No neighbor: interface up? Same area on both ends? Hello/Dead match? Auth match? Network type match?
   - Stuck at 2-Way: normal between DROTHERs — check whether a DR exists
   - Stuck at EXSTART/EXCHANGE: usually MTU mismatch or LSA exchange issues
② show ip route ospf → did you learn routes?
   - No: check whether network statements cover the interface networks
③ Check the wildcard mask (the most common error!)
④ Process IDs on both ends are irrelevant, but Router IDs must be unique network-wide

10.8 Chapter Self-Test

Q1. OSPF's AD? Hello and Dead intervals on Ethernet?
Ans: AD=110; Hello 10s, Dead 40s.

Q2. Which multicast addresses does OSPF use? DR/BDR?
Ans: 224.0.0.5 (all OSPF); 224.0.0.6 (DR/BDR).

Q3. Which networks elect DR/BDR?
Ans: multi-access networks (Ethernet); point-to-point links do not.

Q4. Router ID selection order?
Ans: manual → highest loopback IP → highest active physical interface IP.

Q5. What wildcard mask for advertising 192.168.1.0/24?
Ans: 0.0.0.255.

10OSPF 动态路由协议

核心 OSPF 是链路状态协议的代表,CCNA 重点考单区域 OSPFv2。学完本章要能:说清链路状态 vs 距离向量的区别、OSPF 怎么选邻居/邻接/DR、配单区域 OSPF 并排错。

10.1 为什么需要动态路由

静态路由适合小网络,但网络一大(几十上百台路由器)就不可维护:加一条链路要改一堆路由器、拓扑变化要人工重配、还容易配错。动态路由协议让路由器自己交换信息、自己算出路由、自己适应变化。

两大类(考试必考对比):

类型代表原理优点缺点
距离向量 Distance VectorRIP, EIGRP(混合)"听邻居的"——只向邻居通告自己的路由表,按跳数/度量累加,"传闻路由"(routing by rumor)简单、省资源收敛慢、有环路风险(需水平分割/毒性反转)
链路状态 Link StateOSPF, IS-IS"看全图"——每台路由器收集全网链路状态(LSDB),用 SPF 算法自己算最短路径收敛快、无环路、支持VLSM/CIDR消耗CPU/内存,需分层(区域)
一句话:距离向量"听邻居的"(相信传闻),链路状态"看全图的"(自己算)。OSPF 是链路状态,RIP 是距离向量。

10.2 OSPF 工作原理(邻居→邻接→LSDB→SPF→路由表)

建立邻居(Neighbor):接口 up 后周期发 Hello 报文(组播 224.0.0.5),Hello 参数一致(区域ID、Hello/Dead间隔、认证等)→ 邻居关系建立(状态 2-Way)。
建立邻接(Adjacency):邻居之间交换 LSA(链路状态通告)——每台路由器描述自己的直连链路、接口、网络、度量。所有 LSA 汇总成 LSDB(链路状态数据库)(状态 Full,交换完成)。
运行 SPF 算法:每台路由器以自己为根,用 Dijkstra 算法 对 LSDB 计算最短路径树,生成路由表。
维护:Hello 持续保活(10秒一发,Dead 40秒);拓扑变化时增量更新 LSA(触发更新),全网重新收敛。

邻居状态重点:2-Way(邻居建立、还没交换LSA)、Full(邻接完成、LSDB同步)——考试看 show ip ospf neighbor 的状态字段,Full 才是完全正常。

10.3 OSPF 关键参数(背数字)

参数值说明
管理距离 AD110路由可信度
Hello 间隔以太网 10秒(点对点10秒,NBMA 30秒)周期保活报文
Dead 间隔40秒(4×Hello)超时未收Hello即邻居失效
组播地址224.0.0.5(所有OSPF路由器)/ 224.0.0.6(DR/BDR)Hello/LSA 发送目标
度量 Cost10^8 / 带宽(bps)越小越优;可手动改
区域 Area0 = 骨干区CCNA 只考单区域(都在Area 0)

Cost 示例:100Mbps→cost 1(10^8/10^8),1Gbps→cost 1(10^8/10^9 取整=1)……实际上千兆 cost=1、百兆=1、10M=10(10^8/10^7)。考试常考"怎么算 cost 以及改 cost 影响选路"。

10.4 Router ID 的选择(必考规则)

Router ID 是 OSPF 进程的唯一标识(32位,像IP)。选择优先级:

手动配置 router-id(最高优先,推荐用 loopback 地址)。
最高 loopback 接口 IP(逻辑接口,稳定不会down)。
最高的活动物理接口 IP。

重要:Router ID 选好后就"锁定"了,即使后面改了接口IP也不会变——除非 clear ip ospf process 或重启 OSPF。DR/BDR 选举时 Router ID 大者优先。

10.5 DR / BDR(多路访问网络的关键机制)

在广播多路访问网络(以太网)上,如果所有路由器两两建邻接,N台要 N(N-1)/2 个邻接——太浪费。OSPF 选出:

  • DR(Designated Router,指定路由器):代表该网段与所有路由器交换 LSA(所有人只和 DR 同步)。
  • BDR(Backup DR,备份指定路由器):DR 的备份,DR 挂了立刻顶上。
  • 其他路由器(DROTHER)只与 DR/BDR 建 Full 邻接,互相之间停在 2-Way(邻居,不交换LSA)。

选举规则(背):接口优先级大者优先(默认1,0=不参与选举)→ 平局比 Router ID 大者。DR/BDR 选举不可抢占——已经当选的不会因新来的更优而换(除非全网络重启)。

要点:DR/BDR 只存在于多路访问网络(以太网);点对点链路没有 DR/BDR(如两台路由器串口直连)。考试常考"什么时候有DR/BDR"。

10.6 配置单区域 OSPF(完整命令 + 验证)

命令

R1(config)# router ospf 1              # 启动OSPF进程1(进程号本地有意义,两端可不同)
R1(config-router)# router-id 1.1.1.1   # 建议手动设Router ID
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0   # 宣告接口所在网络
R1(config-router)# network 192.168.12.0 0.0.0.255 area 0  # 反掩码!
R1(config-router)# exit

# 注意: network 宣告的是"接口所在的网络", 反掩码=掩码取反
# 255.255.255.0 → 0.0.0.255 ; 255.255.255.128 → 0.0.0.127

R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 192.168.12.0 0.0.0.255 area 0
R2(config-router)# network 192.168.2.0 0.0.0.255 area 0

# 验证
R1# show ip ospf neighbor           # 邻居状态(Full=OK)
R1# show ip ospf interface          # 看Hello/Dead/区域/Cost
R1# show ip route ospf              # 看OSPF学到的路由
R1# show ip ospf database           # 看LSDB
R1# clear ip ospf process           # 重置OSPF进程(改Router ID后必做)

邻居验证输出:

R1# show ip ospf neighbor
Neighbor ID  Pri  State      Dead Time  Address        Interface
2.2.2.2        1  FULL/DR    00:00:35   192.168.12.2   GigabitEthernet0/0
                        ^^^^
               FULL = 邻接完成, /DR = 对端是DR

10.7 OSPF 排错(实验题思路)

① show ip ospf neighbor → 邻居存在吗? 状态?
   - 没有邻居: 接口up? 两端是否同区域? Hello/Dead一致? 认证一致? 网络类型一致?
   - 停在2-Way: 说明是DROTHER之间(正常), 看是否有DR
   - 停在EXSTART/EXCHANGE: 通常MTU不匹配或LSA交换问题
② show ip route ospf → 路由学到了吗?
   - 没有: 检查network宣告是否覆盖接口网络
③ 检查反掩码是否正确(最常见错误!)
④ 检查两端进程号无关, 但Router ID必须全网唯一

10.8 本章自测

Q1. OSPF 的管理距离是?Hello 间隔和 Dead 间隔(以太网)?
答:AD=110;Hello 10秒,Dead 40秒。

Q2. OSPF 用哪个组播地址?DR/BDR 用哪个?
答:224.0.0.5(所有OSPF);224.0.0.6(DR/BDR)。

Q3. 哪些网络需要选 DR/BDR?
答:多路访问网络(以太网);点对点链路不需要。

Q4. Router ID 的选择顺序?
答:手动配置 → 最高loopback IP → 最高活动物理接口IP。

Q5. network 192.168.1.0 255.255.255.0 宣告时反掩码写什么?
答:0.0.0.255。

11IPv6 Fundamentals

Important The modern CCNA requires IPv6 addressing and basic configuration. After this chapter: read compressed/expanded IPv6 addresses, name the address types and prefixes, configure interface IPv6 addresses, and explain IPv6 neighbor discovery.

11.1 Why IPv6 (IPv4's three pain points)

  • Address exhaustion: IPv4 has only ~4.3 billion addresses (2^32), long since exhausted. IPv6 has 2^128 — every grain of sand on Earth could get billions.
  • The NAT burden: IPv4 leans on NAT to survive, but NAT breaks end-to-end transparency, complicates troubleshooting, and affects some protocols. IPv6 has native address abundance, so NAT is not needed — end-to-end is restored.
  • Autoconfiguration: IPv4 needs DHCP; IPv6 has SLAAC (Stateless Address Autoconfiguration) — hosts generate addresses automatically.

11.2 IPv6 Address Structure (reading 128 bits)

An IPv6 address is 128 bits, written as 8 groups of 4 hex digits, colon-separated:

Full form: 2001:0db8:0000:0000:0000:ff00:0042:8329
Compression rules:
① Leading zeros per group may be omitted:
   2001:db8:0:0:0:ff00:42:8329
② One run of all-zero groups may be compressed with :: (once only!):
   2001:db8::ff00:42:8329
   Note: :: only once — twice is ambiguous
Examples: 2001:db8::1        = 2001:0db8:0000:...:0001
    ::1                      = loopback (0:0:...:0:1)
    ::                       = unspecified address
Exam traps: ① :: may appear once; ② when expanding, count "how many zero groups are missing" and fill them; ③ ::1 is loopback (IPv4's 127.0.0.1), :: is unspecified (IPv4's 0.0.0.0); ④ IPv6 has no broadcast addresses.

11.3 Address Types & Prefixes (memorize the table)

TypePrefixPurposeNotes
Global Unicast (GUA)2000::/3Public unique address, routableLike IPv4 public
Unique Local (ULA)fc00::/7Private internal addressesLike IPv4 private (10.x / 192.168.x)
Link-Localfe80::/10Same-link communication, auto-generatedEvery interface has one; not routable; used for NDP/routing protocols
Loopback::1/128Self-testLike 127.0.0.1
Unspecified::/128Source address not yet assignedLike 0.0.0.0
Multicastff00::/8One-to-manyIPv6 has no broadcast — multicast replaces it
Anycast—Shared by multiple interfaces; delivers to the nearestNew IPv6 concept

Common multicast addresses: ff02::1 (all nodes), ff02::2 (all routers), ff02::5 (OSPFv3), ff02::9 (RIPng), ff02::1:ffxx:xxxx (solicited-node, for NDP).

11.4 Link-Local & EUI-64 (exam item)

Every IPv6 interface auto-generates a link-local address (fe80::/10), even with no configured address. By default it derives the interface ID via EUI-64 (from MAC):

MAC:  00:1A:2B:3C:4D:5E
Step 1: insert fffe in the middle → 001A:2BFF:FE3C:4D5E
Step 2: flip bit 7 (U/L bit) → 021A:2BFF:FE3C:4D5E
Result: interface ID = 021A:2BFF:FE3C:4D5E
Link-local = fe80::021A:2BFF:FE3C:4D5E
Memory: EUI-64 = insert FFFE in the middle of the MAC + flip bit 7. Cisco also allows manual interface IDs (e.g., ipv6 address fe80::1 link-local).

11.5 IPv6 Neighbor Discovery (NDP — replaces ARP)

IPv6 has no ARP; NDP (Neighbor Discovery Protocol) does the same job, built on ICMPv6:

MessageWhat it doesLike
NS (Neighbor Solicitation)Asks "who has this address?" (multicast to solicited-node)ARP request
NA (Neighbor Advertisement)Replies "I have it" (unicast reply)ARP reply
RS (Router Solicitation)Host at boot asks "who is the router?"—
RA (Router Advertisement)Router periodically advertises prefix, default gateway, SLAAC infoDHCP announcement
DAD (Duplicate Address Detection)Checks for conflicts before configuring an addressARP probe

SLAAC: a host receives an RA (with a /64 prefix) and auto-generates a GUA using its EUI-64 interface ID — no DHCP needed. For extra info (DNS), pair it with DHCPv6.

11.6 Configuring IPv6 (complete commands)

Commands

R1(config)# ipv6 unicast-routing          # enable IPv6 routing (routers; not switches)
R1(config)# interface g0/0
R1(config-if)# ipv6 address 2001:db8:1::1/64   # configure a GUA
R1(config-if)# ipv6 address fe80::1 link-local # (optional) manual link-local
R1(config-if)# no shutdown

# Static routes
R1(config)# ipv6 route 2001:db8:2::/64 2001:db8:12::2
R1(config)# ipv6 route ::/0 2001:db8:12::254   # IPv6 default route (::/0)

# OSPFv3 (IPv6 OSPF — awareness)
R1(config)# ipv6 router ospf 1
R1(config-rtr)# router-id 1.1.1.1
R1(config)# interface g0/0
R1(config-if)# ipv6 ospf 1 area 0

# Verify
R1# show ipv6 interface brief
R1# show ipv6 route
R1# show ipv6 neighbors

11.7 IPv4 vs IPv6 (frequently compared)

DimensionIPv4IPv6
Address length32 bits128 bits
NotationDotted decimalColon hex
Address count2^322^128
BroadcastYesNo (multicast instead)
Address resolutionARPNDP (ICMPv6)
AutoconfigurationDHCPSLAAC + DHCPv6
NATUbiquitousNot needed by design
FragmentationRouters can fragmentOnly source fragments (path MTU discovery)

11.8 Chapter Self-Test

Q1. Compress 2001:0db8:0000:0000:0000:0000:0000:0001
Ans: 2001:db8::1.

Q2. IPv6 loopback and unspecified addresses?
Ans: ::1 and ::.

Q3. Link-local prefix? Is it routable?
Ans: fe80::/10; no, same-link only.

Q4. Which protocol replaces ARP in IPv6?
Ans: NDP (NS/NA, based on ICMPv6).

Q5. Which command enables IPv6 routing on a router?
Ans: ipv6 unicast-routing.

11IPv6 基础

重要 现代 CCNA 必考 IPv6 寻址与基本配置。学完本章要能:看懂压缩/展开IPv6地址、说出地址类型与前缀、配接口IPv6地址、说清IPv6邻居发现。

11.1 为什么需要 IPv6(IPv4 的三大痛点)

  • 地址枯竭:IPv4 只有约 43 亿个地址(2^32),早已耗尽。IPv6 有 2^128 个地址——地球上每粒沙子都能分到亿万个。
  • NAT 的负担:IPv4 靠 NAT 缓解枯竭,但 NAT 破坏端到端透明性、增加排错复杂度、影响某些协议。IPv6 原生海量地址,可以不做 NAT,恢复端到端。
  • 自动配置:IPv4 需要 DHCP;IPv6 有 SLAAC(无状态自动配置),主机可自动生成地址。

11.2 IPv6 地址结构(128位怎么读写)

IPv6 地址是 128 位,写作 8 组 4 位十六进制,组间冒号分隔:

完整形式: 2001:0db8:0000:0000:0000:ff00:0042:8329
压缩规则:
① 每组前导0可省略:
   2001:db8:0:0:0:ff00:42:8329
② 连续的全0组可用 :: 压缩一次(只能一次!):
   2001:db8::ff00:42:8329
   注意: :: 只能用一次, 用两次会产生歧义
例: 2001:db8::1        = 2001:0db8:0000:...:0001
    ::1                = 环回 (0:0:...:0:1)
    ::                 = 未指定地址
考试陷阱:① :: 只能出现一次;② 展开时数"还差几组0"补进去;③ ::1 是环回(IPv4的127.0.0.1),:: 是未指定(IPv4的0.0.0.0);④ IPv6 没有广播地址。

11.3 地址类型与前缀(必背表)

类型前缀用途备注
全球单播 GUA2000::/3公网唯一地址,可路由类似IPv4公网IP
唯一本地 ULAfc00::/7内网私用地址类似IPv4私网(10.x/192.168.x)
链路本地 Link-Localfe80::/10同一链路内通信,自动生成每接口必有;不可路由;用于邻居发现/路由协议
环回 Loopback::1/128本机自测类似127.0.0.1
未指定 Unspecified::/128源地址未分配时类似0.0.0.0
组播 Multicastff00::/8一对多IPv6无广播,用组播替代
任播 Anycast—多个接口共享,发给最近者IPv6新增概念

常用组播地址:ff02::1(所有节点)、ff02::2(所有路由器)、ff02::5(OSPFv3)、ff02::9(RIPng)、ff02::1:ffxx:xxxx(被请求节点组播,用于邻居发现)。

11.4 链路本地地址与 EUI-64(考点)

每个 IPv6 接口自动生成一个链路本地地址(fe80::/10),即使没配任何地址也有。默认从 EUI-64(基于MAC)生成接口标识:

MAC:  00:1A:2B:3C:4D:5E
步骤1: 中间插入 fffe → 001A:2BFF:FE3C:4D5E
步骤2: 翻转第7位(U/L位) → 021A:2BFF:FE3C:4D5E
结果: 接口ID = 021A:2BFF:FE3C:4D5E
链路本地 = fe80::021A:2BFF:FE3C:4D5E
记忆:EUI-64 = MAC中间插FFFE + 第7位翻转。Cisco 默认接口ID也可手动指定(如 ipv6 address fe80::1 link-local)。

11.5 IPv6 邻居发现(NDP,替代 ARP)

IPv6 没有 ARP,用 NDP(Neighbor Discovery Protocol) 完成同样的活,基于 ICMPv6:

消息作用类似
NS(邻居请求)问"谁有某地址?"(组播到被请求节点)ARP请求
NA(邻居通告)回"我有"(单播回复)ARP应答
RS(路由器请求)主机开机问"谁是路由器?"—
RA(路由器通告)路由器周期性通告前缀、默认网关、SLAAC信息DHCP通告
DAD(重复地址检测)配置地址前先检测是否冲突ARP探测

SLAAC(无状态地址自动配置):主机收到 RA(含 /64 前缀)后,用自己的 EUI-64 接口ID 自动生成全球单播地址,无需 DHCP。需要额外信息(DNS)时配合 DHCPv6。

11.6 配置 IPv6(完整命令)

命令

R1(config)# ipv6 unicast-routing          # 启用IPv6路由(路由器必做,交换机不做)
R1(config)# interface g0/0
R1(config-if)# ipv6 address 2001:db8:1::1/64   # 配全球单播地址
R1(config-if)# ipv6 address fe80::1 link-local # (可选)手动指定链路本地
R1(config-if)# no shutdown

# 静态路由
R1(config)# ipv6 route 2001:db8:2::/64 2001:db8:12::2
R1(config)# ipv6 route ::/0 2001:db8:12::254   # IPv6默认路由(::/0)

# OSPFv3 (IPv6版OSPF, 了解)
R1(config)# ipv6 router ospf 1
R1(config-rtr)# router-id 1.1.1.1
R1(config)# interface g0/0
R1(config-if)# ipv6 ospf 1 area 0

# 验证
R1# show ipv6 interface brief
R1# show ipv6 route
R1# show ipv6 neighbors

11.7 IPv4 vs IPv6 对比(考试常考)

维度IPv4IPv6
地址长度32位128位
表示点分十进制冒号十六进制
地址数量2^322^128
广播有无(用组播替代)
地址解析ARPNDP(ICMPv6)
自动配置DHCPSLAAC + DHCPv6
NAT普遍使用设计上不需要
分片路由器可分片仅源端可发分片(路径MTU发现)

11.8 本章自测

Q1. 压缩 2001:0db8:0000:0000:0000:0000:0000:0001
答:2001:db8::1。

Q2. IPv6 的环回地址是?未指定地址是?
答:::1;::。

Q3. 链路本地地址的前缀是?它能否被路由?
答:fe80::/10;不能,只能同一链路通信。

Q4. IPv6 用什么协议替代 ARP?
答:NDP 邻居发现协议(NS/NA 基于 ICMPv6)。

Q5. 路由器上要启用 IPv6 路由必须敲什么命令?
答:ipv6 unicast-routing。

12DHCP · NAT · DNS

Core The big three IP services — NAT is a guaranteed calculation/config topic. After this chapter: explain DHCP's four steps, NAT's three types and configuration, and the DNS resolution flow.

12.1 DHCP Deep Dive

DHCP automatically assigns IP address, mask, default gateway, and DNS, saving per-host manual configuration. Ports: UDP 67 (server), 68 (client).

The working process (DORA, memorize):

Client                                   DHCP server
   |---- Discover (broadcast) ----->|  ① Find servers: "who can give me an IP?" (broadcast to 255.255.255.255)
   |<---- Offer (unicast/broadcast) ----|  ② Server offers: "I can give you 192.168.1.100"
   |---- Request (broadcast) ----->|  ③ Client requests: "I want that address" (broadcast so all servers know)
   |<---- Ack (unicast/broadcast) -----|  ④ Server confirms: "OK, leased to you for X seconds"

Details: lease typically 24 hours or less; T1 = 50% of lease the client unicasts to renew with its original server; T2 = 87.5% it broadcasts to rediscover servers. If renewal fails, the address is released when the lease expires.

12.2 Configuring a Cisco Router as DHCP Server (complete commands)

Commands

R1(config)# ip dhcp excluded-address 192.168.1.1 192.168.1.10
# reserved addresses (gateway/servers — never handed out)
R1(config)# ip dhcp pool LAN                  # create an address pool
R1(dhcp-config)# network 192.168.1.0 255.255.255.0   # assignable range
R1(dhcp-config)# default-router 192.168.1.1          # gateway
R1(dhcp-config)# dns-server 8.8.8.8                  # DNS
R1(dhcp-config)# lease 7                             # 7-day lease (optional)
R1(dhcp-config)# exit

# DHCP across subnets: relay on the router facing clients
R2(config)# interface g0/0
R2(config-if)# ip helper-address 192.168.1.1   # forward DHCP broadcasts to the server

# Verify
R1# show ip dhcp binding        # assigned addresses
R1# show ip dhcp pool           # pool config
R1# debug ip dhcp server events # troubleshooting
Key: DHCP discovery is a broadcast — it cannot cross routers. Cross-subnet, use ip helper-address (DHCP relay) to turn the broadcast into a unicast to the server. Exams ask "how to do DHCP across subnets."

12.3 NAT (the focus topic)

Private addresses (RFC 1918) are not routable on the public Internet. NAT on the edge device translates private IPs to public IPs. Three benefits: conserves public addresses, hides the internal structure, resolves overlapping address schemes.

The three types (memorize):

TypeMappingFeaturesTypical use
Static NAT1 private ↔ 1 fixed publicOne-to-one, fixed, externally reachablePublic servers
Dynamic NAT1 private ↔ 1 public (from a pool)One-to-one, temporary, no inboundMany internal users egressing
PAT / overloadMany private ↔ 1 public (ports distinguish)Many-to-one, most common, port-basedHome/office sharing one public IP

The four address concepts (exams split hairs — know them):

TermMeaningExample
Inside LocalInternal host as seen inside (private IP)192.168.1.10
Inside GlobalInternal host as seen outside (translated public IP)203.0.113.5
Outside LocalExternal host as seen inside (usually the real IP)198.51.100.7
Outside GlobalExternal host as seen outside (the real IP)198.51.100.7

12.4 Configuring PAT (overload) + Static NAT

Commands

# ---------- PAT: internal network shares one public IP ----------
R1(config)# access-list 1 permit 192.168.1.0 0.0.0.255   # define the internal network
R1(config)# ip nat inside source list 1 interface g0/1 overload
#        [internal ACL]             [exit iface] [overload = port reuse]
R1(config)# interface g0/0
R1(config-if)# ip nat inside     # mark inside
R1(config)# interface g0/1
R1(config-if)# ip nat outside    # mark outside

# ---------- Static NAT: publish a server ----------
R1(config)# ip nat inside source static 192.168.1.50 203.0.113.50
#        [server private IP]  [public IP]
# note: don't forget the ACL permit + inside/outside markings

# Verify
R1# show ip nat translations    # the translation table (Inside Local ↔ Inside Global)
R1# show ip nat statistics      # hit counters
R1# clear ip nat translation *  # flush (troubleshooting)
R1# show ip nat translations
Pro Inside global      Inside local       Outside local    Outside global
tcp 203.0.113.5:1025   192.168.1.10:1025  198.51.100.7:80   198.51.100.7:80
tcp 203.0.113.5:1026   192.168.1.11:1026  198.51.100.7:80   198.51.100.7:80
   ^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^
   public IP+port       private IP+port  ← PAT: same public IP, different ports
Troubleshooting: ① interfaces must be marked inside/outside (missing marks = 90% of problems); ② the ACL matches source addresses only (standard ACL); ③ PAT requires the overload keyword; ④ empty show ip nat translations = no traffic triggered it; ⑤ remember the ip route 0.0.0.0 0.0.0.0 default route outbound.

12.5 DNS Deep Dive

DNS resolves human-friendly names (www.example.com) to IPs. Port UDP 53 (queries), TCP 53 (zone transfers/large responses).

The resolution process (recursive + iterative):

PC asks local DNS: what is www.example.com?
Local DNS checks cache → miss:
   → asks the root server: who is authoritative for .com?
   → asks the .com TLD: who is authoritative for example.com?
   → asks the example.com authoritative: www's A record = 93.184.216.34
Local DNS caches and replies: 93.184.216.34

Record types (memorize): A=IPv4, AAAA=IPv6, CNAME=alias, MX=mail server, NS=name server, PTR=reverse (IP→name), TXT=text (SPF anti-spam).

On Cisco devices: ip name-server 8.8.8.8 + ip domain-lookup (on by default, lets ping resolve names).

12.6 Chapter Self-Test

Q1. The four DHCP steps?
Ans: Discover → Offer → Request → Ack (DORA).

Q2. DHCP ports? Cross-subnet mechanism?
Ans: UDP 67/68; ip helper-address (DHCP relay).

Q3. Which NAT lets many internal hosts share one public IP?
Ans: PAT (overload), port-distinguished.

Q4. Publishing a web server uses which NAT?
Ans: static NAT (fixed one-to-one).

Q5. DNS default query port/protocol? A and AAAA records?
Ans: UDP 53; A=IPv4, AAAA=IPv6.

12DHCP · NAT · DNS

核心 IP 服务的三大件,NAT 是必考计算与配置题。学完本章要能:说清 DHCP 四步、NAT 三种类型与配置、DNS 解析流程。

12.1 DHCP 动态主机配置协议(深入)

DHCP 自动给主机分配 IP 地址、掩码、默认网关、DNS,省去逐台手工配置。端口:UDP 67(服务器)、68(客户端)。

工作过程(DORA 四步,必背):

客户端                                  DHCP服务器
   |---- Discover(广播) ----->|  ① 找服务器: "谁有IP可以给我?" (广播到255.255.255.255)
   |<---- Offer(单播/广播) ----|  ② 服务器提议: "我可以给你 192.168.1.100"
   |---- Request(广播) ----->|  ③ 客户端请求: "我就要这个地址" (广播,让所有服务器知道)
   |<---- Ack(单播/广播) -----|  ④ 服务器确认: "好,租给你, 租期X秒"

细节:租期(Lease)默认通常 24 小时或更短;T1=50%租期 时客户端单播向原服务器续租,T2=87.5% 时广播重新寻找服务器。续租失败租期到了地址释放。

12.2 配置 Cisco 路由器为 DHCP 服务器(完整命令)

命令

R1(config)# ip dhcp excluded-address 192.168.1.1 192.168.1.10
# 保留地址(网关/服务器等静态地址不分配)
R1(config)# ip dhcp pool LAN                  # 建地址池
R1(dhcp-config)# network 192.168.1.0 255.255.255.0   # 可分配网段
R1(dhcp-config)# default-router 192.168.1.1          # 网关
R1(dhcp-config)# dns-server 8.8.8.8                  # DNS
R1(dhcp-config)# lease 7                             # 租期7天(可选)
R1(dhcp-config)# exit

# DHCP 跨网段: 路由器上对客户端接口开中继
R2(config)# interface g0/0
R2(config-if)# ip helper-address 192.168.1.1   # 把DHCP广播转发到服务器

# 验证
R1# show ip dhcp binding        # 看已分配
R1# show ip dhcp pool           # 看池配置
R1# debug ip dhcp server events # 排错
关键:DHCP 发现是广播,不能跨路由器。跨网段用 ip helper-address(DHCP中继)把广播转为单播转发到服务器。考试常考"DHCP跨网段怎么配"。

12.3 NAT 网络地址转换(重点中的重点)

私有地址(RFC 1918)不能在公网路由。NAT 在边界设备上把私有 IP 转换为公网 IP。三个作用:节省公网地址、隐藏内网结构、地址重叠解决。

三类 NAT(必背):

类型映射关系特点典型场景
静态 NAT1 私网IP ↔ 1 固定公网IP一对一、固定、可被外部主动访问对外提供服务的服务器
动态 NAT1 私网IP ↔ 1 公网IP(从池中动态分配)一对一、临时、外网不能主动访问内网大量用户出网
PAT / NAT过载多 私网IP ↔ 1 公网IP(端口区分)多对一、最常用、用端口号区分会话家庭/企业共享一个公网IP上网

四个地址概念(考试抠字眼,必须分清):

术语含义例子
Inside Local内网主机在内网看到的地址(私有IP)192.168.1.10
Inside Global内网主机在外网看到的地址(转换后的公网IP)203.0.113.5
Outside Local外网主机在内网看到的地址(通常=外部真实IP)198.51.100.7
Outside Global外网主机在外网看到的地址(外部真实IP)198.51.100.7

12.4 配置 PAT(过载,最常用)+ 静态 NAT

命令

# ---------- PAT: 内网共享一个公网IP上网 ----------
R1(config)# access-list 1 permit 192.168.1.0 0.0.0.255   # 定义内网网段
R1(config)# ip nat inside source list 1 interface g0/1 overload
#        [内网ACL]             [出接口]      [过载=复用端口]
R1(config)# interface g0/0
R1(config-if)# ip nat inside     # 标记内网口
R1(config)# interface g0/1
R1(config-if)# ip nat outside    # 标记外网口

# ---------- 静态 NAT: 对外发布服务器 ----------
R1(config)# ip nat inside source static 192.168.1.50 203.0.113.50
#        [内网服务器私IP]   [对外公网IP]
# 注意: 别忘了 ACL 允许 + 接口标 inside/outside

# 验证
R1# show ip nat translations    # 查看转换表(Inside Local ↔ Inside Global)
R1# show ip nat statistics      # 命中统计
R1# clear ip nat translation *  # 清空转换表(排错用)
R1# show ip nat translations
Pro Inside global      Inside local       Outside local    Outside global
tcp 203.0.113.5:1025   192.168.1.10:1025  198.51.100.7:80   198.51.100.7:80
tcp 203.0.113.5:1026   192.168.1.11:1026  198.51.100.7:80   198.51.100.7:80
   ^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^
   公网IP+端口          私网IP+端口      ← PAT: 同一公网IP, 不同端口区分
排错要点:① 接口必须标 inside/outside(漏标是90%的问题);② ACL 只匹配源地址(标准ACL);③ PAT 看 overload 关键字;④ show ip nat translations 空 = 没流量触发;⑤ 记得 ip route 0.0.0.0 0.0.0.0 默认路由出网。

12.5 DNS 域名解析(深入)

DNS 把人类易记的域名(www.example.com)解析为 IP。端口 UDP 53(查询)、TCP 53(区域传送/大响应)。

解析过程(递归+迭代):

PC 问本地DNS: www.example.com 是多少?
本地DNS 查缓存 → 没有:
   → 问根服务器: .com 的权威服务器是谁?
   → 问 .com 权威: example.com 的权威服务器是谁?
   → 问 example.com 权威: www 的 A 记录 = 93.184.216.34
本地DNS 缓存并回复 PC: 93.184.216.34

记录类型(必背):A=IPv4 地址、AAAA=IPv6、CNAME=别名(如 www→example.com)、MX=邮件服务器、NS=域名服务器、PTR=反向(IP→域名)、TXT=文本(SPF反垃圾邮件)。

Cisco 设备配 DNS:ip name-server 8.8.8.8 + ip domain-lookup(默认开,用于 ping 域名时解析)。

12.6 本章自测

Q1. DHCP 四步过程是?
答:Discover → Offer → Request → Ack(DORA)。

Q2. DHCP 用哪些端口?跨网段靠什么?
答:UDP 67/68;ip helper-address(DHCP中继)。

Q3. 哪种 NAT 让多台内网主机共享一个公网 IP?
答:PAT(过载 overload),用端口区分。

Q4. 对外发布 Web 服务器用哪种 NAT?
答:静态 NAT(固定一对一映射)。

Q5. DNS 默认查询端口和协议?A/AAAA 记录分别是什么?
答:UDP 53;A=IPv4,AAAA=IPv6。

13WAN · PPP · Wireless

Important WAN connectivity and wireless basics are exam topics. After this chapter: name the common WAN technologies, configure PPP authentication, and explain wireless standards and security.

13.1 WAN Technology Overview (LAN vs WAN)

LAN: you own it, geographically small, fast. The typical technology is Ethernet. WAN: connects remote sites, usually leased from a service provider, geographically large.

WAN technologyTypeBandwidth/featuresUse
Leased linePoint-to-point physical circuitFixed bandwidth, reliable, expensiveBanks/critical business
MPLSProvider label-switched networkFlexible, QoS, enterprise-gradeMulti-site enterprise
IPsec VPNEncrypted tunnel over public InternetLow cost, encrypted, depends on Internet qualityBranches / remote workers
DSLBroadband over phone lineAsymmetric (down fast, up slow)Home / small office
Fiber broadbandFTTH/FTTBSymmetric, high bandwidthEnterprise / home
SD-WANSoftware-defined WANSmart multi-link steering, centralized management (modern trend)Multi-cloud / multi-branch

Cisco serial encapsulation: the two protocols to compare (exam favorite): HDLC (Cisco default, proprietary framing) and PPP (standard, supports authentication and multilink).

13.2 PPP Deep Dive

PPP (Point-to-Point Protocol) is the standard point-to-point link protocol — more powerful than HDLC:

  • Authentication: PAP (plaintext), CHAP (encrypted three-way handshake) — HDLC has none.
  • Multilink (MLPPP): bundles multiple physical links into one logical link (like EtherChannel for serial).
  • Compression: data compression (Predictor/Stacker).
  • Error detection: LCP quality check.
  • Dynamic assignment: IPCP can assign the peer an IP (for dial-up).

PPP protocol stack: LCP (Link Control Protocol) builds the link/negotiates/auths; NCP (Network Control Protocol) negotiates network-layer parameters (e.g., IPCP assigns IPs).

PAP vs CHAP (memorize):

ItemPAPCHAP
Auth methodUsername + password sent in plaintextChallenge-response (password never on the wire)
FrequencyOnce at link setupAt setup + periodically repeated
SecurityWeak (plaintext, sniffable)Strong (MD5 hash, recommended)

13.3 Configuring PPP + CHAP (complete commands)

Commands Configure both ends; usernames/passwords are reciprocal:

# ---- R1 ----
R1(config)# username R2 password cisco    # username = peer's hostname, same password both ends
R1(config)# interface serial0/0/0
R1(config-if)# encapsulation ppp          # PPP encapsulation
R1(config-if)# ppp authentication chap    # enable CHAP
R1(config-if)# no shutdown

# ---- R2 ----
R2(config)# username R1 password cisco    # note: the username is R1
R2(config)# interface serial0/0/0
R2(config-if)# encapsulation ppp
R2(config-if)# ppp authentication chap

# Verify
R1# show interfaces serial0/0/0   # look for LCP: Open / auth state
R1# debug ppp authentication      # troubleshooting (watch the auth exchange)
# Troubleshooting: username is the peer's hostname, passwords identical, enable secret does not affect PPP

13.4 Wireless Fundamentals (deep dive)

Wireless LAN standards are the IEEE 802.11 family. Memorize the speeds and bands:

StandardBandMax rateNotes
802.11b2.4 GHz11 MbpsLegacy, obsolete
802.11g2.4 GHz54 MbpsBackward-compatible with b
802.11n (WiFi 4)2.4/5 GHz~600 MbpsMIMO
802.11ac (WiFi 5)5 GHz~6.9 GbpsMU-MIMO, modern mainstream
802.11ax (WiFi 6)2.4/5/6 GHz~9.6 GbpsOFDMA, latest

Key concepts:

  • AP (Access Point): Layer-2 device, the wireless terminal's "switch." WLC (Wireless LAN Controller) centrally manages thin APs (thin APs download config from the WLC).
  • SSID: the wireless network name clients use to find the network.
  • Channels: 2.4 GHz has 13 overlapping channels; use non-overlapping 1/6/11; 5 GHz has many non-overlapping channels, less interference.
  • CSMA/CA: wireless uses collision avoidance (not detection) — hidden nodes + inability to listen while transmitting (see Chapter 2).
  • Roaming: clients move between APs keeping connectivity (same SSID).

Wireless security (memorize):

MechanismSecurityEncryptionStatus
WEPVery weak (cracked in minutes)RC4 (static keys)Obsolete
WPAWeakTKIP (RC4 + dynamic keys)Transitional, deprecated
WPA2StrongAES (CCMP)Modern standard
WPA3StrongerAES-GCMP, brute-force resistantLatest standard
Exam stance: wireless security means WPA2/WPA3 + AES; WEP is the "must-know obsolete" item. Auth modes: PSK (pre-shared key, home/small business) or 802.1X (enterprise, with a RADIUS server).

13.5 Wireless vs Wired (frequently compared)

DimensionWired EthernetWireless 802.11
Media accessFull-duplex switching (no collisions)Half-duplex shared medium, CSMA/CA
SecurityPhysical access control (plug in to connect)Signals travel through air — must encrypt (WPA2/3)
BandwidthStable, dedicated (switched)Shared, varies with distance/interference
DeploymentCabling costFlexible, mobility

13.6 Chapter Self-Test

Q1. Key difference between PPP and HDLC?
Ans: PPP is a standard supporting auth (CHAP/PAP)/multilink/compression; HDLC is Cisco-proprietary, no auth.

Q2. Why is CHAP safer than PAP?
Ans: CHAP uses challenge-response + MD5 hash, password never leaves the wire; PAP sends it in plaintext.

Q3. Which 802.11 standard is WiFi 6?
Ans: 802.11ax.

Q4. The must-use wireless encryption?
Ans: WPA2/WPA3 + AES.

Q5. What media access mechanism does wireless use, and why?
Ans: CSMA/CA (collision avoidance) — wireless cannot listen while transmitting and has hidden nodes.

13WAN 广域网 · PPP · 无线

重要 广域网连接与无线基础是考点。学完本章要能:说出 WAN 常见技术、配 PPP 认证、说清无线标准与安全。

13.1 广域网技术概览(LAN vs WAN)

LAN(局域网):自己拥有的、地理范围小、速度快。典型技术以太网。WAN(广域网):连接远程站点,通常租用运营商的服务,地理范围大。

WAN技术类型带宽/特点适用
专线 Leased Line点对点物理电路固定带宽,可靠,贵银行/关键业务
MPLS运营商标签交换网络灵活、支持QoS、企业级多站点企业网
IPsec VPN公网加密隧道低成本、加密、受公网质量影响分支机构/远程办公
DSL电话线宽带不对称(下行快上行慢)家庭/小办公室
光纤宽带FTTH/FTTB对称、高带宽企业/家庭
SD-WAN软件定义WAN多链路智能调度、集中管理(现代趋势)多云/多分支

Cisco 路由器串口封装的两种协议(考试常考对比):HDLC(Cisco默认、私有帧格式)和 PPP(标准、支持认证、多链路)。

13.2 PPP 点对点协议(深入)

PPP(Point-to-Point Protocol) 是标准的点对点链路协议,比 HDLC 强大:

  • 认证:PAP(明文)、CHAP(加密三次握手)——HDLC 没有认证。
  • 多链路捆绑(MLPPP):把多条物理链路绑成一条逻辑链路(类似EtherChannel但用于串口)。
  • 压缩:数据压缩(Predictor/Stacker)。
  • 错误检测:LCP 质量检测。
  • 动态分配:配合 IPCP 给对端分配IP(用于拨号)。

PPP 协议栈:LCP(链路控制协议)负责建链/协商/认证;NCP(网络控制协议)负责协商网络层参数(如 IPCP 分IP)。

PAP vs CHAP(必背):

项PAPCHAP
认证方式用户名+密码明文传输挑战-响应(密码不出网)
次数建链时一次建链时 + 周期性重复
安全性弱(明文,可被窃听)强(MD5哈希,推荐)

13.3 配置 PPP + CHAP(完整命令)

命令 两端都要配,用户名密码要互为对端:

# ---- R1 ----
R1(config)# username R2 password cisco    # 用户名=对端主机名, 密码两端一致
R1(config)# interface serial0/0/0
R1(config-if)# encapsulation ppp          # 封装PPP
R1(config-if)# ppp authentication chap    # 启用CHAP认证
R1(config-if)# no shutdown

# ---- R2 ----
R2(config)# username R1 password cisco    # 注意: 用户名是R1
R2(config)# interface serial0/0/0
R2(config-if)# encapsulation ppp
R2(config-if)# ppp authentication chap

# 验证
R1# show interfaces serial0/0/0   # 看 LCP: Open / 认证状态
R1# debug ppp authentication      # 排错(看认证过程)
# 排错要点: 用户名写对端主机名、密码两端完全一致、enable secret不影响PPP

13.4 无线网络基础(深入)

无线局域网(WLAN)标准是 IEEE 802.11 家族。必背速率与频段:

标准频段最大速率说明
802.11b2.4GHz11 Mbps老标准,基本淘汰
802.11g2.4GHz54 Mbps兼容b
802.11n (WiFi 4)2.4/5GHz~600 MbpsMIMO多天线
802.11ac (WiFi 5)5GHz~6.9 GbpsMU-MIMO,现代主流
802.11ax (WiFi 6)2.4/5/6GHz~9.6 GbpsOFDMA,最新

关键概念:

  • AP(接入点):第2层设备,无线终端的"交换机"。WLC(无线控制器)集中管理瘦AP(瘦AP无独立配置,从WLC下载)。
  • SSID:无线网络名,客户端凭 SSID 找到网络。
  • 信道:2.4GHz 有13个信道(重叠),常用不重叠的 1/6/11;5GHz 信道多、干扰少。
  • CSMA/CA:无线用冲突避免(不是检测),因为有隐藏节点且无法边发边听(见第2章)。
  • 漫游:客户端在多个AP间切换保持连接(相同SSID)。

无线安全(必背):

机制安全性加密状态
WEP极弱(可几分钟破解)RC4(静态密钥)废弃
WPA弱TKIP(RC4+动态密钥)过渡,已淘汰
WPA2强AES(CCMP)现代标准
WPA3更强AES-GCMP,防暴力破解最新标准
考试立场:无线安全只用 WPA2/WPA3 + AES;WEP 是必考"淘汰"项。认证模式:PSK(预共享密钥,家庭/小企业) 或 802.1X(企业级,接RADIUS服务器)。

13.5 无线 vs 有线对比(常考)

维度有线以太网无线802.11
介质访问全双工交换(无冲突)半双工共享介质,CSMA/CA
安全性物理接入控制(插线才通)信号空中传播,必须加密(WPA2/3)
带宽稳定、独占(交换)共享、随距离/干扰波动
部署布线成本灵活、移动性

13.6 本章自测

Q1. PPP 和 HDLC 的关键区别?
答:PPP是标准协议、支持认证(CHAP/PAP)/多链路/压缩;HDLC是Cisco私有、无认证。

Q2. CHAP 相比 PAP 安全在哪?
答:CHAP用挑战-响应+MD5哈希,密码不出网;PAP明文传输。

Q3. WiFi 6 对应的802.11标准是?
答:802.11ax。

Q4. 无线安全必用的加密方式?
答:WPA2/WPA3 + AES。

Q5. 无线用什么介质访问机制?为什么?
答:CSMA/CA(冲突避免),因无线无法边发边听且有隐藏节点。

14Access Control Lists (ACL)

Core ACLs are the core of network security and traffic filtering — guaranteed config and judgment questions. After this chapter: explain standard vs extended ACLs, understand implicit deny, place in/out correctly, and configure named ACLs.

14.1 What Is an ACL (position it first)

ACL (Access Control List): an ordered set of rules on a router that makes permit / deny decisions on passing traffic. Uses beyond "firewall":

  • Traffic filtering (allow/deny specific traffic) — the main use
  • NAT match conditions (which internal addresses translate)
  • QoS classification (which traffic is prioritized)
  • Route filtering (e.g., distribute-list limits route advertisements)
  • Remote management restriction (only specific management IPs reach the VTY)

14.2 The Three Iron Rules (memorize)

Match top-down: the packet is compared against each rule in order from the first; the first match decides (permit or deny), and processing stops.
Implicit deny: traffic that matches no rule is denied by default. So an ACL needs at least one permit or it blocks everything.
Direction (in/out) + interface binding: an ACL only takes effect when bound to an interface + direction; in = checked on entry, out = checked on exit.
Most common mistakes: writing an ACL but not binding it, binding the wrong direction, or forgetting the implicit deny and blocking legitimate traffic. Verify with show access-lists and look at each rule's match counter — zero hits means wrong place/direction/order.

14.3 Standard vs Extended ACL (memorize the comparison)

ItemStandard ACLExtended ACL
Number ranges1-99, 1300-1999100-199, 2000-2699
Matches onsource IP onlysource + destination IP + protocol (TCP/UDP/ICMP) + ports
PlacementAs close to the destination as possibleAs close to the source as possible (drop early, save bandwidth)
GranularityCoarse (by source only)Fine (down to protocol/port)
Memory: standard looks at source, place at the destination; extended looks at everything, place at the source. A standard ACL placed too close to the source blocks that source's traffic to everywhere (it matches source only).

14.4 Wildcard Mask — the hidden ACL exam item

ACLs match addresses with wildcard masks (not subnet masks): 0 = must match exactly, 1 = ignore.

Subnet mask: 255.255.255.0   → wildcard: 0.0.0.255
Match a whole /24:  permit 192.168.1.0 0.0.0.255   (first 24 bits exact, last 8 any)
Match a single host: permit 192.168.1.5 0.0.0.0     (all exact)  or  permit host 192.168.1.5
Match anything:       permit any                    (shorthand for 0.0.0.0 255.255.255.255)

Special wildcards (awareness): 0.0.0.254 matches even addresses (last bit must be 0); 0.0.0.252 matches blocks of 4. Exams mainly test network/host/any.

14.5 Configuring Standard + Extended + Named ACLs (complete commands)

Commands

# ---------- Standard ACL (numbered) ----------
R1(config)# access-list 1 permit 192.168.1.0 0.0.0.255   # permit that network
R1(config)# access-list 1 deny 192.168.2.0 0.0.0.255     # deny another
R1(config)# interface g0/0
R1(config-if)# ip access-group 1 in       # bind + direction (in)

# ---------- Extended ACL (numbered) ----------
# permit internal web (80) out; deny external Telnet (23) in
R1(config)# access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80
R1(config)# access-list 100 deny tcp any 192.168.1.0 0.0.0.255 eq 23
R1(config)# access-list 100 permit ip any any   # implicit deny would block the rest — add a catch-all
R1(config)# interface g0/1
R1(config-if)# ip access-group 100 in

# ---------- Named ACL (editable, recommended) ----------
R1(config)# ip access-list extended BLOCK_TELNET
R1(config-ext-nacl)# deny tcp any 192.168.1.0 0.0.0.255 eq 23
R1(config-ext-nacl)# permit ip any any
R1(config-ext-nacl)# exit
R1(config)# interface g0/1
R1(config-if)# ip access-group BLOCK_TELNET in

# ---------- Verify ----------
R1# show access-lists              # rules + match counters
R1# show ip access-lists
R1# show access-lists 100

Reading the output:

R1# show access-lists
Extended IP access list 100
    10 permit tcp 192.168.1.0 0.0.0.255 any eq www (12 matches)
    20 deny tcp any 192.168.1.0 0.0.0.255 eq telnet (3 matches)
    30 permit ip any any (58 matches)
    ^^ sequence #   ^^ match counter — which rule is doing the work

14.6 Classic Scenarios (exam drills)

Scenario 1: allow only 192.168.1.0/24 to the server's web; deny everything else.
Extended ACL near the source (the router in front of the server): permit tcp 192.168.1.0 0.0.0.255 host 10.0.0.5 eq 80 + implicit deny handles the rest.

Scenario 2: block the finance VLAN (VLAN 10) from reaching the management network (10.0.0.0/24); allow everything else.
deny ip 192.168.10.0 0.0.0.255 10.0.0.0 0.0.0.255 + permit ip any any.

Scenario 3: allow only the admin IP (1.1.1.1) to SSH-manage the router.
Bind on the VTY lines: access-class 5 in (standard ACL 5 permits 1.1.1.1) — remote management restriction uses access-class, not access-group.

High-frequency traps: ① eq only applies to TCP/UDP (ICMP has no ports); ② extended ACL syntax order: protocol → source → destination → port; ③ VTY binding uses access-class; ④ edit with named ACLs (insert sequence numbers); numbered ACLs must be deleted and rebuilt wholesale.

14.7 Chapter Self-Test

Q1. What does a standard ACL match, and where is it placed?
Ans: source IP only; close to the destination.

Q2. The implicit rule at the end of an ACL?
Ans: implicit deny — unmatched traffic is denied.

Q3. Wildcard 0.0.0.255 matches what?
Ans: first 24 bits exact, last 8 any — a whole /24.

Q4. Extended ACL number range?
Ans: 100-199 (and 2000-2699).

Q5. Which command restricts VTY remote management?
Ans: access-class under line vty.

14访问控制列表 ACL

核心 ACL 是网络安全与流量过滤的核心,必考配置与判断。学完本章要能:说清标准vs扩展ACL、理解隐式deny、正确放in/out方向、配命名ACL并排错。

14.1 什么是 ACL(先理解定位)

ACL(Access Control List,访问控制列表):路由器上的一组有序规则,对经过的流量做允许(permit)/拒绝(deny)判断。用途不止"防火墙":

  • 流量过滤(允许/拒绝特定流量)——最主要用途
  • NAT 的匹配条件(定义哪些内网地址做转换)
  • QoS 分类(标记哪些流量优先)
  • 路由过滤(如 distribute-list 限制路由通告)
  • 远程管理限制(只允许特定管理IP访问VTY)

14.2 三大铁律(ACL 的判读规则,必背)

从上到下顺序匹配:数据包按规则第一条开始逐条比较,命中即停止(permit 或 deny 就定论了)。
隐含拒绝(Implicit Deny):所有规则都没匹配的流量,默认被拒绝(丢弃)。所以 ACL 至少要有一条 permit,否则全拒。
方向(in/out)和接口绑定:ACL 必须绑定到接口 + 方向才生效;in=进入接口时检查,out=从接口发出时检查。
最容易犯的错:ACL 写好了没绑接口、或绑错方向、或忘了隐式deny把该放的流量也拒了。验证用 show access-lists 看每条规则的匹配计数——没命中说明放错位置/方向/顺序。

14.3 标准 ACL vs 扩展 ACL(必背对比)

项标准 ACL扩展 ACL
编号范围1–99, 1300–1999100–199, 2000–2699
匹配依据仅源IP源IP + 目的IP + 协议(TCP/UDP/ICMP) + 端口
放置位置尽量靠近目的端(别误伤中间流量)尽量靠近源端(早拒绝省带宽)
粒度粗(只能按来源分)细(能精确到协议/端口)
记忆:标准看源、放目的;扩展看全、放源。标准ACL放太靠源会挡住所有来自该源去任何地方的流量(因为只匹配源)。

14.4 反掩码(Wildcard Mask)——ACL 的隐藏考点

ACL 匹配地址用反掩码(通配符),不是子网掩码:0 = 必须精确匹配的位,1 = 忽略的位。

子网掩码: 255.255.255.0   → 反掩码: 0.0.0.255
匹配整个网段: permit 192.168.1.0 0.0.0.255    (前24位精确, 后8位任意)
匹配单个主机: permit 192.168.1.5 0.0.0.0      (全精确)  或  permit host 192.168.1.5
匹配任意地址: permit any                      (0.0.0.0 255.255.255.255 简写)

奇偶匹配等特殊反掩码:0.0.0.254 匹配偶数地址(最后一位必须是0)、0.0.0.252 匹配4的倍数块——了解即可,考试以网段/单主机为主。

14.5 配置标准 + 扩展 + 命名 ACL(完整命令)

命令

# ---------- 标准 ACL (编号) ----------
R1(config)# access-list 1 permit 192.168.1.0 0.0.0.255   # 允许该网段
R1(config)# access-list 1 deny 192.168.2.0 0.0.0.255     # 拒绝另一网段
R1(config)# interface g0/0
R1(config-if)# ip access-group 1 in       # 绑接口+方向(入方向)

# ---------- 扩展 ACL (编号) ----------
# 允许内网访问外网Web(80), 拒绝外网Telnet(23)进内网
R1(config)# access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80
R1(config)# access-list 100 deny tcp any 192.168.1.0 0.0.0.255 eq 23
R1(config)# access-list 100 permit ip any any   # 注意: 隐式deny会拒掉其余, 需要这条兜底
R1(config)# interface g0/1
R1(config-if)# ip access-group 100 in

# ---------- 命名 ACL (可编辑, 推荐) ----------
R1(config)# ip access-list extended BLOCK_TELNET
R1(config-ext-nacl)# deny tcp any 192.168.1.0 0.0.0.255 eq 23
R1(config-ext-nacl)# permit ip any any
R1(config-ext-nacl)# exit
R1(config)# interface g0/1
R1(config-if)# ip access-group BLOCK_TELNET in

# ---------- 验证 ----------
R1# show access-lists              # 看规则+命中计数
R1# show ip access-lists
R1# show access-lists 100
R1# debug ip packet (排除时用,慎用)

验证输出解读:

R1# show access-lists
Extended IP access list 100
    10 permit tcp 192.168.1.0 0.0.0.255 any eq www (12 matches)
    20 deny tcp any 192.168.1.0 0.0.0.255 eq telnet (3 matches)
    30 permit ip any any (58 matches)
    ^^  顺序号   ^^匹配计数——看哪条在干活

14.6 经典场景题(考试必练)

场景1:只允许 192.168.1.0/24 访问服务器的 Web,其他都拒绝。
扩展ACL放源端(服务器前那台路由器):permit tcp 192.168.1.0 0.0.0.255 host 10.0.0.5 eq 80 + 隐式deny兜底。

场景2:禁止财务VLAN(VLAN 10)访问管理网段(10.0.0.0/24),其余放行。
deny ip 192.168.10.0 0.0.0.255 10.0.0.0 0.0.0.255 + permit ip any any。

场景3:只允许管理员IP(1.1.1.1)SSH 管理路由器。
VTY 行绑定:access-class 5 in(标准ACL 5 permit 1.1.1.1)——注意远程管理限制用 access-class,不是 access-group。

高频陷阱:① eq 只对 TCP/UDP 有效(ICMP 没有端口);② 扩展ACL语句顺序:协议→源→目的→端口;③ 绑VTY用 access-class;④ 改ACL用命名ACL(可插入顺序号),编号ACL只能整体删重建。

14.7 本章自测

Q1. 标准ACL匹配什么?通常放哪里?
答:只匹配源IP;放靠近目的端。

Q2. ACL 末尾的隐式规则是什么?
答:隐式拒绝(implicit deny)——没匹配的全拒绝。

Q3. 反掩码 0.0.0.255 匹配什么?
答:前24位精确、后8位任意——整个/24网段。

Q4. 扩展ACL的编号范围?
答:100–199(及2000–2699)。

Q5. 限制VTY远程管理用什么命令?
答:line vty 下配 access-class。

15Port Security & Basic Defense

Important Switch port security is the security-chapter focus of CCNA. After this chapter: configure port security, name the three violation modes, and understand Layer-2 security technologies like DHCP Snooping/DAI.

15.1 Port Security Deep Dive

Port security: limit the number of MAC addresses a port may learn, and which MACs are allowed, preventing unauthorized devices. Three typical scenarios:

  • Prevent rogue devices: allow only 1 MAC (the workstation PC); plugging in an AP/switch trips the violation.
  • Prevent MAC flooding attacks: attackers send thousands of fake MACs to fill the MAC table, making the switch "forget" real MACs → flood → sniff. Limiting the MAC count mitigates this.
  • Pin fixed devices: only the specified MAC (server/printer) may connect.

The three violation modes — memorize:

ModeBehaviorSecurity
Shutdown (default)Port goes err-disable (off); manual no shutdown to recoverStrictest
RestrictDrops violating frames + logs/counts; port keeps workingMedium
ProtectDrops violating frames only (no log, no count); port continuesWeak (silent)

15.2 Configuring Port Security (complete commands + verification)

Commands

SW1(config)# interface f0/1
SW1(config-if)# switchport mode access          # port security works on access ports
SW1(config-if)# switchport port-security        # enable port security
SW1(config-if)# switchport port-security maximum 2     # max 2 MACs (default 1)
SW1(config-if)# switchport port-security violation shutdown   # violation = shutdown (default)
SW1(config-if)# switchport port-security mac-address 0011.2233.4455   # fixed allowed MAC
SW1(config-if)# switchport port-security mac-address sticky          # stick learned MACs to config
SW1(config-if)# end

# Verify
SW1# show port-security
SW1# show port-security interface f0/1
SW1# show port-security address

# Recover a shutdown port
SW1(config)# interface f0/1
SW1(config-if)# shutdown
SW1(config-if)# no shutdown     # must close-open once to recover

Reading the output:

SW1# show port-security interface f0/1
Port Security              : Enabled
Violation Mode             : Shutdown          ← current violation mode
Maximum MAC Addresses      : 2                 ← limit
Total MAC Addresses        : 1
Security Violation Count   : 0                 ← violations so far
Sticky MAC Addresses       : 0
Points: ① port security only works on access ports (trunk limited); ② default max=1, violation=shutdown; ③ recovering shutdown requires shutdown + no shutdown; ④ sticky writes learned MACs into running-config (lost on reboot unless saved).

15.3 The Layer-2 Security Toolkit (concepts exams test)

TechnologyBlocksHow
DHCP SnoopingRogue DHCP serversTrusted/untrusted ports; untrusted ports drop DHCP Offer/Ack (only trusted ports may send DHCP responses)
DAI (Dynamic ARP Inspection)ARP spoofing / MITMValidates ARP packets against the DHCP Snooping binding table (IP-MAC must match)
IP Source GuardIP spoofingA port may only use source IPs from the binding table (based on DHCP Snooping)
PortFast + BPDU GuardRogue switches altering STPAccess port that receives a BPDU → err-disable
Disable DTPVLAN hoppingswitchport nonegotiate
VLAN minimizationVLAN hoppingTrunks carry only needed VLANs; native VLAN moved to an unused VLAN
VLAN ACL (VACL)Intra-VLAN traffic filteringApply ACLs to traffic within a VLAN
Storm ControlBroadcast/multicast stormsDrops broadcast frames over a threshold
Attack-chain view: attacker plugs in → MAC flooding (blocked by port security) → rogue DHCP (blocked by DHCP Snooping) → ARP spoofing (blocked by DAI) → IP spoofing (blocked by IP Source Guard) → rogue switch altering STP (blocked by BPDU Guard). Block every layer — that is defense in depth.

15.4 Device Management Security (basic but tested)

ItemRecommendedBannedNotes
Remote mgmtSSH (22, encrypted)Telnet (23, plaintext)SSH needs a domain + key: ip domain-name + crypto key generate rsa
Privileged passwordenable secretenable passwordsecret stores a hash (MD5); password is plaintext
Password encryptionservice password-encryption—Encrypts plaintext passwords in config (weak, better than nothing)
AAARADIUS (UDP 1812/1813) or TACACS+ (TCP 49)Local password only (small scale)TACACS+ encrypts the whole packet; RADIUS only the password
Login bannerbanner motd—Legal warning: unauthorized access prohibited
Idle timeoutexec-timeout 5—Auto-logout VTY/console after 5 min idle
# Full SSH configuration example
R1(config)# hostname R1
R1(config)# ip domain-name example.com      # SSH needs a domain
R1(config)# crypto key generate rsa          # generate RSA keys (768-2048 bits)
R1(config)# username admin secret cisco123   # local user
R1(config)# line vty 0 4
R1(config-line)# transport input ssh         # SSH only
R1(config-line)# login local                # local auth
R1(config-line)# exit

15.5 Chapter Self-Test

Q1. Port security default max MACs and violation mode?
Ans: maximum 1; violation shutdown.

Q2. How to recover a shutdown port?
Ans: shutdown + no shutdown under the interface.

Q3. Which technology blocks rogue DHCP servers?
Ans: DHCP Snooping (untrusted ports drop DHCP Offer).

Q4. What does DAI block?
Ans: ARP spoofing (validates IP-MAC bindings).

Q5. What does remote management recommend? What must be generated first for SSH?
Ans: SSH; crypto key generate rsa.

15端口安全与基础防护

重要 交换机端口安全是 CCNA 安全章节重点。学完本章要能:配端口安全、说清三种违规模式、理解DHCP Snooping/DAI等第2层安全技术。

15.1 端口安全(Port Security)深入

端口安全:限制交换机端口上允许学习的 MAC 地址数量 和 允许的MAC,防止非法设备接入。三个典型防护场景:

  • 防私接设备:只允许1个MAC(工位PC),接个AP/交换机立刻触发违规。
  • 防 MAC 洪泛攻击:攻击者发大量假MAC填满MAC表,让交换机"忘记"真MAC→泛洪→抓包。限制MAC数量可缓解。
  • 固定设备绑定:只允许指定MAC(服务器/打印机)接入。

三种违规行为(violation mode)——必背:

模式行为安全性
Shutdown(默认)端口进入 err-disable(关闭),需手动 no shutdown 恢复最严
Restrict丢弃违规帧 + 记录日志/计数,端口继续工作中
Protect只丢弃违规帧(不记录、不计数),端口继续弱(静默)

15.2 配置端口安全(完整命令 + 验证)

命令

SW1(config)# interface f0/1
SW1(config-if)# switchport mode access          # 端口安全仅access口有效
SW1(config-if)# switchport port-security        # 启用端口安全
SW1(config-if)# switchport port-security maximum 2     # 最多2个MAC(默认1)
SW1(config-if)# switchport port-security violation shutdown   # 违规=关端口(默认)
SW1(config-if)# switchport port-security mac-address 0011.2233.4455   # 固定允许的MAC
SW1(config-if)# switchport port-security mac-address sticky          # 动态学到后固化
SW1(config-if)# end

# 验证
SW1# show port-security
SW1# show port-security interface f0/1
SW1# show port-security address

# 恢复被shutdown的端口
SW1(config)# interface f0/1
SW1(config-if)# shutdown
SW1(config-if)# no shutdown     # 必须关-开一次才能恢复

验证输出解读:

SW1# show port-security interface f0/1
Port Security              : Enabled
Violation Mode             : Shutdown          ← 当前违规模式
Maximum MAC Addresses      : 2                 ← 上限
Total MAC Addresses        : 1
Security Violation Count   : 0                 ← 违规次数
Sticky MAC Addresses       : 0
要点:① 端口安全只在 access 口生效(trunk口不支持或受限);② 默认 max=1、violation=shutdown;③ 恢复 shutdown 必须 shutdown + no shutdown;④ sticky 自动把学到的MAC写进 running-config(固化,重启丢除非保存)。

15.3 第2层安全技术全家桶(考试常考概念)

技术防什么原理
DHCP Snooping假冒DHCP服务器端口分信任/不信任;不信任口丢弃DHCP Offer/Ack(只有信任口能发DHCP响应)
DAI(Dynamic ARP Inspection)ARP欺骗/中间人用DHCP Snooping绑定表校验ARP报文(IP-MAC必须匹配)
IP Source GuardIP欺骗端口只能使用绑定表中的源IP(基于DHCP Snooping)
PortFast + BPDU Guard私接交换机改STP拓扑接入口收到BPDU→err-disable
禁用DTPVLAN跳转攻击switchport nonegotiate
VLAN 最小化VLAN 跳转trunk只允许必要VLAN;native VLAN改为未用VLAN
VLAN ACL (VACL)VLAN内流量过滤对VLAN内流量应用ACL
Storm Control广播/组播风暴超阈值丢弃广播帧
攻击链理解:攻击者接上交换机→MAC洪泛(→端口安全防)→假冒DHCP(→DHCP Snooping防)→ARP欺骗(→DAI防)→IP欺骗(→IP Source Guard防)→私接交换机改STP(→BPDU Guard防)。每层都堵死,才叫纵深防御。

15.4 设备管理安全(基础但必考)

项推荐禁用说明
远程管理SSH(22,加密)Telnet(23,明文)SSH需配域名+密钥:ip domain-name + crypto key generate rsa
特权密码enable secretenable passwordsecret存哈希(MD5),password明文
口令加密service password-encryption—配置里明文密码加密(弱加密,聊胜于无)
AAARADIUS(UDP 1812/1813)或 TACACS+(TCP 49)本地密码库(小规模)TACACS+加密整个报文,RADIUS只加密密码
登录横幅banner motd—法律警告:未经授权禁止访问
闲置超时exec-timeout 5—VTY/console 5分钟无操作自动登出
# SSH 配置完整示例
R1(config)# hostname R1
R1(config)# ip domain-name example.com      # SSH需要域名
R1(config)# crypto key generate rsa          # 生成RSA密钥(768-2048位)
R1(config)# username admin secret cisco123   # 本地用户
R1(config)# line vty 0 4
R1(config-line)# transport input ssh         # 只允许SSH
R1(config-line)# login local                # 本地认证
R1(config-line)# exit

15.5 本章自测

Q1. 端口安全的默认最大MAC数和违规模式?
答:maximum 1;violation shutdown。

Q2. 端口被shutdown后怎么恢复?
答:接口下 shutdown + no shutdown。

Q3. 哪个技术防假冒DHCP服务器?
答:DHCP Snooping(不信任端口丢弃DHCP Offer)。

Q4. DAI 防什么攻击?
答:ARP欺骗(校验IP-MAC绑定)。

Q5. 远程管理推荐用什么?SSH需要先生成什么?
答:SSH;crypto key generate rsa 生成RSA密钥。

16Network Automation & Programmability

Important This is a major new direction in CCNA 200-301 with a notable weight — a concept must-know. After this chapter: explain SDN's three planes, compare SNMP/NETCONF/RESTCONF, read JSON, and name the automation tools.

16.1 Why Automation (understand the trend first)

Traditional networking means logging into every device and typing CLI: slow, error-prone, inconsistent, no rollback. Network automation turns configuration into code: repeatable, version-controlled (Git), testable (CI/CD), deployable in bulk — the core of "Network as Code" and SDN.

Real benefits: provisioning 100 new branch routers in minutes with a script vs hours by hand; automatic validation and rollback on errors; a unified, auditable config baseline network-wide.

16.2 SDN & the Three Planes (must-know concept)

SDN (Software-Defined Networking): separate the network's control plane from the data plane, with a centralized controller pushing policy in software.

PlaneResponsibilityAnalogy
Control PlaneDecides "how traffic goes": routing computation, routing/forwarding table construction, protocol processingBrain (decides)
Data PlaneActually "forwards traffic": table lookup, frame/packet processingHands (executes)
Management PlaneOperations: SSH/SNMP/NETCONF config & monitoringAdministration (manages the device)

Traditional router: control and data planes both live in the device, each computing its own routes. SDN: the controller computes centrally, and the switch just executes (simplified to a forwarding device).

Memory: control plane = brain (computes paths), data plane = hands (forwards packets), management plane = administration (manages config). SDN takes the brain out of each device and centralizes it.

16.3 SDN Interfaces (API directions)

InterfaceDirectionPurposeProtocols
SouthboundController ↓ devicesController pushes forwarding rules/config to devicesOpenFlow, NETCONF, RESTCONF, gRPC
NorthboundApps/upper layers ↑ controllerApps express network requirements to the controllerREST API (common)
East-WestController ↔ controllerMulti-controller sync (large scale)—

OpenFlow is the classic southbound protocol: the controller directly manipulates the switch's flow table (match-action). Modern controllers (Cisco DNA Center) primarily manage devices via NETCONF/RESTCONF.

16.4 Network Management Protocols: SNMP vs NETCONF vs RESTCONF (memorize)

ProtocolTypeData formatPortFeatures
SNMPTraditional, polledMIB (ASN.1)UDP 161/162Read-only monitoring mostly; v3 adds encryption; manager polls + device Traps
NETCONFModern, full-duplexXMLSSH(830)/TLSConfig/state separation; YANG models; transactions/rollback
RESTCONFModern, RESTfulJSON/XMLHTTPS(443)REST version of NETCONF; HTTP verbs; simple
gRPCModernBinary (Protobuf)—High performance, Google family (gNMI/gNOI)

YANG (Yet Another Next Generation): a data modeling language — tree-structured descriptions of device config/state data (e.g., "what attributes does an interface have"). NETCONF/RESTCONF operate on YANG-defined data. Exams ask "what is YANG" — a data model / modeling language, not a protocol.

Memory: SNMP is the "grandfather" (read-only monitoring, MIB); NETCONF is the "regular army" (XML+YANG+transactions); RESTCONF is the "light cavalry" (HTTP+JSON). SNMP v1/v2c uses plaintext community strings; v3 is encrypted/auth'd.

16.5 REST API & JSON (must-know basics)

REST API: operate on resources (identified by URLs) with HTTP methods:

HTTP methodActionDB analogy
GETRead a resourceSELECT
POSTCreate a resourceINSERT
PUTFull update/replaceUPDATE
PATCHPartial updateUPDATE (local)
DELETEDelete a resourceDELETE

JSON (JavaScript Object Notation): key-value text format, the most common network-API format. Key points: { } objects, [ ] arrays, "key":"value"; value types: string/number/boolean/array/object/null.

# JSON example: one interface's state
{
  "interface": "GigabitEthernet0/1",
  "enabled": true,
  "mtu": 1500,
  "ipv4": {
    "address": "192.168.1.1",
    "mask": "255.255.255.0"
  },
  "vlans": [10, 20, 30]          ← array
}

# curl to RESTCONF for interface config
curl -u user:pass https://device/restconf/data/interfaces \
     -H "Accept: application/yang-data+json"

# Python with the requests library
import requests, json
r = requests.get("https://device/restconf/data/interfaces",
                 auth=("user","pass"), verify=False)
print(json.dumps(r.json(), indent=2))

16.6 Automation Tools & Config Management (awareness)

ToolPositioningNotes
Python + Netmiko / NAPALM / requestsScriptingDirect SSH to devices for bulk exec/collection; most flexible
AnsibleAgentless config mgmtPlaybooks (YAML), declarative push over SSH; the enterprise workhorse
GitVersion controlConfigs/scripts in Git: rollback, audit, collaboration
CI/CD (Jenkins etc.)Continuous integration/deploymentAutomated testing + release of config changes
Terraform / Ansible + YANGInfrastructure as codeBulk management via NETCONF
# Ansible playbook example (YAML) — bulk VLAN config
---
- name: Configure VLANs
  hosts: switches
  gather_facts: no
  tasks:
    - name: Create VLAN 10
      cisco.ios.ios_vlan:
        vlan_id: 10
        name: SALES
        state: present

16.7 Chapter Self-Test

Q1. Which two planes does SDN separate?
Ans: control (brain) and data (forwarding).

Q2. What do the southbound and northbound interfaces connect?
Ans: southbound = controller to devices; northbound = apps to controller.

Q3. NETCONF data format and modeling language?
Ans: XML transport; YANG modeling.

Q4. What do GET/POST/DELETE do in REST?
Ans: GET reads, POST creates, DELETE deletes.

Q5. In JSON, what do [ ] represent?
Ans: an array (a set of values).

16网络自动化与可编程性

重要 这是 CCNA 200-301 新增的重点方向,占比可观。必考概念。学完本章要能:说清 SDN 三大平面、对比 SNMP/NETCONF/RESTCONF、读懂 JSON、说出自动化工具。

16.1 为什么自动化(先理解趋势)

传统网络靠工程师一台台登录设备敲 CLI:效率低、易出错、难一致、无法回滚。网络自动化把配置变成代码:可重复、可版本控制(Git)、可测试(CI/CD)、可批量下发——这是"网络即代码"(Network as Code)和 SDN 的核心思想。

实际收益:新开100个分公司分支,脚本批量5分钟完成 vs 人工几小时;配置错误自动检测回滚;全网配置基线统一可审计。

16.2 SDN 与三个平面(必考概念)

SDN(Software-Defined Networking,软件定义网络)的核心思想:把网络的控制平面和数据平面分离,由集中式控制器用软件统一下发策略。

平面职责比喻
控制平面 Control Plane决定"流量怎么走":路由计算、路由表/转发表构建、协议处理大脑(做决策)
数据平面 Data Plane实际"转发流量":查表转发、帧/包处理双手(执行)
管理平面 Management Plane运维管理:SSH/SNMP/NETCONF 配置与监控行政(管设备)

传统路由器:控制平面和数据平面都在设备里,每台自己算路由。SDN:控制器集中计算,交换机只负责执行(简化成转发设备)。

记忆:控制平面=大脑(算路径),数据平面=双手(转发包),管理平面=行政(管配置)。SDN 把大脑从设备里拿出来集中放。

16.3 SDN 的接口(API 方向)

接口方向作用协议
南向接口 Southbound控制器 ↓ 设备控制器向设备下发转发规则/配置OpenFlow, NETCONF, RESTCONF, gRPC
北向接口 Northbound应用/上层 ↑ 控制器应用向控制器表达网络需求REST API(常见)
东西向接口控制器 ↔ 控制器多控制器同步(大规模)—

OpenFlow 是经典的南向协议:控制器直接操作交换机的流表(match-action)。现代控制器(Cisco DNA Center)主要用 NETCONF/RESTCONF 管理设备。

16.4 网络管理协议:SNMP vs NETCONF vs RESTCONF(必背)

协议类型数据格式端口特点
SNMP传统、被拉取MIB(ASN.1)UDP 161/162只读监控为主;v3才加密;管理站轮询+设备Trap
NETCONF现代、全双工XMLSSH(830)/TLS配置与状态分离;用 YANG 数据模型;支持事务/回滚
RESTCONF现代、REST风格JSON/XMLHTTPS(443)NETCONF 的 REST 版,用 HTTP 方法,简单
gRPC现代二进制(Protobuf)—高性能,Google系(gNMI/gNOI)

YANG(Yet Another Next Generation):数据建模语言——用树形结构描述设备的配置/状态数据(如"接口有哪些属性")。NETCONF/RESTCONF 操作的就是 YANG 模型定义的数据。考试爱问"YANG 是什么"——数据模型/建模语言,不是协议。

对比记忆:SNMP 是"老爷爷"(只读监控、MIB);NETCONF 是"正规军"(XML+YANG+事务);RESTCONF 是"轻骑兵"(HTTP+JSON)。SNMP v1/v2c 明文 community,v3 才加密认证。

16.5 REST API 与 JSON(必考基础)

REST API:用 HTTP 方法操作资源(URL 标识的资源):

HTTP方法动作对应数据库操作
GET读取资源SELECT(查)
POST创建资源INSERT(增)
PUT整体更新/替换UPDATE(改)
PATCH部分更新UPDATE(局部改)
DELETE删除资源DELETE(删)

JSON(JavaScript Object Notation):键值对文本格式,网络API最常用。要点:{ } 对象,[ ] 数组,"键":"值",值类型:字符串/数字/布尔/数组/对象/null。

# JSON 示例: 一个接口的状态
{
  "interface": "GigabitEthernet0/1",
  "enabled": true,
  "mtu": 1500,
  "ipv4": {
    "address": "192.168.1.1",
    "mask": "255.255.255.0"
  },
  "vlans": [10, 20, 30]          ← 数组
}

# 用 curl 调 RESTCONF 读接口配置
curl -u user:pass https://device/restconf/data/interfaces \
     -H "Accept: application/yang-data+json"

# 用 Python 调 REST API (requests 库)
import requests, json
r = requests.get("https://device/restconf/data/interfaces",
                 auth=("user","pass"), verify=False)
print(json.dumps(r.json(), indent=2))

16.6 自动化工具与配置管理(了解)

工具定位说明
Python + Netmiko / NAPALM / requests脚本化直接SSH连设备批量执行/采集,最灵活
Ansible无代理配置管理playbook(YAML)声明式下发,SSH即可,企业最常用
Git版本控制配置/脚本进Git,可回滚、可审计、可协作
CI/CD(Jenkins等)持续集成/部署配置变更自动测试+发布
Terraform / Ansible + YANG基础设施即代码配合NETCONF批量管理
# Ansible playbook 示例 (YAML) - 批量配置VLAN
---
- name: Configure VLANs
  hosts: switches
  gather_facts: no
  tasks:
    - name: Create VLAN 10
      cisco.ios.ios_vlan:
        vlan_id: 10
        name: SALES
        state: present

16.7 本章自测

Q1. SDN 把哪两个平面分离?
答:控制平面(大脑)和数据平面(转发)。

Q2. 南向接口和北向接口分别连接什么?
答:南向=控制器到设备;北向=应用到控制器。

Q3. NETCONF 用什么数据格式和建模语言?
答:XML 传输;YANG 建模。

Q4. REST API 中 GET/POST/DELETE 分别做什么?
答:GET读、POST建、DELETE删。

Q5. JSON 里 [ ] 表示什么?
答:数组(一组值)。

17CLI Command Quick Reference

Core The CCNA must-know Cisco IOS commands, organized by use case, for a final pre-exam pass. Memorize by practicing, not by staring.

17.1 Mode Navigation (CLI basics)

enable                          # user → privileged mode
disable                         # privileged → user
configure terminal              # privileged → global config
interface g0/0                  # global → interface config
interface range f0/1-10         # batch interfaces
line console 0 / line vty 0 4   # line config
router ospf 1 / router rip      # routing protocol config
exit                            # back one level
end / Ctrl-Z                    # straight back to privileged
?                               # context help
Tab                             # command completion
show running-config             # running config
show startup-config             # startup config
copy running-config startup-config   # save (=write)
reload                          # reboot
erase startup-config            # wipe startup config (factory reset)

17.2 Interface & IP Configuration

interface g0/0
  ip address 192.168.1.1 255.255.255.0   # IP + mask
  description LINK-TO-CORE              # documentation
  no shutdown                           # enable
  shutdown                              # disable
  speed 100 / duplex full               # manual speed/duplex
show ip interface brief     # interface IP + status (core troubleshooting)
show interfaces             # detail (traffic/errors/duplex)
show ip interface           # IP details

17.3 Switching (VLAN/Trunk/STP/EtherChannel)

vlan 10
  name SALES                          # create VLAN + name
interface f0/1
  switchport mode access
  switchport access vlan 10           # assign port to VLAN
interface g0/1
  switchport mode trunk
  switchport trunk allowed vlan 10,20,30   # trunk: only these VLANs
  switchport trunk native vlan 99          # change native
  switchport nonegotiate                   # disable DTP
spanning-tree mode rapid-pvst              # rapid spanning tree
interface f0/1
  spanning-tree portfast                   # access port fast forward
  spanning-tree bpduguard enable           # BPDU protection
interface range g0/1-2
  channel-group 1 mode active              # EtherChannel (LACP)
interface port-channel 1
  switchport mode trunk                    # channel type
show vlan brief
show interfaces trunk
show spanning-tree
show etherchannel summary

17.4 Routing (static/default/OSPF)

ip route 192.168.2.0 255.255.255.0 192.168.1.2     # static (next hop)
ip route 192.168.2.0 255.255.255.0 serial0/0/0       # static (exit interface)
ip route 0.0.0.0 0.0.0.0 192.168.1.254               # default route
router ospf 1
  router-id 1.1.1.1
  network 192.168.1.0 0.0.0.255 area 0               # advertise (wildcard!)
show ip route
show ip route ospf / static
show ip ospf neighbor

17.5 IP Services (DHCP/NAT/ACL)

# DHCP server
ip dhcp excluded-address 192.168.1.1 192.168.1.10
ip dhcp pool LAN
  network 192.168.1.0 255.255.255.0
  default-router 192.168.1.1
  dns-server 8.8.8.8
# DHCP relay
interface g0/0
  ip helper-address 192.168.2.5

# NAT/PAT
access-list 1 permit 192.168.1.0 0.0.0.255
ip nat inside source list 1 interface g0/1 overload
ip nat inside source static 192.168.1.50 203.0.113.50   # static NAT
interface g0/0 → ip nat inside
interface g0/1 → ip nat outside

# ACL
access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80
ip access-list extended BLOCK
  deny tcp any any eq 23
  permit ip any any
interface g0/1
  ip access-group 100 in
show ip dhcp binding
show ip nat translations
show access-lists

17.6 Security (port security/SSH/passwords)

# Basic passwords
enable secret cisco123
service password-encryption
banner motd #UNAUTHORIZED ACCESS PROHIBITED#
line console 0 / line vty 0 4
  password cisco
  login
  exec-timeout 5 0            # 5-min timeout

# SSH
hostname R1
ip domain-name example.com
crypto key generate rsa
username admin secret cisco123
line vty 0 4
  transport input ssh
  login local

# Port security
interface f0/1
  switchport mode access
  switchport port-security
  switchport port-security maximum 2
  switchport port-security violation shutdown
  switchport port-security mac-address sticky
show port-security address
show port-security interface f0/1

17.7 Troubleshooting & Verification (a lab's lifeline)

ping 192.168.1.1            # connectivity
ping 192.168.1.1 source 192.168.2.1   # specify source IP (multi-path scenarios)
traceroute 8.8.8.8          # hop-by-hop path
show cdp neighbors          # directly connected neighbors (Cisco proprietary)
show lldp neighbors         # standard neighbor discovery
show arp                    # ARP table (IP-MAC)
show mac address-table      # switch MAC table
show ip interface brief     # interface status overview
show interfaces             # interface errors/duplex/CRC
show ip route               # routing table
show running-config | include ip route   # filtered view
debug ip packet             # packet-level debug (careful; never in production)
show logging                # logs
clear counters              # clear interface counters (watch increments)
terminal monitor            # see debug output over remote sessions
How to memorize: don't memorize commands by staring — type every chapter's config once in Packet Tracer / GNS3. Finger memory is 10× stronger than eye memory. Before the exam, run this table three times, thinking "when would I use this?" for each command.

17CLI 命令速查表

核心 汇总 CCNA 必背 Cisco IOS 命令,考前最后一遍过。按使用场景分类,配合实验记忆。

17.1 模式导航(CLI 的基础)

enable                          # 用户模式→特权模式
disable                         # 特权→用户
configure terminal              # 特权→全局配置模式
interface g0/0                  # 全局→接口配置
interface range f0/1-10         # 批量接口
line console 0 / line vty 0 4   # 线路配置
router ospf 1 / router rip      # 路由协议配置
exit                            # 退回上一层
end / Ctrl-Z                    # 直接回特权模式
?                               # 上下文帮助
Tab                             # 命令补全
show running-config             # 查看运行配置
show startup-config             # 查看启动配置
copy running-config startup-config   # 保存(=write)
reload                          # 重启
erase startup-config            # 清除启动配置(恢复出厂)

17.2 接口与 IP 配置

interface g0/0
  ip address 192.168.1.1 255.255.255.0   # 配IP+掩码
  description LINK-TO-CORE              # 描述(文档化)
  no shutdown                           # 开启接口
  shutdown                              # 关闭接口
  speed 100 / duplex full               # 手动设速率/双工
show ip interface brief     # 接口IP+状态(核心排错命令)
show interfaces             # 接口详细信息(流量/错误/双工)
show ip interface           # IP相关详情

17.3 交换配置(VLAN/Trunk/STP/EtherChannel)

vlan 10
  name SALES                          # 创建VLAN+命名
interface f0/1
  switchport mode access
  switchport access vlan 10           # 端口划入VLAN
interface g0/1
  switchport mode trunk
  switchport trunk allowed vlan 10,20,30   # trunk只允许这些VLAN
  switchport trunk native vlan 99          # 改native
  switchport nonegotiate                   # 禁用DTP
spanning-tree mode rapid-pvst              # 快速生成树
interface f0/1
  spanning-tree portfast                   # 接入端口快速转发
  spanning-tree bpduguard enable           # BPDU防护
interface range g0/1-2
  channel-group 1 mode active              # EtherChannel(LACP)
interface port-channel 1
  switchport mode trunk                    # 通道类型
show vlan brief
show interfaces trunk
show spanning-tree
show etherchannel summary

17.4 路由配置(静态/默认/OSPF)

ip route 192.168.2.0 255.255.255.0 192.168.1.2     # 静态(下一跳)
ip route 192.168.2.0 255.255.255.0 serial0/0/0       # 静态(出接口)
ip route 0.0.0.0 0.0.0.0 192.168.1.254               # 默认路由
router ospf 1
  router-id 1.1.1.1
  network 192.168.1.0 0.0.0.255 area 0               # 宣告(反掩码!)
show ip route
show ip route ospf / static
show ip ospf neighbor

17.5 IP 服务(DHCP/NAT/ACL)

# DHCP服务器
ip dhcp excluded-address 192.168.1.1 192.168.1.10
ip dhcp pool LAN
  network 192.168.1.0 255.255.255.0
  default-router 192.168.1.1
  dns-server 8.8.8.8
# DHCP中继
interface g0/0
  ip helper-address 192.168.2.5

# NAT/PAT
access-list 1 permit 192.168.1.0 0.0.0.255
ip nat inside source list 1 interface g0/1 overload
ip nat inside source static 192.168.1.50 203.0.113.50   # 静态NAT
interface g0/0 → ip nat inside
interface g0/1 → ip nat outside

# ACL
access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80
ip access-list extended BLOCK
  deny tcp any any eq 23
  permit ip any any
interface g0/1
  ip access-group 100 in
show ip dhcp binding
show ip nat translations
show access-lists

17.6 安全配置(端口安全/SSH/密码)

# 基础密码
enable secret cisco123
service password-encryption
banner motd #UNAUTHORIZED ACCESS PROHIBITED#
line console 0 / line vty 0 4
  password cisco
  login
  exec-timeout 5 0            # 5分钟超时

# SSH
hostname R1
ip domain-name example.com
crypto key generate rsa
username admin secret cisco123
line vty 0 4
  transport input ssh
  login local

# 端口安全
interface f0/1
  switchport mode access
  switchport port-security
  switchport port-security maximum 2
  switchport port-security violation shutdown
  switchport port-security mac-address sticky
show port-security address
show port-security interface f0/1

17.7 排错与验证命令(实验题的生命线)

ping 192.168.1.1            # 连通性
ping 192.168.1.1 source 192.168.2.1   # 指定源IP(多路由场景)
traceroute 8.8.8.8          # 逐跳路径
show cdp neighbors          # 直连邻居发现(Cisco私有)
show lldp neighbors         # 标准邻居发现
show arp                    # ARP表(IP-MAC)
show mac address-table      # 交换机MAC表
show ip interface brief     # 接口状态总览
show interfaces             # 接口错误/双工/CRC
show ip route               # 路由表
show running-config | include ip route   # 过滤查看
debug ip packet             # 包级调试(慎用,生产禁用)
show logging                # 日志
clear counters              # 清接口计数(看增量)
terminal monitor            # 远程会话看debug输出
记忆方法:命令不要死背——在 Packet Tracer / GNS3 里每章配一遍,手指记忆比眼睛记忆牢10倍。考前把本表过三遍,每个命令想一遍"什么时候用"。

18Exam Strategy & Practice

Core Passing strategy + self-test questions to verify your level. After this chapter: know how the exam works, know your study priorities, and check yourself with the practice set.

18.1 CCNA 200-301 Exam Overview (know the format)

ItemDetails
Duration120 minutes
Questions~100-110 (single/multiple-choice, drag-drop, simlets)
ScoringOut of ~1000; passing ~825-850 (not published; varies by pool)
Format mix~70% objective + ~20% drag-drop + ~10% labs (SIM)
Exam code200-301 (single exam, no split)

Official blueprint weights (read this — it decides your study effort):

TopicWeightHandbook chapters
Network Fundamentals20%Ch 1-4
Network Access (switching)20%Ch 5-8
IP Connectivity (routing)25%Ch 9-11
IP Services10%Ch 12
Security Fundamentals15%Ch 13-15
Automation & Programmability10%Ch 16
Study allocation: IP Connectivity (25%) + Network Fundamentals (20%) + Network Access (20%) = 65% of your score lives in routing, switching, and subnetting — master these three first for the best ROI.

18.2 Study Roadmap (an 8-week example)

Weeks 1-2 · Foundation: Ch 1-4 (OSI/Ethernet/IP addressing/transport). Do 10 subnetting problems daily until instant.
Weeks 3-4 · Switching: Ch 5-8 (VLAN/Trunk/STP/EtherChannel). Configure every lab once in Packet Tracer.
Weeks 5-6 · Routing + Services: Ch 9-12 (static/OSPF/IPv6/DHCP/NAT). Focus on NAT and OSPF labs.
Week 7 · Security + Automation: Ch 13-16. ACL and port security labs are mandatory.
Week 8 · Sprint: Ch 17 quick reference three times + practice exams + fill gaps.

Invest 1-2 hours daily, with hands-on ≥50% of the time. Reading without labs = wasted study — the Cisco exam tests "can you configure and troubleshoot," not "have you seen these commands."

18.3 Exam Techniques (points you can bank)

  • Do subnetting first: calculation questions early while fresh — guaranteed points.
  • Drag-and-drop: answers usually include distractors (e.g., a protocol that doesn't exist).
  • Simlets (labs): configure only what's needed, nothing extra; verify with show; save when done (copy run start doesn't always count but it's a good habit).
  • Multi-select: the question says "Choose two/three" — over- or under-selecting both fail; if unsure, don't add.
  • Time management: 120 min / ~110 questions ≈ 1 min each. Flag uncertain ones and come back.
  • Process of elimination: when unsure, first drop obviously wrong answers (wrong port, wrong AD, wrong layer).

18.4 Comprehensive Self-Test (35 questions, answers included)

Part A · Network Fundamentals (Ch 1-4)

Q1. How many usable hosts in a /26 subnet (255.255.255.192)?
A. 62 B. 64 C. 126 D. 30
Answer: A (2^6 - 2 = 62).

Q2. At which layer does a router work? How does it isolate networks?
Answer: Layer 3 (network); it separates broadcast domains.

Q3. Data travels from host A to host B through 2 routers. How often do MAC and IP change?
Answer: MAC 3 times (once per hop); IP never (end-to-end).

Q4. When does a switch flood a frame?
Answer: when the destination MAC is unknown (not in the table) or is broadcast/multicast.

Q5. Which protocol uses UDP? A. FTP B. HTTP C. DNS D. SMTP
Answer: C (DNS default UDP/53).

Q6. HTTPS port and its two underlying protocols?
Answer: 443; HTTP + TLS/SSL.

Q7. 172.16.0.0/12 is which class?
Answer: Class B private range (172.16.0.0-172.31.255.255).

Q8. Where is CSMA/CA used, and why not CD?
Answer: wireless (802.11); wireless can't listen while transmitting and has hidden nodes.

Part B · Switching (Ch 5-8)

Q9. In STP, what determines the root bridge?
Answer: smallest Bridge ID (priority + MAC, smaller wins).

Q10. Where is the 802.1Q tag inserted, and how many bytes?
Answer: after the source MAC; 4 bytes.

Q11. Which VLAN is untagged on a trunk?
Answer: the Native VLAN (default VLAN 1).

Q12. Port security defaults: max MACs and violation mode?
Answer: maximum 1; violation shutdown.

Q13. LACP's active mode name?
Answer: active (passive is the passive side).

Q14. 802.1D blocking to forwarding: how long, which states?
Answer: ~50 s; blocking → listening → learning → forwarding.

Q15. What does inter-VLAN communication need?
Answer: a Layer-3 device (router / L3 switch), e.g., Router-on-a-Stick or SVIs.

Part C · Routing & IP Services (Ch 9-12)

Q16. OSPF's AD? Hello/Dead on Ethernet?
Answer: AD=110; Hello 10 s, Dead 40 s.

Q17. Which NAT lets many internal hosts share one public IP?
Answer: PAT (overload).

Q18. Static and OSPF both present, same prefix — which wins?
Answer: static (AD 1 < OSPF 110) — but if the OSPF prefix is longer (/28 vs /24), OSPF wins (longest match outranks AD).

Q19. The four DHCP steps?
Answer: Discover → Offer → Request → Ack (DORA).

Q20. How do you write a default route?
Answer: ip route 0.0.0.0 0.0.0.0 <next-hop>.

Q21. IPv6 loopback and unspecified?
Answer: ::1 and ::.

Q22. What replaces ARP in IPv6?
Answer: NDP (NS/NA, based on ICMPv6).

Q23. Why DR/BDR on Ethernet OSPF?
Answer: to reduce adjacencies — full mesh on a multi-access network is too costly; everyone syncs only with DR/BDR.

Q24. Wildcard mask to advertise 192.168.1.0/24 in OSPF?
Answer: 0.0.0.255.

Part D · Security & Automation (Ch 13-16)

Q25. Standard vs extended ACL: what do they match, where are they placed?
Answer: standard = source IP, near destination; extended = src/dst IP + ports, near source.

Q26. The implicit rule at the end of an ACL?
Answer: implicit deny — unmatched traffic is dropped.

Q27. Remote management protocol? Port? vs Telnet?
Answer: SSH (22, encrypted); Telnet (23, plaintext, obsolete).

Q28. What does DHCP Snooping block?
Answer: rogue DHCP servers (untrusted ports drop DHCP Offer).

Q29. YANG, NETCONF, RESTCONF — what are they?
Answer: YANG = data modeling language; NETCONF = XML configuration protocol; RESTCONF = REST-style config interface.

Q30. Which two planes does SDN separate?
Answer: control plane (brain) and data plane (forwarding).

Q31. The must-use wireless encryption?
Answer: WPA2/WPA3 + AES (WEP is obsolete).

Q32. Why is PPP CHAP safer than PAP?
Answer: CHAP challenge-response + MD5 hash; the password never leaves the wire; PAP is plaintext.

Part E · Simlet-style questions (think through the steps)

Q33. Two switches each have VLAN 10; PCs can't ping each other. Troubleshoot.
Steps: ① show vlan brief — does VLAN 10 exist on both ends with ports assigned? ② show interfaces trunk — is the interconnect a trunk with Status=trunking? ③ allowed list contains 10? native VLAN matches? ④ ping the gateway / hop-by-hop.

Q34. PAT is configured but internal users still can't reach the Internet. Check what?
Steps: ① show ip nat translations — any translations? (none = ACL didn't match or inside/outside not marked); ② show ip interface brief — is the outside interface up? ③ show ip route — is there a default route? ④ does the ACL permit the internal network?

Q35. OSPF neighbors stuck at EXSTART — why?
Answer: usually an MTU mismatch — the interfaces' MTUs differ, breaking LSA exchange. Set MTU to match.

18.5 The 24-Hour Countdown Checklist

  • Run through the Ch 17 CLI quick reference (blind-write the commands).
  • 10 subnetting warm-ups (instant recall).
  • Memorize ADs (0/1/90/110/120), ports (80/443/22/23/53/67/68/110/143), the STP state machine.
  • Re-read every "memory" box (this handbook's tip/warn boxes are condensed exam points).
  • Sleep well, bring ID, arrive early.
Closing words: networking is a hands-on discipline. Type every chapter's commands once — it beats reading the text ten times. Get subnetting to "instant," and configure routing/switching/ACL/NAT end-to-end on a simulator, and you already have the hard skill to pass CCNA. This handbook gives you "what's tested, how to learn it, how to practice it" — the rest is your time and your fingers. Good luck! 🎯

18考试策略与综合练习

核心 通过策略 + 模拟题自测,检验掌握程度。学完本章要能:知道考试怎么考、知道复习优先级、用自测题检验水平。

18.1 CCNA 200-301 考试概况(了解形式)

项说明
考试时长120 分钟
题量约 100-110 题(单选/多选/拖放/模拟实验)
总分/及格1000 分制,及格线约 825-850(官方不固定公布,随题组浮动)
题型分布约70%客观题 + 20%拖放 + 10%实验(SIM)
考试号200-301(CCNA 单一考试,无分科)

官方考试大纲权重(必看,决定复习投入):

主题权重对应本手册章节
网络基础 Network Fundamentals20%第1-4章
网络接入 Network Access(交换)20%第5-8章
IP 连接 IP Connectivity(路由)25%第9-11章
IP 服务 IP Services10%第12章
安全基础 Security Fundamentals15%第13-15章
自动化和可编程性10%第16章
复习分配建议:IP连接(25%) + 网络基础(20%) + 网络接入(20%) = 65%的分数集中在路由、交换、子网——这三块务必吃透,性价比最高。

18.2 备考路线图(8周计划示例)

第1-2周 · 打地基:第1-4章(OSI/以太网/IP编址/传输层)。每天算10道子网题,练到秒算。
第3-4周 · 交换:第5-8章(VLAN/Trunk/STP/EtherChannel)。Packet Tracer 配一遍所有实验。
第5-6周 · 路由+服务:第9-12章(静态/OSPF/IPv6/DHCP/NAT)。重点 NAT 和 OSPF 实验。
第7周 · 安全+自动化:第13-16章。ACL、端口安全必配。
第8周 · 冲刺:第17章速查表过3遍 + 刷模拟题 + 查漏补缺。

每天建议投入1-2小时,动手实验≥50%时间。只看不练 = 白学——Cisco 考试考的是"能不能配、能不能排错",不是"认不认识命令"。

18.3 考试技巧(拿分细节)

  • 子网题先做:计算题放前面做,状态好、稳拿分。
  • 拖放题:注意答案通常有干扰项(比如多给一个不存在的协议)。
  • 实验题(SIM):只配需要的部分,别多配;配完用 show 验证;注意保存(copy run start 可做可不做,不影响评分但养成习惯)。
  • 多选题:题目会明确"Choose two/three";少选多选都错,不确定就别选。
  • 时间管理:120分钟110题,平均1分钟/题。模拟题标记后跳,最后回来。
  • 排除法:拿不准时先排除明显错误的(端口号不对、AD不对、协议层不对)。

18.4 综合自测题(60题模拟精选,每题附解析)

Part A · 网络基础(对应第1-4章)

Q1. 一个 /26 子网(255.255.255.192)能容纳多少可用主机?
A. 62 B. 64 C. 126 D. 30
答案:A(2^6 - 2 = 62)。

Q2. 路由器工作在哪一层?它如何隔离网络?
答案:第3层(网络层),路由器分隔广播域。

Q3. 数据从主机A到主机B经过2台路由器,MAC地址和IP地址各改变几次?
答案:MAC变3次(每跳一次),IP不变(端到端)。

Q4. 交换机在什么情况下泛洪帧?
答案:目的MAC未知(不在MAC表)或目的MAC是广播/组播时。

Q5. 以下哪个协议使用UDP?A. FTP B. HTTP C. DNS D. SMTP
答案:C(DNS默认UDP/53)。

Q6. HTTPS 使用哪个端口?基于哪两个协议?
答案:443;HTTP + TLS/SSL。

Q7. 私有地址 172.16.0.0/12 属于哪个类?
答案:B类私有范围(172.16.0.0–172.31.255.255)。

Q8. CSMA/CA 用在什么网络?为什么不用 CD?
答案:无线(802.11);无线无法边发边听且有隐藏节点。

Part B · 交换(对应第5-8章)

Q9. STP 中,什么决定哪台交换机成为根桥?
答案:桥 ID 最小(优先级 + MAC地址,值越小越优)。

Q10. 802.1Q 标签插在帧的什么位置?共几字节?
答案:源MAC之后;4字节。

Q11. Trunk 上哪个 VLAN 的帧不打标签?
答案:Native VLAN(默认VLAN 1)。

Q12. 端口安全默认最大MAC数和违规模式?
答案:maximum 1;violation shutdown。

Q13. EtherChannel 中 LACP 的主动模式叫什么?
答案:active(被动是passive)。

Q14. 802.1D 从阻塞到转发约需多久?经过哪些状态?
答案:约50秒;阻塞→监听→学习→转发。

Q15. 跨VLAN通信需要什么?
答案:第3层设备(路由器/三层交换机),如单臂路由或SVI。

Part C · 路由与IP服务(对应第9-12章)

Q16. OSPF 的管理距离是?Hello/Dead间隔(以太网)?
答案:AD=110;Hello 10秒、Dead 40秒。

Q17. 哪种 NAT 让多台内网主机共享一个公网 IP?
答案:PAT(过载 overload)。

Q18. 静态路由和 OSPF 同时存在且前缀相同,用哪个?
答案:静态(AD 1 < OSPF 110)——但若 OSPF 前缀更长(/28 vs /24),则 OSPF 优先(最长匹配优先于AD)。

Q19. DHCP 四步过程是?
答案:Discover → Offer → Request → Ack(DORA)。

Q20. 默认路由怎么写?
答案:ip route 0.0.0.0 0.0.0.0 <下一跳>。

Q21. IPv6 的环回地址和未指定地址是?
答案:::1 和 ::。

Q22. IPv6 用什么替代 ARP?
答案:NDP 邻居发现协议(NS/NA,基于ICMPv6)。

Q23. OSPF 在以太网上为什么要选 DR/BDR?
答案:减少邻接数量——多路访问网络中全互联开销太大,所有人只与DR/BDR同步。

Q24. 配置OSPF宣告 192.168.1.0/24 的反掩码是?
答案:0.0.0.255。

Part D · 安全与自动化(对应第13-16章)

Q25. 标准ACL和扩展ACL分别匹配什么?放哪里?
答案:标准ACL匹配源IP放目的端;扩展ACL匹配源/目的IP+端口放源端。

Q26. ACL 末尾的隐式规则是什么?
答案:隐式拒绝(implicit deny)——没匹配的全拒。

Q27. 远程管理设备用哪个协议?端口?对比 Telnet?
答案:SSH(22,加密);Telnet(23,明文,弃用)。

Q28. DHCP Snooping 防什么攻击?
答案:假冒DHCP服务器(不信任端口丢弃DHCP Offer)。

Q29. YANG、NETCONF、RESTCONF 分别是什么?
答案:YANG=数据建模语言;NETCONF=XML配置协议;RESTCONF=REST风格配置接口。

Q30. SDN 分离了哪两个平面?
答案:控制平面(大脑)和数据平面(转发)。

Q31. 无线安全必用的加密方式?
答案:WPA2/WPA3 + AES(WEP已废弃)。

Q32. PPP 的 CHAP 比 PAP 安全在哪?
答案:CHAP挑战-响应+MD5哈希,密码不出网;PAP明文。

Part E · 实验题模拟(按步骤想答案)

Q33. 两台交换机各配了VLAN 10,PC互ping不通,你怎么排错?
步骤:① show vlan brief 确认两端VLAN 10存在且端口划分正确;② show interfaces trunk 确认互联口是trunk且Status=trunking;③ 确认两端trunk的allowed列表包含10、native VLAN一致;④ ping网关/对端逐跳定位。

Q34. 路由器上配置了PAT但内网还是上不了网,检查什么?
步骤:① show ip nat translations 有没有转换(没有=ACL没匹配或接口没标inside/outside);② show ip interface brief 外网口up吗;③ show ip route 有默认路由吗;④ 确认ACL permit了内网网段。

Q35. OSPF 邻居状态停在 EXSTART,什么原因?
答案:常见MTU不匹配——两端接口MTU不一致导致LSA无法交换。改MTU一致即可。

18.5 考前24小时清单

  • 过一遍第17章 CLI 速查表(命令盲写)。
  • 子网题10道热身(确保秒算)。
  • 背AD表(0/1/90/110/120)、端口号(80/443/22/23/53/67/68/110/143)、STP状态机。
  • 重看每个"记忆口诀"框(本手册的 tip/warn 框就是浓缩考点)。
  • 睡好觉,带证件,提前到考场。
结语:网络是实践学科。把每一章的命令亲手敲一遍,比只看十遍文字有效。子网计算做到"秒算",路由/交换/ACL/NAT 能在模拟器独立配通,你就已具备通过 CCNA 的硬实力。这份手册是把"考什么、怎么学、怎么练"全部给你了——剩下的,就是你的时间和手指。祝顺利!🎯