OSI/RM 网络的参考的模型,将网络分为七层:应用层 表示层 会话层 传输层 网络层 数链层 物理层
高层:应用层 表示层 会话层
低层:物理层 数链层 网络层
高层面向于应用,低层面向于通信
网络建设的思路从低向高考虑,数据的传输过程从高向低考虑。

TCP/IP体系架构,将网络分为四层:应用层 传输层(TCP层)网络层(IP层)网络接口层
网络接口层:V.35 RS232 ETHERNET PPP HDLC FRAME-RELAY ATM
ethernet(以太网):采用了CSMA/CD机制来避免冲突的一种局域网技术
标准的以太网:10M的以太网,早期是HUB连网,后来交换机连接
高速的交换式以太网:100M以上的以太网,采用交换机连接。
IP层:IP ARP/RARP ICMP
IP协议的功能:编址/寻址
IP V4地址的格式:32位二进制,用点分十进制表示。
地址的组成:网络部分+主机部分
子网掩码:连续的“1”标识网络位,用连续的“0”标识主机位
IP地址的分类:A,1-126   B, 128-191    C, 192-223
子网划分:将大的网络划分成更多更小的网络,分割更大的网络,提高地址的利用率。
例:一个公司获得一个C类的地址段,如192.168.1.0/24,现在公司有五个部门,每个部门最多需要30台主机,如何规划地址?
   分析需求:>=5个网段 <=30台主机
   准备知识:2的N次方>=网段需求    子网掩码:128 192 224 240 248 252 254 255
计算:1、 2的N次方>=5====》n=3=====>子网掩码长度24+3=27,255.255.255.224==》△=256-224=32 
      2、 192.168.1.0 --192.168.1.32--192.168.1.64--192.168.1.96--192.168.1.128--192.168.1.160--192.168.1.192--192.168.1.224

  172.16.0.0/16 ==》 172.16.0.0/19,255.255.224.0
   172.16.64.0:172.16.64.0--172.16.65.0....172.16.95.0-172.16.95.255
   172.16.96.0

ARP协议:将IP地址解析成MAC地址的协议。
RARP协议:将MAC地址解析成IP地址。例DHCP的过程
ICMP协议:测试网络连通性。例 PING

TCP层:TCP UDP
TCP协议,面向连接的可靠传输协议,三次握手机制、确认机制、滑动窗口机制
UDP协议,面向无连接的不可靠的协议

应用层:http dns telnet smtp pop snmp

路由器和交换机
1、路由器的硬件结构:CPU 存储器(RAM,ROM,NVRAM,FLASH)接口
 ROM:boot strap   miniIOS
 RAM:running-config
 NVRAM:startup-config
 flash:IOS
 接口:ethernet fast-ethernet serial bri
2、路由器的启动的过程:
   开机自检,装载启动时的引导代码(ROM)----解压、装载IOS(flash\rom\network)---解压、装载配置文件startup-config--->running-config
 
注:寄存器的值:0X2102/0X2142   最后一个字段是引导字段,“2”表示从FLASH启动倒数第二个字段是配置文件调用的字段,“0X2102”表示调用NVRAM中的startup-config文件;“0X2142”表示不调startup-config
修改寄存器的值的命令:
    在全局配置模式下输入(config)#config-register 0x2102
    在维修模式下输入 rommon>confreg 0x2102
                     rommon>reset
 
3、路由器和交换机的区别:A、硬件结构上,路由器接口丰富 ;交换机接口单一,但是接口数量多
                         B、路由器是低速设备,通过软件生成路由表转发数据;交换机是高速设备,通过硬件快速转发,以MAC地址为转发依据。
                         C、数由器分割广播域和冲突域,交换机默认只分割冲突域。
 
路由
路由的概念:1、寻找最佳路径的过程
            2、最佳路径
路由的类型:
1、直连路由,当路由器的接口打开且配置了IP地址时,路由器就会添加关于接口所在网段的路由信息,且根据这样的路由信息来转发数据。
2、静态路由,由管理员手工指定到达目标网段所要经过的路径,包含目标(未知)网段、子网掩码、下一跳IP地址
3、默认路由,特殊的静态路由,但是优先级最低。用于未知网段只有一个出口的网络结构。
4、动态路由,由路由协议根据算法自动学习得到的关于目标网段的路径。

例:静态路由的配置与调试
  
R1
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r1
ena pass cisco
ena secret huayu
interface f1/0
ip add 192.168.1.1 255.255.255.0
no sh
interface s0/0
ip add 192.168.2.1 255.255.255.0
no sh
ip route 0.0.0.0 0.0.0.0 192.168.2.2
 
 

