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.
Core Important Awareness Exam weight tiers
CCNA 200-301
深度学习手册
一份面向通过思科 CCNA 认证、并真正理解现代网络原理的完整学习指南。基于思科公开考试大纲与官方文档重写,覆盖网络基础、交换、路由、IP 服务、WAN、安全与自动化。
核心 重要 了解 考试权重分级
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.
| Layer | Name | PDU | Core responsibility | Typical protocols | Typical devices |
|---|---|---|---|---|---|
| 7 | Application | Data | Network service interface for applications; identifies communication peers | HTTP, FTP, SMTP, DNS, Telnet, DHCP | — (software) |
| 6 | Presentation | Data | Data format conversion, encryption, compression; ensures "the peer can understand" | SSL/TLS, JPEG, ASCII, MPEG | — (software) |
| 5 | Session | Data | Establish, manage, terminate sessions; dialog control (who talks first) | NetBIOS, RPC, SQL sessions | — (software) |
| 4 | Transport | Segment | End-to-end connection; reliable delivery; flow control; port addressing | TCP, UDP | — (firewalls sometimes) |
| 3 | Network | Packet | Logical addressing (IP); routing; fragmentation | IP, ICMP, ARP, OSPF, RIP | Router |
| 2 | Data Link | Frame | Physical addressing (MAC); error detection; media access control | Ethernet, PPP, HDLC, 802.11 | Switch, NIC |
| 1 | Physical | Bit | Transmit raw bitstream; electrical/mechanical/timing specs | RJ-45, fiber, twisted pair | Hub, repeater, transceiver |
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).
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).
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 Layer | OSI layers | Core responsibility | Typical protocols |
|---|---|---|---|
| Application | 5+6+7 | Services for applications, incl. format & encryption | HTTP, HTTPS, DNS, DHCP, SMTP, FTP, SNMP |
| Transport | 4 | End-to-end reliable/best-effort delivery, port addressing | TCP, UDP |
| Internet | 3 | Logical addressing & routing | IP, ICMP, ARP, OSPF, EIGRP |
| Network Access | 1+2 | Physical transmission & frame encapsulation | Ethernet, PPP, 802.11 |
1.6 Device-to-Layer Mapping (memorize this table)
| Device | Layer | Forwarding basis | Splits collision domains | Splits broadcast domains |
|---|---|---|---|---|
| Repeater / Hub | L1 | None (regenerates signal, floods all ports) | No (all ports one collision domain) | No |
| Bridge / Switch | L2 | MAC address table | Yes (one per port) | No (one broadcast domain by default; VLANs can split) |
| Router | L3 | IP routing table | Yes | Yes |
| Firewall | L3-4 (some to L7) | 5-tuple / session | Yes | Yes |
| Wireless AP (bridge mode) | L2 | MAC | Yes | No |
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, 光纤, 双绞线 | 集线器、中继器、收发器 |
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+加密都在)。
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服务器)。
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 |
1.6 设备与层的对应(必背表)
| 设备 | 工作层 | 转发依据 | 是否分割冲突域 | 是否分割广播域 |
|---|---|---|---|---|
| 中继器/集线器 Hub | 第1层 | 无(再生信号广播所有口) | 否(所有口在同一冲突域) | 否 |
| 网桥/交换机 Switch | 第2层 | MAC 地址表 | 是(每端口一个冲突域) | 否(默认一个广播域,VLAN可分割) |
| 路由器 Router | 第3层 | IP 路由表 | 是 | 是 |
| 防火墙 Firewall | 3-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:
| Mechanism | Full name | How it works | Used by |
|---|---|---|---|
| CSMA/CD | Carrier Sense Multiple Access / Collision Detection | Listen before send, listen while sending, back off and retransmit after a collision | Wired Ethernet (half-duplex era) |
| CSMA/CA | Carrier Sense Multiple Access / Collision Avoidance | Listen before send, wait actively (DIFS + random backoff), confirm with ACK, avoid collisions | Wireless (802.11) |
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":
| Field | Length | Purpose |
|---|---|---|
| Preamble | 7 bytes | Clock synchronization so the receiver can "align" the bitstream (not part of the frame) |
| SFD (Start Frame Delimiter) | 1 byte | Marks the frame start (10101011) |
| Destination MAC | 6 bytes | Receiver (unicast / multicast / broadcast) |
| Source MAC | 6 bytes | Sender |
| Length / Type | 2 bytes | ≤1500 means length (802.3); ≥1536 means upper-layer protocol type (0x0800=IPv4, 0x0806=ARP, 0x86DD=IPv6) |
| Payload | 46-1500 bytes | Upper-layer data (Layer-3 packet); padded if under 46 bytes |
| FCS (Frame Check Sequence) | 4 bytes | CRC 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).
| Name | Speed | Media | Max distance | Common interface |
|---|---|---|---|---|
| 10BASE-T | 10 Mbps | Cat3+ twisted pair | 100 m | RJ-45 |
| 100BASE-TX | 100 Mbps | Cat5 twisted pair | 100 m | RJ-45 |
| 1000BASE-T | 1 Gbps | Cat5e/6 twisted pair | 100 m | RJ-45 |
| 1000BASE-SX | 1 Gbps | Multimode fiber | 220-550 m | LC/SC |
| 1000BASE-LX | 1 Gbps | Single/multimode fiber | ~5 km (SMF) / 550 m (MMF) | LC/SC |
| 10GBASE-T | 10 Gbps | Cat6a/7 twisted pair | 100 m (Cat6a) / 55 m (Cat6) | RJ-45 |
| 10GBASE-SR | 10 Gbps | Multimode fiber | ~300 m | LC |
| 10GBASE-LR | 10 Gbps | Single-mode fiber | ~10 km | LC |
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).
2.6 Switch vs Hub vs Router (deep comparison)
| Device | OSI layer | Forwarding basis | Collision domains | Broadcast domains | Learns addresses |
|---|---|---|---|---|---|
| Hub | L1 | None (regenerates signal, floods all ports) | 1 (all ports share) | 1 | No |
| Switch | L2 | MAC address table | One per port (full-duplex = none) | 1 (VLANs can split) | Yes (learns MACs) |
| Router | L3 | IP routing table | One per interface | One 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.
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) |
2.2 以太网帧结构(把帧拆开看)
802.3 以太网帧(不带VLAN标签的基础帧)由以下字段组成,考试常考"各字段作用":
| 字段 | 长度 | 作用 |
|---|---|---|
| 前导码 Preamble | 7字节 | 同步时钟,让接收方"对齐"比特流(非帧内容) |
| SFD 帧起始定界符 | 1字节 | 标记帧开始(10101011) |
| 目的MAC | 6字节 | 接收者(单播/多播/广播) |
| 源MAC | 6字节 | 发送者 |
| 长度/类型 Type | 2字节 | ≤1500表示长度(802.3);≥1536表示上层协议类型(如0x0800=IPv4,0x0806=ARP,0x86DD=IPv6) |
| 数据 Payload | 46–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-T | 10 Mbps | Cat3+ 双绞线 | 100 m | RJ-45 |
| 100BASE-TX | 100 Mbps | Cat5 双绞线 | 100 m | RJ-45 |
| 1000BASE-T | 1 Gbps | Cat5e/6 双绞线 | 100 m | RJ-45 |
| 1000BASE-SX | 1 Gbps | 多模光纤 | 220–550 m | LC/SC |
| 1000BASE-LX | 1 Gbps | 单模/多模光纤 | ~5 km(单模)/550m(多模) | LC/SC |
| 10GBASE-T | 10 Gbps | Cat6a/7 双绞线 | 100 m(Cat6a)/55m(Cat6) | RJ-45 |
| 10GBASE-SR | 10 Gbps | 多模光纤 | ~300 m | LC |
| 10GBASE-LR | 10 Gbps | 单模光纤 | ~10 km | LC |
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)。
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)
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) | Decimal | Meaning |
|---|---|---|
| 10000000 | 128 | /25 mask last octet |
| 11000000 | 192 | /26 mask last octet |
| 11100000 | 224 | /27 mask last octet |
| 11110000 | 240 | /28 mask last octet |
| 11111000 | 248 | /29 mask last octet |
| 11111100 | 252 | /30 mask last octet |
| 11111111 | 255 | full 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:
| Class | First octet binary | First octet decimal | Default mask | Networks/hosts | Use |
|---|---|---|---|---|---|
| A | 0xxxxxxx | 1-126 | 255.0.0.0 (/8) | 126 nets / 16,777,214 hosts | Very large |
| B | 10xxxxxx | 128-191 | 255.255.0.0 (/16) | 16,384 nets / 65,534 hosts | Medium |
| C | 110xxxxx | 192-223 | 255.255.255.0 (/24) | 2,097,152 nets / 254 hosts | Small |
| D | 1110xxxx | 224-239 | — (multicast) | — | Multicast |
| E | 1111xxxx | 240-255 | — (reserved) | — | Research |
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):
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)
| Mask | CIDR | Borrow n | Subnets 2^n | Usable hosts 2^m-2 | Block size |
|---|---|---|---|---|---|
| 255.255.255.0 | /24 | 0 | 1 | 254 | 256 |
| 255.255.255.128 | /25 | 1 | 2 | 126 | 128 |
| 255.255.255.192 | /26 | 2 | 4 | 62 | 64 |
| 255.255.255.224 | /27 | 3 | 8 | 30 | 32 |
| 255.255.255.240 | /28 | 4 | 16 | 14 | 16 |
| 255.255.255.248 | /29 | 5 | 32 | 6 | 8 |
| 255.255.255.252 | /30 | 6 | 64 | 2 | 4 |
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个)
3.2 二进制↔十进制转换(必须熟练)
八位二进制每一位的权重(从高位到低位):
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
1 1 0 0 1 0 1 0 = 128+64+8+2 = 202
几个必背的十进制值(考试秒用):
| 二进制(1的个数) | 十进制 | 含义 |
|---|---|---|
| 10000000 | 128 | /25 掩码末位 |
| 11000000 | 192 | /26 掩码末位 |
| 11100000 | 224 | /27 掩码末位 |
| 11110000 | 240 | /28 掩码末位 |
| 11111000 | 248 | /29 掩码末位 |
| 11111100 | 252 | /30 掩码末位 |
| 11111111 | 255 | 整段 |
幂次表(背到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),但类别概念仍是考试基础:
| 类 | 首八位二进制 | 首八位十进制 | 默认掩码 | 网络数/主机数 | 用途 |
|---|---|---|---|---|---|
| A | 0xxxxxxx | 1–126 | 255.0.0.0 (/8) | 126网 / 16,777,214主机 | 超大型网络 |
| B | 10xxxxxx | 128–191 | 255.255.0.0 (/16) | 16,384网 / 65,534主机 | 中型网络 |
| C | 110xxxxx | 192–223 | 255.255.255.0 (/24) | 2,097,152网 / 254主机 | 小型网络 |
| D | 1110xxxx | 224–239 | —(组播) | — | 组播 Multicast |
| E | 1111xxxx | 240–255 | —(保留) | — | 实验研究 |
3.4 子网划分核心技能(重点中的重点)
子网划分:把一个大网络的主机位"借"几位出来当子网位,从而拆成多个逻辑子网。目的:按部门/楼层隔离、减少广播域、节省地址、简化路由。
两条黄金公式(必须闭眼能背):
子网数量 = 2^n (n = 从主机位借用的位数)
每个子网可用主机数 = 2^m - 2 (m = 剩余的主机位数,减2去掉网络号和广播号)
一步步的解题流程(考试固定套路):
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 | /24 | 0 | 1 | 254 | 256 |
| 255.255.255.128 | /25 | 1 | 2 | 126 | 128 |
| 255.255.255.192 | /26 | 2 | 4 | 62 | 64 |
| 255.255.255.224 | /27 | 3 | 8 | 30 | 32 |
| 255.255.255.240 | /28 | 4 | 16 | 14 | 16 |
| 255.255.255.248 | /29 | 5 | 32 | 6 | 8 |
| 255.255.255.252 | /30 | 6 | 64 | 2 | 4 |
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:
| Mechanism | Purpose | Implementation |
|---|---|---|
| Three-way handshake | Establish connection; both confirm "you hear me, I hear you" | SYN → SYN-ACK → ACK |
| Sequence & ACK numbers | Ordering, no dup, no loss | One number per byte; ACK carries "next expected sequence" |
| ACK (acknowledgment) | Receiver confirms receipt | ACK on data; retransmit on timeout |
| Timeout retransmission | Loss recovery | Sender keeps an RTO timer |
| Sliding window | Flow control | Receiver advertises window size; sender sends at most "window" unacknowledged bytes |
| Congestion control | Avoid network congestion | Slow start, congestion avoidance, fast retransmit, fast recovery |
| Four-way teardown | Graceful close | FIN → 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.
4.4 TCP vs UDP — the ultimate comparison table (memorize this)
| Dimension | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (3-way handshake) | Connectionless |
| Reliability | Reliable (ACK + retransmit) | Unreliable (best-effort) |
| Ordering | Ordered bytes (sequence numbers) | No ordering guarantee |
| Flow control | Yes (sliding window) | No |
| Congestion control | Yes (slow start, etc.) | No |
| Header | 20 bytes (more with options) | 8 bytes |
| Delivery model | Byte stream | Datagram (each independent) |
| Speed/overhead | Slow / high | Fast / low |
| Typical apps | HTTP, FTP, SMTP, SSH, Telnet | DNS, DHCP, VoIP, video, SNMP, games |
4.5 Port Numbers (memorize this table — instant exam points)
| Port | Protocol | Transport | One-line purpose |
|---|---|---|---|
| 20/21 | FTP | TCP | File transfer (20 data / 21 control) |
| 22 | SSH | TCP | Secure remote management (encrypted) |
| 23 | Telnet | TCP | Remote management (plaintext, insecure) |
| 25 | SMTP | TCP | Sending mail |
| 53 | DNS | UDP/TCP | Name resolution (UDP queries, TCP zone transfers) |
| 67/68 | DHCP | UDP | 67 server / 68 client |
| 69 | TFTP | UDP | Trivial file transfer (no auth) |
| 80 | HTTP | TCP | Web plaintext |
| 110 | POP3 | TCP | Receive mail (download then offline) |
| 143 | IMAP | TCP | Receive mail (online management) |
| 161/162 | SNMP | UDP | 161 queries / 162 traps |
| 443 | HTTPS | TCP | Encrypted web (HTTP + TLS) |
| 3389 | RDP | TCP | Windows remote desktop |
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).
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、在线游戏。
4.4 TCP vs UDP 终极对比表(背这张就够)
| 维度 | TCP | UDP |
|---|---|---|
| 连接 | 面向连接(三次握手) | 无连接 |
| 可靠性 | 可靠(ACK+重传) | 不可靠(尽力而为) |
| 有序性 | 字节有序(序号) | 无顺序保证 |
| 流量控制 | 有(滑动窗口) | 无 |
| 拥塞控制 | 有(慢启动等) | 无 |
| 报文头 | 20字节(选项可更大) | 8字节 |
| 传输方式 | 字节流(Stream) | 数据报(Datagram,每报独立) |
| 速度/开销 | 慢/高 | 快/低 |
| 典型应用 | HTTP, FTP, SMTP, SSH, Telnet | DNS, DHCP, VoIP, 视频, SNMP, 游戏 |
4.5 端口号(背这张表,考试直接得分)
| 端口 | 协议 | 传输层 | 一句话用途 |
|---|---|---|---|
| 20/21 | FTP | TCP | 文件传输(20数据/21控制) |
| 22 | SSH | TCP | 安全远程管理(加密) |
| 23 | Telnet | TCP | 远程管理(明文,不安全) |
| 25 | SMTP | TCP | 发邮件 |
| 53 | DNS | UDP/TCP | 域名解析(查询用UDP,区域传送用TCP) |
| 67/68 | DHCP | UDP | 67服务器/68客户端 |
| 69 | TFTP | UDP | 简单文件传输(无认证) |
| 80 | HTTP | TCP | 网页明文 |
| 110 | POP3 | TCP | 收邮件(下载后离线) |
| 143 | IMAP | TCP | 收邮件(在线管理) |
| 161/162 | SNMP | UDP | 161查询/162陷阱 |
| 443 | HTTPS | TCP | 网页加密(HTTP+TLS) |
| 3389 | RDP | TCP | Windows远程桌面 |
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,现代必须)。
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:
| Behavior | Trigger | Action |
|---|---|---|
| Forward | Destination MAC in table, port ≠ receiving port | Send out that port only (precise forwarding) |
| Flood | Destination MAC unknown, or destination is broadcast/multicast | Send out all ports (except the receiving port) |
| Drop | Destination 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.
5.3 VLAN Ranges (memorize the numbers)
| Range | Name | Notes |
|---|---|---|
| 0, 4095 | Reserved | System-reserved, unusable |
| 1 | Default | Factory default; cannot be renamed or deleted; all ports start here; default native VLAN |
| 2-1001 | Normal | Normal create/delete VLANs; names configurable |
| 1002-1005 | Normal | Reserved for FDDI/Token Ring (exam awareness) |
| 1006-4094 | Extended | Needs 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)
| Mode | Connects to | VLANs carried | Behavior |
|---|---|---|---|
| Access | End devices (PC, printer, IP phone) | 1 (tagged with its access VLAN) | Untagged frames in → tagged with the access VLAN; frames of other VLANs → dropped |
| Trunk | Switch-to-switch, switch-to-router | Many (all by default) | Frames carry 802.1Q tags; the native VLAN is untagged |
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!)
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 statusshows the cause; fix it, thenshutdown+no shutdownto 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可以跨多台交换机)。
- 性能优化:缩小广播域→减少无关流量→提高可用带宽。
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不打标签 |
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. 保存配置(必做!)
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.
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).
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.
| Mode | Behavior | Actively negotiates | Result |
|---|---|---|---|
| access | Force access port | No | Peer also access → access link |
| dynamic desirable | Actively "invites" the peer to trunk | Yes | Peer auto/desirable/trunk → becomes trunk |
| dynamic auto | Passively waits | No | Peer desirable/trunk → trunk; peer auto → stays access |
| trunk | Force trunk | Yes | Peer non-access → trunk |
| nonegotiate | DTP fully disabled | No | Both ends must be configured manually (e.g., to non-Cisco) |
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
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的帧即使混在同一根线上,也互不干扰。
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 报文,它们不带标签传输)。
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设备) |
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
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:
| Problem | Mechanism | Consequence |
|---|---|---|
| Broadcast storm | Broadcast frames replicate and circle the loop endlessly | Bandwidth instantly saturated, host CPUs overloaded, network paralysis |
| MAC table thrash | The same MAC is received on multiple ports repeatedly; entries flip-flop | Switch cannot forward correctly; frames misdelivered |
| Duplicate frames | The same frame arrives at the destination via different paths | Receiver 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)
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):
| Bandwidth | 802.1D cost | 802.1t (new) cost |
|---|---|---|
| 10 Mbps | 100 | 2,000,000 |
| 100 Mbps | 19 | 200,000 |
| 1 Gbps | 4 | 20,000 |
| 10 Gbps | 2 | 2,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
| State | Send/receive BPDU | Learn MACs | Forward data |
|---|---|---|---|
| Blocking | Receive only | No | No |
| Listening | Yes | No | No |
| Learning | Yes | Yes | No |
| Forwarding | Yes | Yes | Yes |
| Disabled | No | No | No |
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:
| Role | Meaning |
|---|---|
| Root | Same as 802.1D |
| Designated | Same as 802.1D |
| Alternate | Backup to the Root Port — takes over immediately if the primary root port fails |
| Backup | Backup to the Designated Port (redundant port to the same segment) |
| Disabled | Not 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).
7.6 STP Enhancements (frequently tested)
| Feature | What it does | Key command |
|---|---|---|
| PortFast | Access ports skip listening/learning, go straight to forwarding | spanning-tree portfast |
| BPDU Guard | PortFast port that receives a BPDU → err-disable (blocks forged-root attacks) | spanning-tree bpduguard enable |
| Root Guard | Prevents a port from becoming a root port (protects the root's status) | spanning-tree guard root |
| Loop Guard | Prevents "no-BPDU misjudgment" on a unidirectional link from creating a loop | spanning-tree guard loop |
| UDLD | Detects unidirectional links (fiber TX/RX one-way) | udld enable |
| BPDU Filter | PortFast port discards BPDUs outright | spanning-tree bpdufilter enable |
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 选举三步曲(考试核心,必须背)
三条铁律记住:① 根桥上全是 DP;② 每台非根桥有且只有一个 RP;③ 每条链路两端,一端DP、另一端RP或阻塞。端口成本(Cost)表(必背):
| 带宽 | 802.1D Cost | 802.1t(新标准) Cost |
|---|---|---|
| 10 Mbps | 100 | 2,000,000 |
| 100 Mbps | 19 | 200,000 |
| 1 Gbps | 4 | 20,000 |
| 10 Gbps | 2 | 2,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 | 否 | 否 | 否 |
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 版本协商)。
7.6 STP 的增强特性(考试常考)
| 特性 | 作用 | 关键命令 |
|---|---|---|
| PortFast | 接入端口跳过监听/学习,直接转发(连PC) | spanning-tree portfast |
| BPDU Guard | PortFast口收到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 Filter | PortFast口直接丢弃BPDU | spanning-tree bpdufilter enable |
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.
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)
| Protocol | Standard | Modes | When to use |
|---|---|---|---|
| LACP | IEEE 802.3ad (standard, recommended) | active (sends LACP PDUs) / passive (waits) | Cross-vendor, new deployments |
| PAgP | Cisco proprietary | desirable (sends PAgP PDUs) / auto (waits) | Cisco-to-Cisco legacy |
Mode combination results (exam focus):
| One end \ other | active | passive | on |
|---|---|---|---|
| active | ✔ negotiates | ✔ negotiates | ✔ (on doesn't ask) |
| passive | ✔ negotiates | ✘ both passive, fails | ✔ |
| on | ✔ | ✔ | ✔ forced bundle (no negotiation) |
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)
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、或两者组合)把流量分散到各成员链路。
8.2 成员端口的一致性要求(配置失败的常见原因)
EtherChannel 内所有成员端口必须配置完全一致,否则通道起不来:
- 相同的速率和双工模式(如都是 1G 全双工)
- 相同的 Switchport 模式(都是 access 或都是 trunk)
- 相同的 VLAN 配置(access:同一VLAN;trunk:相同的 allowed 列表和 native VLAN)
- 相同的 STP 配置(PortFast 等尽量一致)
不一致时,端口可能变成 suspended(挂起),show 输出里能看到。
8.3 协商协议:LACP vs PAgP(必背对比)
| 协议 | 标准 | 模式 | 何时用 |
|---|---|---|---|
| LACP | IEEE 802.3ad(标准,推荐) | active(主动发LACP报文)/ passive(被动等) | 跨厂商设备、新部署 |
| PAgP | Cisco 私有 | desirable(主动发PAgP报文)/ auto(被动等) | Cisco-to-Cisco 老环境 |
模式组合结果(考试重点):
| 一端 \ 另一端 | active | passive | on |
|---|---|---|---|
| active | ✔ 协商成功 | ✔ 协商成功 | ✔(on不问) |
| passive | ✔ 协商成功 | ✘ 都不主动,失败 | ✔ |
| on | ✔ | ✔ | ✔ 强制捆绑(不协商) |
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 source | AD | Notes |
|---|---|---|
| Connected | 0 | Directly attached networks — most trusted |
| Static | 1 | Manually configured |
| EIGRP summary | 5 | Summary route |
| EIGRP | 90 | Cisco proprietary (awareness for newer CCNA) |
| OSPF | 110 | Link-state |
| RIP | 120 | Distance-vector |
| Unreachable | 255 | Not used |
9.3 Route Decision Logic (three comparisons, in order)
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 | 说明 |
|---|---|---|
| 直连 Connected | 0 | 接口直接相连的网络,最可信 |
| 静态 Static | 1 | 手工配置 |
| EIGRP 汇总 | 5 | 汇总路由 |
| EIGRP | 90 | Cisco 私有(较新CCNA了解即可) |
| OSPF | 110 | 链路状态 |
| RIP | 120 | 距离向量 |
| 不可达 | 255 | 不使用 |
9.3 路由决策逻辑(三个比较,顺序不能乱)
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):
| Type | Representatives | Principle | Pros | Cons |
|---|---|---|---|---|
| Distance Vector | RIP, EIGRP (hybrid) | "Hears from neighbors" — advertises its own table to neighbors, accumulates by hop/metric — "routing by rumor" | Simple, light on resources | Slow convergence, loop risk (needs split horizon / poison reverse) |
| Link State | OSPF, IS-IS | "Sees the whole map" — collects all link states (LSDB), computes shortest paths itself with SPF | Fast convergence, loop-free, VLSM/CIDR support | CPU/memory heavy, needs hierarchy (areas) |
10.2 How OSPF Works (neighbor → adjacency → LSDB → SPF → table)
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)
| Parameter | Value | Notes |
|---|---|---|
| Administrative distance | 110 | Route trustworthiness |
| Hello interval | Ethernet 10 s (point-to-point 10s, NBMA 30s) | Periodic keepalive |
| Dead interval | 40 s (4× Hello) | Neighbor declared dead after silence |
| Multicast addresses | 224.0.0.5 (all OSPF routers) / 224.0.0.6 (DR/BDR) | Targets for Hello/LSA |
| Metric cost | 10^8 / bandwidth (bps) | Smaller is better; manually adjustable |
| Area | 0 = backbone | CCNA 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:
router-id (highest priority — recommended, use a loopback).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).
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 Vector | RIP, EIGRP(混合) | "听邻居的"——只向邻居通告自己的路由表,按跳数/度量累加,"传闻路由"(routing by rumor) | 简单、省资源 | 收敛慢、有环路风险(需水平分割/毒性反转) |
| 链路状态 Link State | OSPF, IS-IS | "看全图"——每台路由器收集全网链路状态(LSDB),用 SPF 算法自己算最短路径 | 收敛快、无环路、支持VLSM/CIDR | 消耗CPU/内存,需分层(区域) |
10.2 OSPF 工作原理(邻居→邻接→LSDB→SPF→路由表)
邻居状态重点:2-Way(邻居建立、还没交换LSA)、Full(邻接完成、LSDB同步)——考试看 show ip ospf neighbor 的状态字段,Full 才是完全正常。
10.3 OSPF 关键参数(背数字)
| 参数 | 值 | 说明 |
|---|---|---|
| 管理距离 AD | 110 | 路由可信度 |
| Hello 间隔 | 以太网 10秒(点对点10秒,NBMA 30秒) | 周期保活报文 |
| Dead 间隔 | 40秒(4×Hello) | 超时未收Hello即邻居失效 |
| 组播地址 | 224.0.0.5(所有OSPF路由器)/ 224.0.0.6(DR/BDR) | Hello/LSA 发送目标 |
| 度量 Cost | 10^8 / 带宽(bps) | 越小越优;可手动改 |
| 区域 Area | 0 = 骨干区 | 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 地址)。重要: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 选举不可抢占——已经当选的不会因新来的更优而换(除非全网络重启)。
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
:: 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)
| Type | Prefix | Purpose | Notes |
|---|---|---|---|
| Global Unicast (GUA) | 2000::/3 | Public unique address, routable | Like IPv4 public |
| Unique Local (ULA) | fc00::/7 | Private internal addresses | Like IPv4 private (10.x / 192.168.x) |
| Link-Local | fe80::/10 | Same-link communication, auto-generated | Every interface has one; not routable; used for NDP/routing protocols |
| Loopback | ::1/128 | Self-test | Like 127.0.0.1 |
| Unspecified | ::/128 | Source address not yet assigned | Like 0.0.0.0 |
| Multicast | ff00::/8 | One-to-many | IPv6 has no broadcast — multicast replaces it |
| Anycast | — | Shared by multiple interfaces; delivers to the nearest | New 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
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:
| Message | What it does | Like |
|---|---|---|
| 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 info | DHCP announcement |
| DAD (Duplicate Address Detection) | Checks for conflicts before configuring an address | ARP 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)
| Dimension | IPv4 | IPv6 |
|---|---|---|
| Address length | 32 bits | 128 bits |
| Notation | Dotted decimal | Colon hex |
| Address count | 2^32 | 2^128 |
| Broadcast | Yes | No (multicast instead) |
| Address resolution | ARP | NDP (ICMPv6) |
| Autoconfiguration | DHCP | SLAAC + DHCPv6 |
| NAT | Ubiquitous | Not needed by design |
| Fragmentation | Routers can fragment | Only 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 地址类型与前缀(必背表)
| 类型 | 前缀 | 用途 | 备注 |
|---|---|---|---|
| 全球单播 GUA | 2000::/3 | 公网唯一地址,可路由 | 类似IPv4公网IP |
| 唯一本地 ULA | fc00::/7 | 内网私用地址 | 类似IPv4私网(10.x/192.168.x) |
| 链路本地 Link-Local | fe80::/10 | 同一链路内通信,自动生成 | 每接口必有;不可路由;用于邻居发现/路由协议 |
| 环回 Loopback | ::1/128 | 本机自测 | 类似127.0.0.1 |
| 未指定 Unspecified | ::/128 | 源地址未分配时 | 类似0.0.0.0 |
| 组播 Multicast | ff00::/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
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 对比(考试常考)
| 维度 | IPv4 | IPv6 |
|---|---|---|
| 地址长度 | 32位 | 128位 |
| 表示 | 点分十进制 | 冒号十六进制 |
| 地址数量 | 2^32 | 2^128 |
| 广播 | 有 | 无(用组播替代) |
| 地址解析 | ARP | NDP(ICMPv6) |
| 自动配置 | DHCP | SLAAC + 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
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):
| Type | Mapping | Features | Typical use |
|---|---|---|---|
| Static NAT | 1 private ↔ 1 fixed public | One-to-one, fixed, externally reachable | Public servers |
| Dynamic NAT | 1 private ↔ 1 public (from a pool) | One-to-one, temporary, no inbound | Many internal users egressing |
| PAT / overload | Many private ↔ 1 public (ports distinguish) | Many-to-one, most common, port-based | Home/office sharing one public IP |
The four address concepts (exams split hairs — know them):
| Term | Meaning | Example |
|---|---|---|
| Inside Local | Internal host as seen inside (private IP) | 192.168.1.10 |
| Inside Global | Internal host as seen outside (translated public IP) | 203.0.113.5 |
| Outside Local | External host as seen inside (usually the real IP) | 198.51.100.7 |
| Outside Global | External 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
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 # 排错
ip helper-address(DHCP中继)把广播转为单播转发到服务器。考试常考"DHCP跨网段怎么配"。12.3 NAT 网络地址转换(重点中的重点)
私有地址(RFC 1918)不能在公网路由。NAT 在边界设备上把私有 IP 转换为公网 IP。三个作用:节省公网地址、隐藏内网结构、地址重叠解决。
三类 NAT(必背):
| 类型 | 映射关系 | 特点 | 典型场景 |
|---|---|---|---|
| 静态 NAT | 1 私网IP ↔ 1 固定公网IP | 一对一、固定、可被外部主动访问 | 对外提供服务的服务器 |
| 动态 NAT | 1 私网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, 不同端口区分
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 technology | Type | Bandwidth/features | Use |
|---|---|---|---|
| Leased line | Point-to-point physical circuit | Fixed bandwidth, reliable, expensive | Banks/critical business |
| MPLS | Provider label-switched network | Flexible, QoS, enterprise-grade | Multi-site enterprise |
| IPsec VPN | Encrypted tunnel over public Internet | Low cost, encrypted, depends on Internet quality | Branches / remote workers |
| DSL | Broadband over phone line | Asymmetric (down fast, up slow) | Home / small office |
| Fiber broadband | FTTH/FTTB | Symmetric, high bandwidth | Enterprise / home |
| SD-WAN | Software-defined WAN | Smart 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):
| Item | PAP | CHAP |
|---|---|---|
| Auth method | Username + password sent in plaintext | Challenge-response (password never on the wire) |
| Frequency | Once at link setup | At setup + periodically repeated |
| Security | Weak (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:
| Standard | Band | Max rate | Notes |
|---|---|---|---|
| 802.11b | 2.4 GHz | 11 Mbps | Legacy, obsolete |
| 802.11g | 2.4 GHz | 54 Mbps | Backward-compatible with b |
| 802.11n (WiFi 4) | 2.4/5 GHz | ~600 Mbps | MIMO |
| 802.11ac (WiFi 5) | 5 GHz | ~6.9 Gbps | MU-MIMO, modern mainstream |
| 802.11ax (WiFi 6) | 2.4/5/6 GHz | ~9.6 Gbps | OFDMA, 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):
| Mechanism | Security | Encryption | Status |
|---|---|---|---|
| WEP | Very weak (cracked in minutes) | RC4 (static keys) | Obsolete |
| WPA | Weak | TKIP (RC4 + dynamic keys) | Transitional, deprecated |
| WPA2 | Strong | AES (CCMP) | Modern standard |
| WPA3 | Stronger | AES-GCMP, brute-force resistant | Latest standard |
13.5 Wireless vs Wired (frequently compared)
| Dimension | Wired Ethernet | Wireless 802.11 |
|---|---|---|
| Media access | Full-duplex switching (no collisions) | Half-duplex shared medium, CSMA/CA |
| Security | Physical access control (plug in to connect) | Signals travel through air — must encrypt (WPA2/3) |
| Bandwidth | Stable, dedicated (switched) | Shared, varies with distance/interference |
| Deployment | Cabling cost | Flexible, 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(必背):
| 项 | PAP | CHAP |
|---|---|---|
| 认证方式 | 用户名+密码明文传输 | 挑战-响应(密码不出网) |
| 次数 | 建链时一次 | 建链时 + 周期性重复 |
| 安全性 | 弱(明文,可被窃听) | 强(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.11b | 2.4GHz | 11 Mbps | 老标准,基本淘汰 |
| 802.11g | 2.4GHz | 54 Mbps | 兼容b |
| 802.11n (WiFi 4) | 2.4/5GHz | ~600 Mbps | MIMO多天线 |
| 802.11ac (WiFi 5) | 5GHz | ~6.9 Gbps | MU-MIMO,现代主流 |
| 802.11ax (WiFi 6) | 2.4/5/6GHz | ~9.6 Gbps | OFDMA,最新 |
关键概念:
- 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,防暴力破解 | 最新标准 |
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)
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)
| Item | Standard ACL | Extended ACL |
|---|---|---|
| Number ranges | 1-99, 1300-1999 | 100-199, 2000-2699 |
| Matches on | source IP only | source + destination IP + protocol (TCP/UDP/ICMP) + ports |
| Placement | As close to the destination as possible | As close to the source as possible (drop early, save bandwidth) |
| Granularity | Coarse (by source only) | Fine (down to protocol/port) |
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.
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 的判读规则,必背)
show access-lists 看每条规则的匹配计数——没命中说明放错位置/方向/顺序。14.3 标准 ACL vs 扩展 ACL(必背对比)
| 项 | 标准 ACL | 扩展 ACL |
|---|---|---|
| 编号范围 | 1–99, 1300–1999 | 100–199, 2000–2699 |
| 匹配依据 | 仅源IP | 源IP + 目的IP + 协议(TCP/UDP/ICMP) + 端口 |
| 放置位置 | 尽量靠近目的端(别误伤中间流量) | 尽量靠近源端(早拒绝省带宽) |
| 粒度 | 粗(只能按来源分) | 细(能精确到协议/端口) |
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:
| Mode | Behavior | Security |
|---|---|---|
| Shutdown (default) | Port goes err-disable (off); manual no shutdown to recover | Strictest |
| Restrict | Drops violating frames + logs/counts; port keeps working | Medium |
| Protect | Drops violating frames only (no log, no count); port continues | Weak (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
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)
| Technology | Blocks | How |
|---|---|---|
| DHCP Snooping | Rogue DHCP servers | Trusted/untrusted ports; untrusted ports drop DHCP Offer/Ack (only trusted ports may send DHCP responses) |
| DAI (Dynamic ARP Inspection) | ARP spoofing / MITM | Validates ARP packets against the DHCP Snooping binding table (IP-MAC must match) |
| IP Source Guard | IP spoofing | A port may only use source IPs from the binding table (based on DHCP Snooping) |
| PortFast + BPDU Guard | Rogue switches altering STP | Access port that receives a BPDU → err-disable |
| Disable DTP | VLAN hopping | switchport nonegotiate |
| VLAN minimization | VLAN hopping | Trunks carry only needed VLANs; native VLAN moved to an unused VLAN |
| VLAN ACL (VACL) | Intra-VLAN traffic filtering | Apply ACLs to traffic within a VLAN |
| Storm Control | Broadcast/multicast storms | Drops broadcast frames over a threshold |
15.4 Device Management Security (basic but tested)
| Item | Recommended | Banned | Notes |
|---|---|---|---|
| Remote mgmt | SSH (22, encrypted) | Telnet (23, plaintext) | SSH needs a domain + key: ip domain-name + crypto key generate rsa |
| Privileged password | enable secret | enable password | secret stores a hash (MD5); password is plaintext |
| Password encryption | service password-encryption | — | Encrypts plaintext passwords in config (weak, better than nothing) |
| AAA | RADIUS (UDP 1812/1813) or TACACS+ (TCP 49) | Local password only (small scale) | TACACS+ encrypts the whole packet; RADIUS only the password |
| Login banner | banner motd | — | Legal warning: unauthorized access prohibited |
| Idle timeout | exec-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
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 Guard | IP欺骗 | 端口只能使用绑定表中的源IP(基于DHCP Snooping) |
| PortFast + BPDU Guard | 私接交换机改STP拓扑 | 接入口收到BPDU→err-disable |
| 禁用DTP | VLAN跳转攻击 | switchport nonegotiate |
| VLAN 最小化 | VLAN 跳转 | trunk只允许必要VLAN;native VLAN改为未用VLAN |
| VLAN ACL (VACL) | VLAN内流量过滤 | 对VLAN内流量应用ACL |
| Storm Control | 广播/组播风暴 | 超阈值丢弃广播帧 |
15.4 设备管理安全(基础但必考)
| 项 | 推荐 | 禁用 | 说明 |
|---|---|---|---|
| 远程管理 | SSH(22,加密) | Telnet(23,明文) | SSH需配域名+密钥:ip domain-name + crypto key generate rsa |
| 特权密码 | enable secret | enable password | secret存哈希(MD5),password明文 |
| 口令加密 | service password-encryption | — | 配置里明文密码加密(弱加密,聊胜于无) |
| AAA | RADIUS(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.
| Plane | Responsibility | Analogy |
|---|---|---|
| Control Plane | Decides "how traffic goes": routing computation, routing/forwarding table construction, protocol processing | Brain (decides) |
| Data Plane | Actually "forwards traffic": table lookup, frame/packet processing | Hands (executes) |
| Management Plane | Operations: SSH/SNMP/NETCONF config & monitoring | Administration (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).
16.3 SDN Interfaces (API directions)
| Interface | Direction | Purpose | Protocols |
|---|---|---|---|
| Southbound | Controller ↓ devices | Controller pushes forwarding rules/config to devices | OpenFlow, NETCONF, RESTCONF, gRPC |
| Northbound | Apps/upper layers ↑ controller | Apps express network requirements to the controller | REST API (common) |
| East-West | Controller ↔ controller | Multi-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)
| Protocol | Type | Data format | Port | Features |
|---|---|---|---|---|
| SNMP | Traditional, polled | MIB (ASN.1) | UDP 161/162 | Read-only monitoring mostly; v3 adds encryption; manager polls + device Traps |
| NETCONF | Modern, full-duplex | XML | SSH(830)/TLS | Config/state separation; YANG models; transactions/rollback |
| RESTCONF | Modern, RESTful | JSON/XML | HTTPS(443) | REST version of NETCONF; HTTP verbs; simple |
| gRPC | Modern | Binary (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.
16.5 REST API & JSON (must-know basics)
REST API: operate on resources (identified by URLs) with HTTP methods:
| HTTP method | Action | DB analogy |
|---|---|---|
| GET | Read a resource | SELECT |
| POST | Create a resource | INSERT |
| PUT | Full update/replace | UPDATE |
| PATCH | Partial update | UPDATE (local) |
| DELETE | Delete a resource | DELETE |
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)
| Tool | Positioning | Notes |
|---|---|---|
| Python + Netmiko / NAPALM / requests | Scripting | Direct SSH to devices for bulk exec/collection; most flexible |
| Ansible | Agentless config mgmt | Playbooks (YAML), declarative push over SSH; the enterprise workhorse |
| Git | Version control | Configs/scripts in Git: rollback, audit, collaboration |
| CI/CD (Jenkins etc.) | Continuous integration/deployment | Automated testing + release of config changes |
| Terraform / Ansible + YANG | Infrastructure as code | Bulk 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:控制器集中计算,交换机只负责执行(简化成转发设备)。
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 | 现代、全双工 | XML | SSH(830)/TLS | 配置与状态分离;用 YANG 数据模型;支持事务/回滚 |
| RESTCONF | 现代、REST风格 | JSON/XML | HTTPS(443) | NETCONF 的 REST 版,用 HTTP 方法,简单 |
| gRPC | 现代 | 二进制(Protobuf) | — | 高性能,Google系(gNMI/gNOI) |
YANG(Yet Another Next Generation):数据建模语言——用树形结构描述设备的配置/状态数据(如"接口有哪些属性")。NETCONF/RESTCONF 操作的就是 YANG 模型定义的数据。考试爱问"YANG 是什么"——数据模型/建模语言,不是协议。
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
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输出
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)
| Item | Details |
|---|---|
| Duration | 120 minutes |
| Questions | ~100-110 (single/multiple-choice, drag-drop, simlets) |
| Scoring | Out of ~1000; passing ~825-850 (not published; varies by pool) |
| Format mix | ~70% objective + ~20% drag-drop + ~10% labs (SIM) |
| Exam code | 200-301 (single exam, no split) |
Official blueprint weights (read this — it decides your study effort):
| Topic | Weight | Handbook chapters |
|---|---|---|
| Network Fundamentals | 20% | Ch 1-4 |
| Network Access (switching) | 20% | Ch 5-8 |
| IP Connectivity (routing) | 25% | Ch 9-11 |
| IP Services | 10% | Ch 12 |
| Security Fundamentals | 15% | Ch 13-15 |
| Automation & Programmability | 10% | Ch 16 |
18.2 Study Roadmap (an 8-week example)
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.
18考试策略与综合练习
核心 通过策略 + 模拟题自测,检验掌握程度。学完本章要能:知道考试怎么考、知道复习优先级、用自测题检验水平。
18.1 CCNA 200-301 考试概况(了解形式)
| 项 | 说明 |
|---|---|
| 考试时长 | 120 分钟 |
| 题量 | 约 100-110 题(单选/多选/拖放/模拟实验) |
| 总分/及格 | 1000 分制,及格线约 825-850(官方不固定公布,随题组浮动) |
| 题型分布 | 约70%客观题 + 20%拖放 + 10%实验(SIM) |
| 考试号 | 200-301(CCNA 单一考试,无分科) |
官方考试大纲权重(必看,决定复习投入):
| 主题 | 权重 | 对应本手册章节 |
|---|---|---|
| 网络基础 Network Fundamentals | 20% | 第1-4章 |
| 网络接入 Network Access(交换) | 20% | 第5-8章 |
| IP 连接 IP Connectivity(路由) | 25% | 第9-11章 |
| IP 服务 IP Services | 10% | 第12章 |
| 安全基础 Security Fundamentals | 15% | 第13-15章 |
| 自动化和可编程性 | 10% | 第16章 |
18.2 备考路线图(8周计划示例)
每天建议投入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 框就是浓缩考点)。
- 睡好觉,带证件,提前到考场。