1056 lines
27 KiB
Markdown
1056 lines
27 KiB
Markdown
---
|
||
title: "华为 hcnp 笔记"
|
||
date: 2021-03-06T22:45:00+08:00
|
||
lastmod: 2021-03-06T22:45:00+08:00
|
||
keywords: []
|
||
tags: ["华为", "hcnp"]
|
||
categories: ["network"]
|
||
---
|
||
|
||
## 基本命令
|
||
### 查看操作系统
|
||
- 用户模式下执行
|
||
```
|
||
dis version
|
||
```
|
||
|
||
### 修改语言
|
||
- 用户模式下执行
|
||
```
|
||
language-mode Chinese
|
||
```
|
||
|
||
### 保存配置
|
||
- 用户模式下执行
|
||
```
|
||
save
|
||
```
|
||
|
||
### 修改主机名
|
||
- 系统模式下执行
|
||
```
|
||
sysname XXXX
|
||
```
|
||
|
||
### 关闭提示信息
|
||
- 系统模式下执行
|
||
```
|
||
undo info-center enable
|
||
```
|
||
|
||
### 显示当前模式配置
|
||
- 任何模式下执行
|
||
```
|
||
dis this
|
||
```
|
||
|
||
## 接口
|
||
### 显示接口摘要信息
|
||
- 任何模式下执行
|
||
```
|
||
dis ip int brief
|
||
```
|
||
|
||
### 显示接口类型
|
||
- 任何模式下执行
|
||
```
|
||
dis port vlan
|
||
```
|
||
|
||
### 配置接口 IP
|
||
- 系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
ip addr 172.16.1.1 24
|
||
```
|
||
|
||
### 配置接口描述信息
|
||
- 系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
description ...
|
||
```
|
||
|
||
### 配置接口组
|
||
- 系统模式下执行
|
||
```
|
||
port-group g e0/0/2 to e0/0/8
|
||
```
|
||
|
||
### 接口安全
|
||
- 默认只允许一个 mac 地址通信
|
||
- 系统模式下执行
|
||
```
|
||
int gi0/0/1
|
||
port-security enable
|
||
port-security mac-address sticky # 只允许第一次连接的设备上网
|
||
port-security mac-address sticky xxxx-xxxx-xxxx vlan 1 # 只允许指定 mac 的设备上网
|
||
port-security max-mac-num 4 # 允许 4 个不同的 mac 地址通信
|
||
port-security protect-action restrict # 触发安全操作时,交换机接口阻塞并警告
|
||
```
|
||
|
||
### 接口镜像
|
||
- 系统模式下执行
|
||
```
|
||
observe-port 1 int gi0/0/24 # 把 24 口设置为观察口
|
||
int gi0/0/1 # 指定要镜像的接口
|
||
port-mirroring to observe-port 1 both # 把 1 口流量复制到 24 口
|
||
```
|
||
|
||
## Vlan
|
||
- 虚拟局域网(Virtual Local Area Network)
|
||
- 交换机接口默认都在 vlan 1 中,一个接口只能从属于一个 vlan
|
||
- 系统模式下执行
|
||
```
|
||
vlan 10 # 创建 vlan 10
|
||
vlan batch 20 30 40 # 创建 3 个 vlan
|
||
vlan batch 50 to 60 # 创建 10 个 vlan
|
||
```
|
||
|
||
- 把接口划入 vlan 10 中,系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
port link-type access
|
||
port default vlan 10
|
||
```
|
||
|
||
- 显示 vlan 配置,任何模式下执行
|
||
```
|
||
dis vlan
|
||
dis port vlan
|
||
```
|
||
|
||
### 基于 mac 配置 vlan
|
||
- 系统模式下执行
|
||
```
|
||
vlan batch 10 20
|
||
vlan 10
|
||
mac-vlan mac-address xxxx-xxxx-xxxx
|
||
vlan 20
|
||
mac-vlan mac-address yyyy-yyyy-yyyy
|
||
|
||
int gi0/0/1 # 指定每个下连用户的接口
|
||
port hybrid untagged vlan all
|
||
mac-vlan enable
|
||
```
|
||
|
||
- 显示 mac 地址所在 vlan,任何模式下执行
|
||
```
|
||
dis mac-address
|
||
```
|
||
|
||
### 基于 ip 配置 vlan
|
||
- 系统模式下执行
|
||
```
|
||
vlan 10
|
||
ip-subnet-vlan 1 ip 192.168.10.0 255.255.255.0
|
||
vlan 20
|
||
ip-subnet-vlan 1 ip 192.168.20.0 255.255.255.0
|
||
|
||
int gi0/0/1 # 指定每个下连用户的接口
|
||
port hybrid untagged vlan all
|
||
ip-subnet-vlan enable
|
||
```
|
||
|
||
- 显示 ip 地址所在 vlan,任何模式下执行
|
||
```
|
||
dis ip-subnet-vlan
|
||
```
|
||
|
||
### super vlan
|
||
- 各子 vlan 共用超级 vlan 的地址段,且各子 vlan 间网络不通
|
||
- 系统模式下执行
|
||
```
|
||
vlan batch 10 20 30 40 100
|
||
vlan 100
|
||
aggregate-vlan # 定义为聚合 vlan
|
||
access-vlan 10 20 30 # 把 10 20 30 三个 vlan 定义为 vlan 100 的子 vlan
|
||
int vlan 100
|
||
ip addr 192.168.1.1 24 # 聚合 vlan 的接口地址作为各子 vlan 的网关
|
||
```
|
||
|
||
### 接口隔离
|
||
- 同一台交换机相同隔离组的端口不能互访,trunk 接口也可以加入隔离组
|
||
- 系统模式下执行
|
||
```
|
||
vlan 10
|
||
port-group g gi0/0/1 to gi0/0/10
|
||
port link-type access
|
||
port default vlan 10
|
||
int gi0/0/4
|
||
port-isolate enable group 1 # 把接口 4 加入隔离组 1
|
||
int gi0/0/8
|
||
port-isolate enable group 1 # 把接口 8 加入隔离组 1
|
||
```
|
||
|
||
### Vlan 映射
|
||
- 系统模式下执行
|
||
```
|
||
# 出口交换机
|
||
int gi0/0/1
|
||
port link-type trunk
|
||
port trunk allow-pass 100
|
||
|
||
# 内网交换机
|
||
int gi0/0/1
|
||
port link-type trunk
|
||
port trunk allow-pass 100
|
||
qinq vlan-translation enable # 启用 vlan 转换
|
||
port vlan-mapping vlan 10 to 30 map-vlan 100 # 把 vlan 10 到 30 转换成 100
|
||
```
|
||
|
||
### Hybrid 混合接口
|
||
- 华为交换机特有且默认,同时具备 access 和 trunk 功能
|
||
- 作为 access 口使用,系统模式下执行
|
||
```
|
||
int gi0/0/1
|
||
port hybrid pvid vlan 10
|
||
port hybrid untagged vlan 10 # 允许指定的多个 vlan 数据不打 tag 通过
|
||
```
|
||
|
||
- 作为 Trunk 口使用,系统模式下执行
|
||
```
|
||
int gi0/0/2
|
||
port hybrid tagged vlan 10 20
|
||
```
|
||
|
||
### Trunk
|
||
- 允许不同 vlan 的数据通过
|
||
- 系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
port link-type trunk
|
||
port trunk allow-pass vlan all # 允许全部 vlan 数据通过
|
||
```
|
||
|
||
- 本征 vlan(pvid) 经过 trunk 接口时 不打标机,默认本征 vlan 是 1
|
||
- 修改 trunk 接口的本征 vlan,系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
port trunk pvid vlan 20
|
||
```
|
||
|
||
- 重置接口配置,系统模式下执行
|
||
```
|
||
clear configuration interface e0/0/0
|
||
int e0/0/0
|
||
undo shutdown
|
||
```
|
||
|
||
### 链路聚合
|
||
- 多个物理接口捆绑为一个逻辑接口
|
||
- 系统模式下执行
|
||
```
|
||
int eth-trunk 1 # 创建逻辑捆绑接口 1
|
||
int e0/0/1
|
||
eth-trunk 1
|
||
int e0/0/2
|
||
eth-trunk 1
|
||
```
|
||
|
||
- 显示捆绑接口的信息,任何模式下执行
|
||
```
|
||
dis eth-trunk 1
|
||
```
|
||
|
||
- 显示捆绑接口的 stp 状态,任何模式下执行
|
||
```
|
||
dis stp brief
|
||
```
|
||
|
||
### SVI
|
||
- 交换机虚拟接口(Switch Virtual Interface)
|
||
- 系统模式下执行
|
||
```
|
||
interface vlan 10
|
||
ip addr 192.168.1.1 24
|
||
interface vlan 20
|
||
ip addr 192.168.2.1 24
|
||
```
|
||
|
||
## STP
|
||
- 生成树协议(Spanning Tree Protocol),防止交换环路
|
||
- 修改交换机优先级,系统模式下执行
|
||
```
|
||
stp priority 0 # 注意是 4096 倍数
|
||
```
|
||
|
||
- 显示 stp 状态,任何模式下执行
|
||
```
|
||
dis stp
|
||
dis stp brief
|
||
```
|
||
|
||
- 建议连接 PC 的端口配置为边缘端口,系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
stp edged-port enable
|
||
# 可能需要重启下接口
|
||
shutdown
|
||
undo shutdown
|
||
```
|
||
|
||
- stp 根保护,如果收到较小优先级的 BPDU 报文,则完全阻塞,在根桥每个接口的系统模式下执行,__易造成大面积断网,慎用__,推荐使用 bpdu 防护
|
||
```
|
||
int e0/0/1 # 根桥接口
|
||
stp root-protection
|
||
int e0/0/2 # 根桥接口
|
||
stp root-protection
|
||
```
|
||
|
||
- stp bpdu 防护,边缘端口收到 stp 报文时,则将该端口阻塞,在系统模式下执行
|
||
```
|
||
# 先配置好全部边缘端口
|
||
# 开启 stp bpdu 防护
|
||
stp bpdu-protection
|
||
```
|
||
|
||
- stp bpdu 防护每隔 30 秒尝试自动恢复
|
||
```
|
||
error-down auto-recovery cause bpdu-protection interval 30
|
||
```
|
||
|
||
### STP 算法
|
||
- 选举根桥(根交换机),先比较优先级,再比较 MAC 地址,越小越优先
|
||
- 非根桥选出根端口(距离根交换机最近的端口)
|
||
- 其余链路上,优先级或 MAC 地址较大的交换机的端口被阻塞
|
||
|
||
### RSTP
|
||
- 快速 stp,stp 升级版
|
||
- 系统模式下执行
|
||
```
|
||
stp mode rstp
|
||
```
|
||
|
||
### MSTP
|
||
- 多生成树协议
|
||
- 划分实例,不同实例里运行独立的 stp,默认实例都是 0
|
||
- 系统模式下执行
|
||
```
|
||
stp region-configuration
|
||
region-name xxxx
|
||
instance 1 vlan 10 # 把 vlan 10 划分到实例 1 中
|
||
instance 2 vlan 20 30 # 把 vlan 20 和 30 划分到实例 2 中
|
||
active region-configuration # 激活配置
|
||
|
||
# 根据拓扑,登录相应的交换机,调整 stp 优先级
|
||
stp instance 1 priority xxxx
|
||
stp instance 2 priority xxxx
|
||
```
|
||
|
||
- 显示指定实例的 stp 信息,任何模式下执行
|
||
```
|
||
dis stp instance 2
|
||
dis stp instance 2 brief
|
||
```
|
||
|
||
## ACL
|
||
- 访问控制列表(Access Control List),ensp 中AR2220 支持 acl
|
||
- 基本 acl(2000-2999)只能匹配源 ip 地址,系统模式下执行
|
||
```
|
||
acl 2000
|
||
rule 5 deny source 192.168.1.100 0 # 注意最后一个参数是反掩码
|
||
int e0/0/0 # 要调用 acl 的接口
|
||
traffic-filter inbound acl 2000
|
||
```
|
||
|
||
- 高级 acl(3000-3999)可以匹配源 ip、目标 ip、源端口、目标端口和协议等,系统模式下执行
|
||
```
|
||
acl 3000
|
||
rule 5 deny icmp source 192.168.20.0 0.0.0.255 destination 172.16.10.2 0
|
||
int e0/0/1 # 要调用 acl 的接口
|
||
traffic-filter inbound acl 3000
|
||
```
|
||
|
||
- 二层 acl(4000-4999)
|
||
|
||
## 路由器
|
||
- 路由器的每个接口都是单独的网段
|
||
|
||
### 优先级
|
||
路由 | 优先级(0-255)
|
||
---- | ----
|
||
直连 | 0
|
||
静态 | 60
|
||
OSPF | 10
|
||
RIP | 100
|
||
|
||
### 显示路由表
|
||
- 任何模式下执行
|
||
```
|
||
dis ip routing-table
|
||
```
|
||
|
||
### 静态路由
|
||
- 系统模式下执行
|
||
```
|
||
ip route-static 172.16.1.0 24 172.16.2.1 preference 60
|
||
# 目标网段: 172.16.1.0 24
|
||
# 下一跳地址: 172.16.2.1
|
||
# 优先级: 默认 60, prefenence 60
|
||
```
|
||
|
||
### 缺省路由
|
||
- 系统模式下执行
|
||
```
|
||
ip route-static 0.0.0.0 0 172.16.3.1
|
||
```
|
||
|
||
- 备份静态路由与现役静态路由优先级一样时,负载均衡传输
|
||
|
||
### 单臂路由
|
||
- 交换机 e0/0/3 与路由器 e0/0/0 连接
|
||
- 交换机系统模式下执行
|
||
```
|
||
vlan batch 10 20
|
||
int e0/0/1
|
||
port link-type access
|
||
port default vlan 10
|
||
int e0/0/2
|
||
port link-type access
|
||
port default vlan 20
|
||
int e0/0/3
|
||
port link-type trunk
|
||
port trunk allow-pass vlan all
|
||
```
|
||
|
||
- 路由器系统模式下执行
|
||
```
|
||
int e0/0/0.10
|
||
dot1q termination vid 10
|
||
ip addr 192.168.10.1 255.255.255.0
|
||
arp broadcast enable
|
||
int e0/0/0.20
|
||
dot1q termination vid 20
|
||
ip addr 192.168.20.1 255.255.255.0
|
||
arp broadcast enable
|
||
```
|
||
|
||
## RIP
|
||
- 只用跳数作为度量值,16 跳不可达,老旧,目前一般不用
|
||
- 系统模式下执行
|
||
```
|
||
rip 1
|
||
undo summary # 关闭自动汇总
|
||
version 2 # 使用版本 2
|
||
network 192.168.1.0 # 宣告直连主类网络
|
||
network 172.16.0.0 # 宣告直连主类网络
|
||
```
|
||
|
||
- 抑制接口,系统模式下执行
|
||
```
|
||
rip 1
|
||
silent-interface e0/0/0
|
||
```
|
||
|
||
## OSPF
|
||
- 开放式最短路径优先 (Open Shortest Path First)
|
||
- area 0 一般作为骨干区域,area 1、2、3 一般作为常规区域,常规区域__必须__与骨干区域相连
|
||
- 系统模式下执行
|
||
```
|
||
ospf 1
|
||
area 0
|
||
network 192.168.1.0 0.0.0.255 # 注意最后一个参数是反掩码
|
||
network 192.168.2.0 0.0.0.255 # 注意最后一个参数是反掩码
|
||
```
|
||
|
||
- ospf 路由优先级模式是 10,可以修改,系统模式下执行
|
||
```
|
||
ospf 1
|
||
preference 20
|
||
```
|
||
|
||
- 重启 ospf 进程,用户模式下执行
|
||
```
|
||
reset ospf process
|
||
```
|
||
|
||
- 显示 ospf 邻居表,任何模式下执行
|
||
```
|
||
dis ospf peer brief
|
||
```
|
||
|
||
- 显示 ospf 错误,任何模式下执行
|
||
```
|
||
dis ospf error
|
||
```
|
||
|
||
- 重置 ospf 错误计数,用户模式下执行
|
||
```
|
||
reset ospf counters
|
||
```
|
||
|
||
- 显示 ospf 拓扑表(链路状态)
|
||
```
|
||
dis ospf lsdb
|
||
```
|
||
|
||
### ospf 邻居
|
||
- abr(area border router),区域边界路由器
|
||
- asbr(auto-system border router),自治系统边界路由器
|
||
- router id: 运行 ospf 路由器的身份 id,不可重复
|
||
- 优先手动指定,__推荐__
|
||
```
|
||
# 系统模式下执行
|
||
router id 2.2.2.2
|
||
|
||
# 用户模式下执行
|
||
reset ospf process
|
||
```
|
||
|
||
- 最先启动的端口
|
||
|
||
- ospf 常见的五种报文
|
||
- hello: 组播(224.0.0.5),发送自身 router id
|
||
- DBD: 数据库摘要(database description)
|
||
- LSR: 链路状态请求(link-state request),请求某链路的详细路由信息
|
||
- LSU: 链路状态更新(link-state update),回应 LSR
|
||
- LSack: 链路状态确认
|
||
|
||
- ospf 邻居建立过程(从上往下):
|
||
- down
|
||
- init: 初始化,开始交互 hello 报文
|
||
- two-way: 互相得到对方的 router id
|
||
- exstart: 准备交互 DBD 描述报文,同时选举 DR 和 BDR
|
||
- exchange: 交互 DBD 描述报文
|
||
- loading: 加载状态,请求对方完整的明细路由
|
||
- full: 邻居建立完成,双方数据库已同步
|
||
|
||
- DR 和 BDR 选举规则
|
||
- 接口优先级(默认都是 1) + router id,越大越优先
|
||
- 一旦选举完成,后面不会再选举(除非重启),也不会抢占
|
||
- 优先级为 0 表示不参与 DR 和 BDR 选举
|
||
- 修改优先级,系统模式下执行
|
||
```
|
||
int gi0/0/1
|
||
ospf dr-priority 5
|
||
```
|
||
|
||
### ospf 虚链路
|
||
- 新增常规区域没有直连骨干区域,此时该新增区域默认与其他非直连区域网络不通
|
||
- 可以配置虚链路打通新增区域的网络,可以看成区域链路的延伸
|
||
- 系统模式下执行
|
||
```
|
||
# 骨干区域边缘路由
|
||
ospf 1
|
||
area xxxx # 指定所在区域
|
||
vlink-peer x.x.x.x # 指定与新增区域直连的常规区域边缘路由的 router id
|
||
|
||
# 与新增区域直连的常规区域边缘路由
|
||
ospf 1
|
||
area xxxx # 指定区域,去前面一致
|
||
vlink-peer x.x.x.x # 执行骨干区域边缘路由的 router id
|
||
```
|
||
|
||
- 显示 ospf 虚链路,系统模式下执行
|
||
```
|
||
dis ospf vlink
|
||
```
|
||
|
||
### ospf 认证
|
||
- 系统模式下执行
|
||
```
|
||
int gi0/0/1 # 指定 ospf 链路接口
|
||
ospf authentication-mode simple cipher 123456
|
||
```
|
||
|
||
### 抑制接口
|
||
- 系统模式下执行
|
||
```
|
||
ospf 1
|
||
silent-interface e0/0/0
|
||
```
|
||
|
||
### 引入其他路由
|
||
- 引入路由的协议显示为:o_ASE(ospf-autosystem external),默认的路由优先级是 150
|
||
- ospf 和 rip 双向引入,系统模式下执行
|
||
```
|
||
# 把 rip 路由引入 ospf
|
||
ospf 1
|
||
import-route rip
|
||
|
||
# 把 ospf 路由引入 rip
|
||
rip 1
|
||
import-route ospf
|
||
```
|
||
|
||
- 向 ospf 引入缺省路由,此时该路由器会向其他 ospf 区域同步该缺省路由,系统模式下执行
|
||
```
|
||
ospf 1
|
||
default-route-advertise always
|
||
```
|
||
|
||
### 路由汇总
|
||
- 精简路由表大小
|
||
- 在边界路由器(abr)上做路由汇总,系统模式下执行
|
||
```
|
||
ospf 1
|
||
area 1 # 在路由所在区域汇总
|
||
abr-summary 192.168.0.0 255.255.0.0
|
||
```
|
||
|
||
- 在自治系统边界路由器(asbr)上做路由汇总,系统模式下执行
|
||
```
|
||
ospf 1
|
||
asbr-summary 192.168.0.0 255.255.0.0
|
||
```
|
||
|
||
### ospf las
|
||
- 链路状态公告(link state advertise),包含在 LSU 报文中
|
||
- 一类 LSA: router lsa
|
||
- 每个路由器都可以发送
|
||
- 仅在自己区域(area)发送
|
||
- 通告自身信息
|
||
- 任何模式下执行
|
||
```
|
||
dis ospf lsdb router
|
||
```
|
||
|
||
- 二类 LSA: network lsa
|
||
- 只有 DR 可以发送
|
||
- 仅在自己区域(area)发送
|
||
- 通告 DR 的身份和位置
|
||
- 任何模式下执行
|
||
```
|
||
dis ospf lsdb network
|
||
```
|
||
|
||
- 三类 LSA: summary lsa
|
||
- 只有 ABR 可以发送
|
||
- 传送不同区域的 ospf 路由信息
|
||
- 任何模式下执行
|
||
```
|
||
dis ospf lsdb summary
|
||
```
|
||
|
||
- 四类 LSA: asbr lsa
|
||
- 只有 ABR 可以发送
|
||
- 通告 ASBR 的身份和位置
|
||
- 任何模式下执行
|
||
```
|
||
dis ospf lsdb asbr
|
||
```
|
||
|
||
- 五类 LSA: external lsa
|
||
- 只有 ASBR 可以发送
|
||
- 通告其他自治系统的路由信息
|
||
- 任何模式下执行
|
||
```
|
||
dis ospf lsdb ase
|
||
```
|
||
|
||
- 七类 LSA: nssa lsa
|
||
- 只有 nssa 区域的 asbr 产生
|
||
- 只能通告自己所在的 nssa 区域,abr 收到时会转成 5 类继续传递
|
||
- 把与 nssa 直连的其他自治系统的路由引入 ospf
|
||
|
||
### ospf 特殊区域
|
||
- stub,末节区域,拒绝五类 lsa,生成执行 abr 的缺省路由,减少路由表大小,系统模式下执行
|
||
```
|
||
# 该区域的路由器 1
|
||
ospf 1
|
||
area 1 # 指定末节区域
|
||
stub
|
||
|
||
# 该区域的路由器 2
|
||
ospf 1
|
||
area 1 # 指定末节区域
|
||
stub
|
||
```
|
||
|
||
- totally stub,完全末节区域,拒绝三、四、五类 lsa,系统模式下执行
|
||
```
|
||
# 该区域的路由器 1
|
||
ospf 1
|
||
area 1 # 指定末节区域
|
||
stub no-summary
|
||
|
||
# 该区域的路由器 2
|
||
ospf 1
|
||
area 1 # 指定末节区域
|
||
stub no-summary
|
||
```
|
||
|
||
- nssa,not so stub area,拒绝五类 lsa,放行七类 lsa,系统模式下执行
|
||
```
|
||
# 该区域的路由器 1
|
||
ospf 1
|
||
area 1 # 指定 nssa 区域
|
||
nssa
|
||
|
||
# 该区域的路由器 2
|
||
ospf 1
|
||
area 1 # 指定 nssa 区域
|
||
nssa
|
||
```
|
||
|
||
- totally nssa,拒绝三、四、五类 lsa,放行七类 lsa,系统模式下执行
|
||
```
|
||
# 该区域的路由器 1
|
||
ospf 1
|
||
area 1 # 指定 nssa 区域
|
||
nssa no-summary
|
||
|
||
# 该区域的路由器 2
|
||
ospf 1
|
||
area 1 # 指定 nssa 区域
|
||
nssa no-summary
|
||
```
|
||
|
||
### 路由过滤
|
||
- 过滤部分路由,在系统模式下执行
|
||
```
|
||
ospf 1
|
||
filter-policy 2000 import # 使用 acl 2000 过滤引入路由
|
||
|
||
acl 2000
|
||
rule 5 deny source 192.168.1.0 0.0.0.255 # 拒绝 192.168.1.0/24 的路由
|
||
rule 10 permit # 其他路由都放过
|
||
```
|
||
|
||
- ospf 引入其他自治系统的路由信息时,做过滤,在系统模式下执行
|
||
```
|
||
ospf 1
|
||
import-route rip 1 route-policy xxxx
|
||
|
||
route-policy xxxx permit node 10 # 配置路由策略 xxxx 的执行序号是 10
|
||
if-match acl 2001 # 路由策略匹配 acl 2001
|
||
|
||
acl 2001
|
||
rule permit source 192.168.2.0 0.0.0.255 # 允许 ospf 引入 192.168.2.0/24 的路由
|
||
```
|
||
|
||
### ospf 排错
|
||
- ospf 无法建立邻居的几个原因:
|
||
- router id 重复
|
||
- 相邻路由器中间直连的网段必须宣告到相同的区域(area)
|
||
- 认证的类型、密码不一样
|
||
- ospf 邻居间的特殊区域标识必须一致
|
||
|
||
## NAT
|
||
- 一般先在内网接口配置缺省路由
|
||
|
||
### 静态 NAT
|
||
- 一个私网地址映射一个公网地址
|
||
- 系统模式下执行
|
||
```
|
||
int e0/0/1 # 外网接口
|
||
nat static global 12.1.1.2 inside 192.168.31.2
|
||
```
|
||
|
||
- 显示 nat 转化过程,任何模式下执行
|
||
```
|
||
dis nat session protocol icmp # 最后一个参数指定协议
|
||
```
|
||
|
||
### easy IP
|
||
- 多个私网地址转换成一个公网地址
|
||
- 系统模式下执行
|
||
```
|
||
acl 2001 # 创建一个 acl,用于匹配内网地址段
|
||
rule 5 permit source 192.168.31.0 0.0.0.255
|
||
int e0/0/1 # 外网接口
|
||
nat outbound 2001 # 这里的 2001 是 acl 编号
|
||
```
|
||
|
||
### NAT Server
|
||
- 把外网地址的某个端口映射到内网服务器的某个端口
|
||
- 系统模式下执行
|
||
```
|
||
int e0/0/1
|
||
nat server protocol tcp global 12.1.1.2 8080 inside 192.168.31.2 80
|
||
```
|
||
|
||
## VRRP
|
||
- 虚拟路由冗余协议
|
||
- 主从路由器必须使用相同的 vrid,且建议指定优先级和密码
|
||
- 主路由器系统模式下执行
|
||
```
|
||
int e0/0/0 # 内网接口,对应交换机的 vlan 接口
|
||
ip addr 192.168.10.2 24
|
||
vrrp vrid 1 virtual-ip 192.168.10.1
|
||
vrrp vrid 1 priority 105
|
||
vrrp vrid 1 track interface e0/0/1 # 外网接口不可用时,优先级减去 10
|
||
vrrp vrid 1 authentication-mode simple plain 123456
|
||
```
|
||
|
||
- 从路由器系统模式下执行
|
||
```
|
||
int e0/0/0
|
||
ip addr 192.168.10.3 24
|
||
vrrp vrid 1 virtual-ip 192.168.10.1
|
||
vrrp vrid 1 priority 100
|
||
vrrp vrid 1 track interface e0/0/1
|
||
vrrp vrid 1 authentication-mode simple plain 123456
|
||
```
|
||
|
||
- 显示 vrrp 状态,任何模式下执行
|
||
```
|
||
dis vrrp
|
||
dis vrrp brief
|
||
```
|
||
|
||
- 交换机 vrrp 通常与 mstp 配合使用,系统模式下执行
|
||
```
|
||
# 在主交换机上执行
|
||
stp instance 1 root primary
|
||
|
||
# 在从交换机上执行
|
||
stp instance 1 root secondary
|
||
```
|
||
|
||
## BFD
|
||
- 双向转发检测,毫秒级故障检测,实现链路故障快速检查
|
||
- 探测包默认每秒发送一次
|
||
- 系统模式下执行
|
||
```
|
||
# 路由器 1
|
||
bfd
|
||
bfd 1 bind peer-ip 172.16.1.2 source-ip 172.16.1.1
|
||
discriminator local 1
|
||
discriminator remote 2
|
||
commit
|
||
|
||
# 路由器 2
|
||
bfd
|
||
bfd 1 bind peer-ip 172.16.1.1 source-ip 172.16.1.2
|
||
discriminator local 2
|
||
discriminator remote 1
|
||
commit
|
||
```
|
||
|
||
- 静态路由调用 bfd,系统模式下执行
|
||
```
|
||
# 路由器 1
|
||
ip route-s 192.168.2.0 255.255.255.0 172.16.1.2 track bfd-session 1
|
||
|
||
# 路由器 2
|
||
ip route-s 192.168.3.0 255.255.255.0 172.16.1.1 track bfd-session 1
|
||
```
|
||
|
||
- ospf 调用 bfd,系统模式下执行
|
||
```
|
||
# 路由器 1
|
||
ospf 1
|
||
bfd all-interface enable
|
||
|
||
# 路由器 2
|
||
ospf 1
|
||
bfd all-interface enable
|
||
```
|
||
|
||
- 查看 bfd 状态,任何模式下执行
|
||
```
|
||
dis bfd session all
|
||
```
|
||
|
||
## DHCP/BOOTP
|
||
- 系统模式下执行
|
||
```
|
||
dhcp enable
|
||
ip pool pool_1
|
||
network 192.168.1.0 mask 24
|
||
gateway-list 192.168.1.1
|
||
dns-list 192.168.1.1 8.8.8.8
|
||
static-bind ip-address 192.168.1.101 mac-address xxxx-xxxx-xxxx # ip 与 mac 绑定
|
||
lease day 0 hour 12 # 租期 12 小时
|
||
excluded-ip-address 192.168.1.200 192.168.1.254 # 200-254 之间的 ip 不自动分配
|
||
int e0/0/0 # 对应交换机的 vlan 接口
|
||
ip addr 192.168.1.1 24
|
||
dhcp select global
|
||
```
|
||
|
||
- 租期 50% 时,客户端发送 dhcp request,要求续租
|
||
- 如果服务端未响应,客户端会在 87.5% 时再发送一次
|
||
- 显示地址池中已用地址,任何模式下执行
|
||
```
|
||
dip ip pool
|
||
dis ip pool name pool_1 used
|
||
```
|
||
|
||
- 重置地址池分配记录,用户模式下执行
|
||
```
|
||
reset ip pool name pool_1 used
|
||
```
|
||
|
||
- 基于当前接口分配 ip,简单便捷,系统模式下执行
|
||
```
|
||
dhcp enable
|
||
int gi0/0/0 # 对应交换机的 vlan 接口
|
||
ip addr 192.168.1.1 255.255.255.0
|
||
dhcp select interface
|
||
dhcp server dns-list 192.168.1.1 8.8.8.8
|
||
```
|
||
|
||
- 基于 dhcp 中继分配 ip,系统模式下执行
|
||
```
|
||
dhcp enable
|
||
int gi0/0/0 # 对应交换机的 vlan 接口
|
||
ip address 192.168.1.1 24
|
||
dhcp select relay
|
||
dhcp relay server-ip 192.168.254.2 # 其他 dhcp 服务器
|
||
```
|
||
|
||
- 启用 dhcp snooping,不接收指定 vlan 下所有接口的 dhcp offer
|
||
```
|
||
dhcp enable
|
||
dhcp snooping enable
|
||
dhcp snooping enable vlan 1 # 指定 snooping 生效的 vlan
|
||
int gi0/0/0 # 指定要信任的 dhcp 接口
|
||
dhcp snooping trusted
|
||
```
|
||
|
||
## Telnet
|
||
- 系统模式下执行
|
||
```
|
||
telnet server enable
|
||
aaa
|
||
local-user user_1 password cipher 123456 privilege level 3
|
||
local-user user_1 service-type telnet
|
||
user-interface vty 0 4 # 同时允许 5 个人远程登录
|
||
authentication-mode aaa
|
||
```
|
||
|
||
- 连接远程路由器,用户模式下执行
|
||
```
|
||
telnet 192.168.3.1
|
||
```
|
||
|
||
## FTP
|
||
- 系统模式下执行
|
||
```
|
||
ftp server enable
|
||
aaa
|
||
local-user user_2 password cipher 123456 privilege level 3 ftp-directory flash:
|
||
local-user service-type ftp
|
||
```
|
||
|
||
## SSH
|
||
- 系统模式下执行
|
||
```
|
||
aaa
|
||
local-user user_3 password cipher 123456 privilege level 3
|
||
local-user user_3 service-type ssh
|
||
user-interface vty 0 4
|
||
authentication-mode aaa
|
||
protocol inbound ssh
|
||
stelnet server enable
|
||
```
|
||
|
||
## 广域网传输
|
||
### PPP
|
||
- 远距离点对点串口传输(Point to Point Protocol)
|
||
- 系统模式下执行
|
||
```
|
||
int serial4/0/0
|
||
link-protocol ppp
|
||
ip addr 12.1.1.2 255.255.255.0
|
||
```
|
||
|
||
#### PAP 认证
|
||
- 明文传输
|
||
- 服务端系统模式下执行
|
||
```
|
||
aaa
|
||
local-user user_3 password cipher 123456
|
||
local-user user_3 service-type ppp
|
||
int serial4/0/0
|
||
ppp authentication-mode pap
|
||
```
|
||
|
||
- 客户端系统模式下执行
|
||
```
|
||
int s4/0/0
|
||
ppp pap local-user user_3 password simple 123456
|
||
shutdown
|
||
undo shutdown
|
||
```
|
||
|
||
#### CHAP 认证
|
||
- 密文传输
|
||
- 服务端系统模式下执行
|
||
```
|
||
aaa
|
||
local-user user_4 password cipher 123456
|
||
local-user user_4 service-type ppp
|
||
int s4/0/0
|
||
ppp authentication-mode chap
|
||
```
|
||
|
||
- 客户端系统模式下执行
|
||
```
|
||
int s4/0/0
|
||
ppp chap user user_4
|
||
ppp chap password simple 123456
|
||
shutdown
|
||
undo shutdown
|
||
```
|
||
|
||
### HDLC
|
||
- 系统模式下执行
|
||
```
|
||
int s4/0/1
|
||
link-protocol hdlc
|
||
ip addr ...
|
||
```
|
||
|
||
### FR
|
||
- 系统模式下执行
|
||
```
|
||
int s4/0/1
|
||
link-protocol fr
|
||
ip addr ...
|
||
```
|
||
|
||
## IPV6
|
||
- 系统模式下执行
|
||
```
|
||
ipv6
|
||
int e0/0/0
|
||
ipv6 enable
|
||
ipv6 addr 2001::2 64
|
||
```
|
||
|
||
- 单播和组播与 ipv4 类似,无广播
|
||
- 无状态自动配置,无需 dhcp
|
||
- 以 FE80:: 开头的地址都是本地链路地址,只在本地链路有效
|
||
- EUI-64 地址: 原 mac 地址中间嵌入 FFFE,第七个 bit 取反
|
||
|
||
## 园区网络
|
||
- 500-1000 设备
|
||
- 路由器/防火墙: 配置缺省路由和 nat 连接外网
|
||
- 核心层交换机: 配置 vlan,svi 和 dhcp,作为网关
|
||
- 接入层交换机: 配置 vlan,划分用户接入接口
|
||
- 核心层 trunk 连接接入层
|
||
- 核心层单独 vlan 接口连接路由器
|
||
- 核心层交换机配置缺省路由,把外网流量都转给路由器
|
||
- 路由器配置静态路由,把内网流量转给核心层交换机
|
||
|
||
- 所有交换机建议配置管理 vlan
|
||
```
|
||
# 核心交换机
|
||
vlan 999
|
||
int vlan 999
|
||
ip addr 192.168.255.1 24
|
||
|
||
# 其他交换机
|
||
vlan 999
|
||
int vlan 999
|
||
ip addr 192.168.255.xxx 24
|
||
ip route-static 0.0.0.0 0 192.168.255.1
|
||
```
|
||
|
||
- 1000 以上设备,接入层 - 汇聚层 - 核心层 - 路由器/防火墙 - 外网
|
||
- 路由器/防火墙: 配置缺省路由和 nat 连接外网
|
||
- 核心层交换机: 配置 vlan,svi 和 dhcp,作为网关
|
||
- 汇聚层交换机: 配置 vlan
|
||
- 接入层交换机: 配置 vlan,划分用户接入接口
|
||
- 核心层 trunk 连接汇聚层
|
||
- 汇聚层 trunk 连接接入层
|
||
- 核心层单独 vlan 接口连接路由器
|
||
- 核心层交换机配置缺省路由,把外网流量都转给路由器
|
||
- 路由器与核心层交换机配置 ospf
|
||
|
||
- 所有交换机建议配置管理 vlan
|
||
|