R2
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r2
ena pass cisco
ena secret huayu
interface s0/1
ip add 192.168.3.1 255.255.255.0
no sh
interface s0/0
ip add 192.168.2.2 255.255.255.0
no sh
ip route 192.168.1.0 255.255.255.0 192.168.2.1
ip route 192.168.4.0 255.255.255.0 192.168.3.2

PC
1
ip 192.168.1.2 192.168.1.1 24
2
ip 192.168.4.2 192.168.4.1 24
 
 
 
动态路由
动态路由的分类:
距离矢量路由协议,周期性的向邻居广播或组播路由表的备份来更新路由;RIP IGRP
链路状态协议,通过收集全网的接口状态,然后再通过自己的算法算出路由表; OSPF IS-IS
混合路由,结合二者的优点,是思科专有; EIGRP
routing protocol,路由选择协议,RIP IGRP OSPF EIGRP
routed protocol,可路由协议,IP IPX

RIP(routing information protocol,路由信息协议)
version 1
基本特点:1、属于距离矢量路由协议 2、度量:以跳数,最大15跳 3、周期性广播(30S,255.255.255.255)4、有类路由(classful routing protocol)
路由表的形成过程:网络中的路由器在更新周期到达时向邻居发送自己路由表的备份,邻居接收到信息对自己的路由表,将未知或更优的路由条目添加到自己的路由表中,且跳数在原有的基础要增加1。
 
R1
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r1
ena pass cisco
ena secret huayu
interface s0/0
ip add 192.168.1.1 255.255.255.252
no sh
interface loopback 0
ip address 1.1.1.1 255.255.255.0
router rip
network 192.168.1.0
network 1.1.1.0
 
 
R2
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r2
ena pass cisco
ena secret huayu
interface s0/0
ip add 192.168.1.2 255.255.255.252
no sh
interface s0/1
ip add 192.168.1.5 255.255.255.252
no sh
router rip
network 192.168.1.4
network 192.168.1.0
 
 
R3
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r3
ena pass cisco
ena secret huayu

interface s0/1
ip add 192.168.1.6 255.255.255.252
no sh
interface l0
ip add 3.3.3.3 255.255.255.0
no sh
router rip
network 192.168.1.4
network 3.3.3.0
*show 静态的查看路由器运行的结果
 debug动态的查看路由器正在运行的过程
###################################################
r2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
R    1.0.0.0/8 [120/1] via 192.168.1.1, 00:00:28, Serial0/0
R    3.0.0.0/8 [120/1] via 192.168.1.6, 00:00:26, Serial0/1
     192.168.1.0/30 is subnetted, 2 subnets
C       192.168.1.0 is directly connected, Serial0/0
C       192.168.1.4 is directly connected, Serial0/1
 

r2#debug ip rip events
RIP event debugging is on
r2#
*Mar  1 00:18:53.939: RIP: sending v1 update to 255.255.255.255 via Serial0/1 (192.168.1.5)
*Mar  1 00:18:53.939: RIP: Update contains 2 routes
*Mar  1 00:18:53.939: RIP: Update queued
*Mar  1 00:18:53.943: RIP: Update sent via Serial0/1
r2#
*Mar  1 00:18:55.215: RIP: received v1 update from 192.168.1.1 on Serial0/0
*Mar  1 00:18:55.215: RIP: Update contains 1 routes
r2#
*Mar  1 00:18:57.223: RIP: received v1 update from 192.168.1.6 on Serial0/1
*Mar  1 00:18:57.223: RIP: Update contains 1 routes
r2#
*Mar  1 00:19:07.943: RIP: sending v1 update to 255.255.255.255 via Serial0/0 (192.168.1.2)
*Mar  1 00:19:07.943: RIP: Update contains 2 routes
*Mar  1 00:19:07.943: RIP: Update queued
*Mar  1 00:19:07.947: RIP: Update sent via Serial0/0
r2#
*Mar  1 00:19:22.715: RIP: received v1 update from 192.168.1.1 on Serial0/0
*Mar  1 00:19:22.715: RIP: Update contains 1 routes
r2#
*Mar  1 00:19:23.795: RIP: sending v1 update to 255.255.255.255 via Serial0/1 (192.168.1.5)
*Mar  1 00:19:23.795: RIP: Update contains 2 routes
*Mar  1 00:19:23.795: RIP: Update queued
*Mar  1 00:19:23.799: RIP: Update sent via Serial0/1
r2#
*Mar  1 00:19:25.779: RIP: received v1 update from 192.168.1.6 on Serial0/1
*Mar  1 00:19:25.779: RIP: Update contains 1 routes
r2#
*Mar  1 00:19:35.635: RIP: sending v1 update to 255.255.255.255 via Serial0/0 (192.168.1.2)
*Mar  1 00:19:35.635: RIP: Update contains 2 routes
*Mar  1 00:19:35.635: RIP: Update queued
*Mar  1 00:19:35.639: RIP: Update sent via Serial0/0

r2#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
R    1.0.0.0/8 [120/1] via 192.168.1.1, 00:00:22, Serial0/0
R    3.0.0.0/8 is possibly down, routing via 192.168.1.6, Serial0/1
     192.168.1.0/30 is subnetted, 2 subnets
C       192.168.1.0 is directly connected, Serial0/0
C       192.168.1.4 is directly connected, Serial0/1
 
路由环路
收敛:网络中所有路由器具有全网络的路由,且信息达到一致的状态。
路由环路的产生:周期性的广播及从邻居的接口返回自己更新的路由。
解决办法:1、触发更新 2、抑制计时器
3、水平分割 ip split-horizon 4、路由毒化 5、毒性反转
6、定义最大跳(RIP 16跳)
被动接口(passive)只接收路由的更新,不从该接口广播路由出去。
单播更新,只向某个邻居更新路由,指定要更新的邻居(neighbor)
r1
ena
config t
no ip do lo
line console 0
logg syn
no exec-time
host r1
interface f0/0
no sh
ip add 192.168.1.1 255.255.255.0
interface l0
ip add 1.1.1.1 255.255.255.0
no sh
router rip
passive-interface f0/0
network 1.1.1.0
network 192.168.1.0
 
 
未开启被动接口时
r1#   show ip route
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
R    2.0.0.0/8 [120/1] via 192.168.1.2, 00:00:02, FastEthernet0/0
R    3.0.0.0/8 [120/1] via 192.168.1.3, 00:00:13, FastEthernet0/0
C    192.168.1.0/24 is directly connected, FastEthernet0/0
R1#debug ip rip events
Mar  1 00:07:15.727: RIP: sending v1 update to 255.255.255.255 via FastEthernet0/0 (192.168.1.1)
*Mar  1 00:07:15.727: RIP: Update contains 1 routes
*Mar  1 00:07:15.727: RIP: Update queued
*Mar  1 00:07:15.731: RIP: Update sent via FastEthernet0/0
r1#
*Mar  1 00:07:22.615: RIP: received v1 update from 192.168.1.3 on FastEthernet0/0
*Mar  1 00:07:22.619: RIP: Update contains 1 routes
r1#
*Mar  1 00:07:28.111: RIP: sending v1 update to 255.255.255.255 via Loopback0 (1.1.1.1)
*Mar  1 00:07:28.111: RIP: Update contains 3 routes
*Mar  1 00:07:28.111: RIP: Update queued
*Mar  1 00:07:28.115: RIP: Update sent via Loopback0
r1#
*Mar  1 00:07:33.975: RIP: received v1 update from 192.168.1.2 on FastEthernet0/0
*Mar  1 00:07:33.975: RIP: Update contains 1 routes

开启被动接口和单播更新
r1(config-router)#passive-interface f0/0
*Mar  1 00:11:20.927: RIP: received v1 update from 192.168.1.2 on FastEthernet0/0
*Mar  1 00:11:20.927: RIP: Update contains 1 routes
r1(config-router)#
*Mar  1 00:11:31.243: RIP: received v1 update from 192.168.1.3 on FastEthernet0/0
*Mar  1 00:11:31.243: RIP: Update contains 1 routes

r1(config-router)#neighbor 192.168.1.2
*Mar  1 00:13:35.743: RIP: sending v1 update to 192.168.1.2 via FastEthernet0/0 (192.168.1.1)
*Mar  1 00:13:35.743: RIP: Update contains 1 routes
*Mar  1 00:13:35.743: RIP: Update queued
*Mar  1 00:13:35.747: RIP: Update sent via FastEthernet0/0
r3#show ip route
R    2.0.0.0/8 [120/1] via 192.168.1.2, 00:00:15, FastEthernet0/0
     3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
C    192.168.1.0/24 is directly connected, FastEthernet0/0
 
r1#show ip route
    1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
R    2.0.0.0/8 [120/1] via 192.168.1.2, 00:00:02, FastEthernet0/0
R    3.0.0.0/8 [120/1] via 192.168.1.3, 00:00:19, FastEthernet0/0
C    192.168.1.0/24 is directly connected, FastEthernet0/0
 
version 2
基本特点:1、属于距离矢量路由协议 2、度量:以跳数,最大15跳 3、周期性组播(30S,224.0.0.9)4、无类路由(classless routing protocol)5、支持认证功能
R1
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r1
ena pass cisco
ena secret huayu

interface s0/0
ip add 192.168.1.1 255.255.255.252
no sh
interface l0
ip add 1.1.1.1 255.255.255.0
no sh
router rip
network 192.168.1.0
network 1.1.1.0
 
R2
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r2
ena pass cisco
ena secret huayu

interface s0/0
ip add 192.168.1.2 255.255.255.252
no sh
interface s0/1
ip add 192.168.1.5 255.255.255.252
no sh
interface s0/2
ip add 192.168.1.9 255.255.255.252
no sh

interface l0
ip add 2.2.2.2 255.255.255.0
no sh
router rip
network 192.168.1.0
network 2.2.2.0
router rip
version 2
network 192.168.1.4
network 192.168.1.8
R3
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r3
ena pass cisco
ena secret huayu

interface s0/1
ip add 192.168.1.6 255.255.255.252
no sh
interface l0
ip add 3.3.3.3 255.255.255.0
no sh
router rip
version 2
network 192.168.1.4
network 3.3.3.0

r4
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r4
ena pass cisco
ena secret huayu

interface s0/2
ip add 192.168.1.10 255.255.255.252
no sh
interface l0
ip add 4.4.4.4 255.255.255.0
no sh
router rip
version 2
network 192.168.1.8
network 4.4.4.0

r1#
*Mar  1 00:08:40.103: RIP: sending v1 update to 255.255.255.255 via Serial0/0 (192.168.1.1)
*Mar  1 00:08:40.103: RIP: Update contains 1 routes
*Mar  1 00:08:40.103: RIP: Update queued
*Mar  1 00:08:40.103: RIP: Update sent via Serial0/0
r1#
*Mar  1 00:08:54.551: RIP: received v2 update from 192.168.1.2 on Serial0/0
*Mar  1 00:08:54.555: RIP: Update contains 5 routes
r1#show ip route
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
R    2.0.0.0/8 [120/1] via 192.168.1.2, 00:00:10, Serial0/0
R    3.0.0.0/8 [120/1] via 192.168.1.2, 00:00:10, Serial0/0
R    4.0.0.0/8 [120/1] via 192.168.1.2, 00:00:10, Serial0/0
     192.168.1.0/30 is subnetted, 3 subnets
R       192.168.1.8 [120/1] via 192.168.1.2, 00:00:10, Serial0/0
C       192.168.1.0 is directly connected, Serial0/0
R       192.168.1.4 [120/1] via 192.168.1.2, 00:00:10, Serial0/0
r1#show ip pro
Routing Protocol is "rip"
    Interface             Send  Recv  Triggered RIP  Key-chain
    Serial0/0             1     1 2                                
    Loopback0             1     1 2                                
r2(config-router)#
*Mar  1 00:07:44.875: RIP: ignored v1 packet from 192.168.1.1 (illegal version)

r2#show ip route
       2.0.0.0/24 is subnetted, 1 subnets
C       2.2.2.0 is directly connected, Loopback0
R    3.0.0.0/8 [120/1] via 192.168.1.6, 00:00:04, Serial0/1
R    4.0.0.0/8 [120/1] via 192.168.1.10, 00:00:18, Serial0/2
     192.168.1.0/30 is subnetted, 3 subnets
C       192.168.1.8 is directly connected, Serial0/2
C       192.168.1.0 is directly connected, Serial0/0
C       192.168.1.4 is directly connected, Serial0/1
r2#show ip pro
Routing Protocol is "rip"
    Interface             Send  Recv  Triggered RIP  Key-chain
    Serial0/0             2     2                                  
    Serial0/1             2     2                                  
    Serial0/2             2     2                                  
    Loopback0             2     2 

解决办法:
r2(config)#interface s0/0
r2(config-if)#ip rip receive version 1
*边界自动汇总(auto-summary):当经过子网划分的地址通告到网络的边界是,会自动汇总成主有类网络。
 
RIP V2 认证功能
R1
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r1
ena pass cisco
ena secret huayu

interface s0/0
ip add 192.168.1.1 255.255.255.252
no sh
interface l0
ip add 1.1.1.1 255.255.255.0
no sh
router rip
network 192.168.1.0
network 1.1.1.0
 
R2
ena
config t
no ip domain-lookup
line console 0
pass cisco
login
logg syn
no exec-timeout

line vty 0 1
pass cisco
login
hostname r2
ena pass cisco
ena secret huayu
key chain huayu
key 1
key-string cisco1234
interface s0/0
ip add 192.168.1.2 255.255.255.252
no sh
interface s0/1
ip add 192.168.1.5 255.255.255.252
no sh
ip rip authentication key-chain huayu 明文验证,只要KEY-STRING内容相同,即验证通过!
interface s0/2
ip add 192.168.1.9 255.255.255.252
no sh
ip rip authentication key-chain hauyu
ip rip authentication mode md5密文验证,需要所有的内容相同,验证才能通过!
interface l0
ip add 2.2.2.2 255.255.255.0
no sh
router rip
network 192.168.1.0
network 2.2.2.0
router rip
version 2
network 192.168.1.4
network 192.168.1.8