0
点赞
收藏
分享

微信扫一扫

运维之基础网络篇-----4. 包格式及IP地址 、 网络层协议及路由器


         上帝是个无耻的老赌徒,他抛弃了我们

                                                                           ——刘慈欣


一、 IP数据包格式

优先级与服务类型(8位):优先级与服务类型

标识符、标志、段偏移量这几个字段用来对数据包进行标识,使数据到达目的端重组的时候,不会乱序 

首部长度:ip包头首部长度最短20字节

总长度(16):

协议号: UDP是17,TCP是6

首部校验和:

TTL:生命周期字段,经过一个路由器TTL值减1,为0时,数据包丢弃。为了防止一个数据包在网络中无限的循环下去。


二、 IP地址

1、 IP地址的组成

网络位+主机位

2、 ip地址的分类

 

A类 网+主+主+主

B类 网+网+主+主

C类 网+网+网+主

3、 默认子网掩码

子网掩码用于区分IP的网络位及主机位,网络位用连续的1表示,主机位用连续0

4、网络ID

网络位的IP地址不变,主机位用连续的0表示

5、 广播地址

IP 地址的广播地址计算:网络位的IP不变,主机位用连续的1表示。

IP地址的广播地址:为IP地址网段的最后一个地址(即该网段的最大值)

6、 可用主机IP个数的计算

2主机位次方-2

三、 子网划分

四、网络层 协议

1、ARP协议

将一个已知的IP地址解析成MAC地址

Windows系统中的ARP  -a:查看ARP缓存表 

2、RARP协议

MAC地址解析为IP地址

3、代理ARP

IP地址解析为网关接口的MAC地址

4、ICMP

Internet 控制消息协议

1)连接建立成功:

Reply from 192.168.1.1:bytes=32 time<1ms TTL=128

2)目标主机不可达:

Destination  host  unreachable.

3)请求时间超时:

Request  timed  out.

5)未知主机名:

Unknown  host  abc.

Ping 命令的常用参数:

Ping  -t 一直ping

Ping  -a 可以返回对方主机名

Ping  -l修改ping包大小,默认32字节



三、路由器原理及静态路由

1、路由

跨越从源主机到目标主机的一个互联网络来转发数据包的过程

2、路由表

路由器根据路由表做路径选择

3、路由表的获得

1)、直连路由:配置IP地址,端口UP状态,形成直连路由。

2)、非直连网段:需要静态路由或动态路由,将网段添加到路由表中。

4、静态路由

1)、特点:

由管理员手工配置的,是单向的,因此需要在两个网络之间的边缘路由器上需要双方对指,否则就会造成流量有去无回,缺乏灵活性,适用于小型网络。

2)、配置

全局模式:

ip  route  目标网络ID  子网掩码  下一跳IP



1 案例1:配置静态路由

1.1 问题

配置路由接口IP地址并通过静态路由的配置实现全网的互通。

1.2 方案

按如下网络拓扑配置接口IP地址并通过静态路由的配置实现全网的互通如图-1所示:


图-1

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:配置静态路由

1)R1上配置接口IP

​R1(config)#interface fastEthernet 0/0​​​​R1(config-if)#ip address 192.168.1.254 255.255.255.0​​​​R1(config-if)#no shutdown ​​​​R1(config-if)#exit​​​​R1(config)#interface fastEthernet 0/1​​​​R1(config-if)#ip address 192.168.2.1 255.255.255.0​​​​R1(config-if)#no shutdown​​​​2)R2上配置接口IP​


  1. R2(config)#interface fastEthernet 0/1
  2. R2(config-if)#ip address 192.168.2.2 255.255.255.0
  3. R2(config-if)#no shutdown
  4. R2config-if)#exit
  5. R2(config)#interface fastEthernet 0/0
  6. R2(config-if)#ip address 192.168.4.254 255.255.255.0
  7. R2(config-if)#no shutdown

3)R1上添加静态路由

​R1(config)#ip route 192.168.4.0 255.255.255.0 192.168.2.2​​​​4)R1上查看路由表​


  1. R1#show ip route
  2. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -
  3. - EIGRP, EX - EIGRP external, O - OSPF, IA -
  4. - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  5. - OSPF external type 1, E2 - OSPF external type 2, E -
  6. - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  7. * - candidate default, U - per-user static route, o -
  8. - periodic downloaded static
  9. Gateway of last resort is not set
  10. C 192.168.1.0/24 is directly connected, FastEthernet0/0
  11. C 192.168.2.0/24 is directly connected, FastEthernet0/1
  12. S 192.168.4.0/24 [1/0] via 192.168.2.2 //S表示静态路由

5)R2上添加静态路由

​R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1​​​​6)R2上查看路由条目​


  1. R2#show ip route
  2. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -
  3. - EIGRP, EX - EIGRP external, O - OSPF, IA -
  4. - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  5. - OSPF external type 1, E2 - OSPF external type 2, E -
  6. - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  7. * - candidate default, U - per-user static route, o -
  8. - periodic downloaded static
  9. Gateway of last resort is not set
  10. S 192.168.1.0/24 [1/0] via 192.168.2.1 //S表示静态路由
  11. C 192.168.2.0/24 is directly connected, FastEthernet0/1
  12. C 192.168.3.0/24 is directly connected, FastEthernet0/0

7)配置PC1的IP地址为192.168.1.1,网关为192.168.1.254

8)配置PC2的IP地址为192.168.4.1,网关为192.168.4.254

9)测试网络连通性,PC1 ping 192.168.4.1

​PC>ping 192.168.4.1​​​​Pinging 192.168.4.1 with 32 bytes of data:​​​​Reply from 192.168.4.1: bytes=32 time=1ms TTL=126​​​​Reply from 192.168.4.1: bytes=32 time=11ms TTL=126​​​​Reply from 192.168.4.1: bytes=32 time=10ms TTL=126​​​​Reply from 192.168.4.1: bytes=32 time=11ms TTL=126​​​​Ping statistics for 192.168.4.1:​​​​: Sent = 4, Received = 4, Lost = 0 (0% loss),​​​​Approximate round trip times in milli-seconds:​​​​= 1ms, Maximum = 11ms, Average =​​​3)、浮动路由配置浮动静态路由,需设置管理距离大于1,从而成为备份路由,实现链路冗余的作用。 2 案例2:配置浮动路由2.1 问题配置浮动静态路由2.2 方案按如下网络拓扑配置接口IP地址配置浮动路由实现链路的冗余,如图-2所示 图-22.3 步骤实现此案例需要按照如下步骤进行。步骤一:配置静态路由并添加模块1)R1上配置接口IP在以上静态路由实验的基础上,先分别进入R1与R2的特权模式输入write命令保存配置信息,然后分别进入R1与R2的物理配置界面,点击开关按钮关闭路由器,添加NM-1FE-TX模块并再次点击开关按钮,如下图-3所示。 图-32)添加模块后将R1的F1/0接口连接到R2的F1/0接口修改拓扑如下图-4所示: 图-43)配置R1的F1/0接口IP​​​​​​​​ R1(config)#interface fastEthernet 1/0R1(config-if)#ip address 192.168.3.1 255.255.255.0R1(config-if)#no shutdown ​

4)配置R2的F1/0接口IP

​R2(config)#interface fastEthernet 1/0​​​​R2(config-if)#ip address 192.168.3.2 255.255.255.0​​​​R2(config-if)#no shutdown​​​​5)R1上添加静态浮动路由​


  1. R1(config)#ip route 192.168.4.0 255.255.255.0 192.168.3.2 50 //管理距离50

6)R2上添加静态浮动路由

​R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.3.1 50 //管理距离50​​​​7)R1上查看路由表​


  1. R1#show ip route
  2. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -
  3. - EIGRP, EX - EIGRP external, O - OSPF, IA -
  4. - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  5. - OSPF external type 1, E2 - OSPF external type 2, E -
  6. - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  7. * - candidate default, U - per-user static route, o -
  8. - periodic downloaded static
  9. Gateway of last resort is not set
  10. C 192.168.1.0/24 is directly connected, FastEthernet0/0
  11. C 192.168.2.0/24 is directly connected, FastEthernet0/1
  12. C 192.168.3.0/24 is directly connected, FastEthernet1/0
  13. S 192.168.4.0/24 [1/0] via 192.168.2.2 //只有下一跳为192.168.2.2的静态路由

8)禁用F/01接口

​R1(config)#interface fastEthernet 0/1​​​​R1(config-if)#shutdown​​​​9)R1上查看路由表​


  1. C 192.168.1.0/24 is directly connected, FastEthernet0/0
  2. S 192.168.4.0/24 [50/0] via 192.168.3.2//下一跳接口为192.168.4.2的路由生效
  3. C 192.168.4.0/24 is directly connected, FastEthernet1/0

10)测试网络连通性,PC1 ping 192.168.4.1

​PC>ping 192.168.4.1​​​​Pinging 192.168.4.1 with 32 bytes of data:​​​​Reply from 192.168.4.1: bytes=32 time=0ms TTL=126​​​​Reply from 192.168.4.1: bytes=32 time=10ms TTL=126​​​​Reply from 192.168.4.1: bytes=32 time=11ms TTL=126​​​​Reply from 192.168.4.1: bytes=32 time=1ms TTL=126​​​​Ping statistics for 192.168.4.1:​​​​: Sent = 4, Received = 4, Lost = 0 (0% loss),​​​​Approximate round trip times in milli-seconds:​​​​= 0ms, Maximum = 11ms, Average =​

3 案例3:配置多路由的静态路由

​3.1 问题配置多路由的静态路由3.2 方案网络环境及IP地址规划,如图-5所示 图-5 3.3 步骤实现此案例需要按照如下步骤进行。步骤一:配置路由IP和静态路由1) R1上配置接口IP​​​​​​​​ Router(config)#interface fastEthernet 0/0R1(config-if)#ip address 192.168.1.254 255.255.255.0R1(config-if)#no shutdown R1(config-if)#exitR1(config)#interface fastEthernet 0/1R1(config-if)#ip address 192.168.2.1 255.255.255.0R1(config-if)#no shutdown​

2)R2上配置接口IP


​R2(config)#interface f0/1​​​​R2(config-if)#ip address 192.168.2.2 255.255.255.0​​​​R2(config-if)#no shutdown ​​​​R2(config-if)#exit​​​​R2(config)#interface fastEthernet 0/0​​​​R2(config-if)#ip address 192.168.3.1 255.255.255.0​​​​R2(config-if)#no shutdown​​​​3)R3上配置接口IP​​​​​​​​ R3(config)#interface fastEthernet 0/1R3(config-if)#ip address 192.168.3.2 255.255.255.0R3(config-if)#no shutdown R3(config-if)#exitR3(config)#interface fastEthernet 0/0R3(config-if)#ip address 192.168.4.254 255.255.255.0R3(config-if)#no shutdown​

4)R1、R2、R3上分别添加静态路由


​R1(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.2​​​​R1(config)#ip route 192.168.4.0 255.255.255.0 192.168.2.2​​​​R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1​​​​R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.3.2​​​​R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.3.1​​​​R3(config)#ip route 192.168.2.0 255.255.255.0 192.168.3.1​​​​5)R1上查看路由表​​​​​​​​ R1#show ip route Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -- EIGRP, EX - EIGRP external, O - OSPF, IA -- OSPF NSSA external type 1, N2 - OSPF NSSA external type 2- OSPF external type 1, E2 - OSPF external type 2, E -- IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area* - candidate default, U - per-user static route, o -- periodic downloaded staticGateway of last resort is not setC 192.168.1.0/24 is directly connected, FastEthernet0/0C 192.168.2.0/24 is directly connected, FastEthernet0/1S 192.168.3.0/24 [1/0] via 192.168.2.2 //静态路由S 192.168.4.0/24 [1/0] via 192.168.2.2 //静态路由​

6)R2上查看路由表


​R2#show ip route ​​​​Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -​​​​- EIGRP, EX - EIGRP external, O - OSPF, IA -​​​​- OSPF NSSA external type 1, N2 - OSPF NSSA external type 2​​​​- OSPF external type 1, E2 - OSPF external type 2, E -​​​​- IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area​​​​* - candidate default, U - per-user static route, o -​​​​- periodic downloaded static​​​​Gateway of last resort is not set​​​​S 192.168.1.0/24 [1/0] via 192.168.2.1 //静态路由​​​​C 192.168.2.0/24 is directly connected, FastEthernet0/1​​​​C 192.168.3.0/24 is directly connected, FastEthernet0/0​​​​S 192.168.4.0/24 [1/0] via 192.168.3.2 //静态路由​​​​7)R3上查看路由表​​​​​​​​ R3#show ip route Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -- EIGRP, EX - EIGRP external, O - OSPF, IA -- OSPF NSSA external type 1, N2 - OSPF NSSA external type 2- OSPF external type 1, E2 - OSPF external type 2, E -- IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area* - candidate default, U - per-user static route, o -- periodic downloaded staticGateway of last resort is not setS 192.168.1.0/24 [1/0] via 192.168.3.1 //静态路由S 192.168.2.0/24 [1/0] via 192.168.3.1 //静态路由C 192.168.3.0/24 is directly connected, FastEthernet0/1C 192.168.4.0/24 is directly connected, FastEthernet0/0​

8)按图-4配置PC的IP地址

9)测试网络连通性,PC1 ping 192.168.2.2、192.168.3.1、192.168.3.2、192.168.4.1

​PC>ping 192.168.2.2 //ping 192.168.2.2​​​​Pinging 192.168.2.2 with 32 bytes of data:​​​​Reply from 192.168.2.2: bytes=32 time=0ms TTL=254​​​​Reply from 192.168.2.2: bytes=32 time=0ms TTL=254​​​​Reply from 192.168.2.2: bytes=32 time=0ms TTL=254​​​​Reply from 192.168.2.2: bytes=32 time=0ms TTL=254​​​​Ping statistics for 192.168.2.2:​​​​: Sent = 4, Received = 4, Lost = 0 (0% loss),​​​​Approximate round trip times in milli-seconds:​​​​= 0ms, Maximum = 0ms, Average =​​​​PC>ping 192.168.3.1 //ping 192.168.3.1​​​​Pinging 192.168.3.1 with 32 bytes of data:​​​​Reply from 192.168.3.1: bytes=32 time=0ms TTL=254​​​​Reply from 192.168.3.1: bytes=32 time=3ms TTL=254​​​​Reply from 192.168.3.1: bytes=32 time=0ms TTL=254​​​​Reply from 192.168.3.1: bytes=32 time=0ms TTL=254​​​​Ping statistics for 192.168.3.1:​​​​: Sent = 4, Received = 4, Lost = 0 (0% loss),​​​​Approximate round trip times in milli-seconds:​​​​= 0ms, Maximum = 3ms, Average =​​​​PC>ping 192.168.3.2 //ping 192.168.3.2​​​​Pinging 192.168.3.2 with 32 bytes of data:​​​​Reply from 192.168.3.2: bytes=32 time=0ms TTL=253​​​​Reply from 192.168.3.2: bytes=32 time=12ms TTL=253​​​​Reply from 192.168.3.2: bytes=32 time=0ms TTL=253​​​​Reply from 192.168.3.2: bytes=32 time=12ms TTL=253​​​​Ping statistics for 192.168.3.2:​​​​: Sent = 4, Received = 4, Lost = 0 (0% loss),​​​​Approximate round trip times in milli-seconds:​​​​= 0ms, Maximum = 12ms, Average =​​​​PC>ping 192.168.4.1 //ping 192.168.4.1​​​​Pinging 192.168.4.1 with 32 bytes of data:​​​​Reply from 192.168.4.1: bytes=32 time=0ms TTL=125​​​​Reply from 192.168.4.1: bytes=32 time=10ms TTL=125​​​​Reply from 192.168.4.1: bytes=32 time=0ms TTL=125​​​​Reply from 192.168.4.1: bytes=32 time=22ms TTL=125​​​​Ping statistics for 192.168.4.1:​​​​: Sent = 4, Received = 4, Lost = 0 (0% loss),​​​​Approximate round trip times in milli-seconds:​​​​= 0ms, Maximum = 22ms, Average =​​​
 六、缺省路由(默认路由)缺省路由是一种特殊的静态路由简单地说,缺省路由就是在没有找到任何匹配的具体路由条目的情况下才使用的路由,适用于只有一个出口的末节网络,优先级最低,可以做为其他路由的补充。全局:ip  route  0.0.0.0  0.0.0.0  下一跳代表任意网络ID 案例4:配置默认路由4.1 问题配置默认路由4.2 方案网络环境及IP地址规划,如图-6所示 图-64.3 步骤1)在案例3基础上删除R1与R3的静态路由​
​​​​​​​ R1(config)#no ip route 192.168.3.0 255.255.255.0 192.168.2.2R1(config)#no ip route 192.168.4.0 255.255.255.0 192.168.2.2R3(config)#no ip route 192.168.1.0 255.255.255.0 192.168.3.1R3(config)#no ip route 192.168.2.0 255.255.255.0 192.168.3.1​

2)R1、R3添加默认路由

​R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.2​​​​R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.1​​​​12)R1上查看路由表​​​​R1#show ip route ​​​​Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -​​​​- EIGRP, EX - EIGRP external, O - OSPF, IA -​​​​- OSPF NSSA external type 1, N2 - OSPF NSSA external type 2​​​​- OSPF external type 1, E2 - OSPF external type 2, E -​​​​- IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area​​​​* - candidate default, U - per-user static route, o -​​​​- periodic downloaded static​​​​Gateway of last resort is 192.168.2.2 to network 0.0.0.0​​​​C 192.168.1.0/24 is directly connected, FastEthernet0/0​​​​C 192.168.2.0/24 is directly connected, FastEthernet0/1​​​​S* 0.0.0.0/0 [1/0] via 192.168.2.2 //默认路由​​​​3)R1、R3上查看路由表​


  1. R1#show ip route
  2. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -
  3. - EIGRP, EX - EIGRP external, O - OSPF, IA -
  4. - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  5. - OSPF external type 1, E2 - OSPF external type 2, E -
  6. - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  7. * - candidate default, U - per-user static route, o -
  8. - periodic downloaded static
  9. Gateway of last resort is 192.168.3.1 to network 0.0.0.0
  10. C 192.168.1.0/24 is directly connected, FastEthernet0/0
  11. C 192.168.2.0/24 is directly connected, FastEthernet0/1
  12. S* 0.0.0.0/0 [1/0] via 192.168.2.2 //默认路由

  13. R3#show ip route
  14. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B -
  15. - EIGRP, EX - EIGRP external, O - OSPF, IA -
  16. - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  17. - OSPF external type 1, E2 - OSPF external type 2, E -
  18. - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  19. * - candidate default, U - per-user static route, o -
  20. - periodic downloaded static
  21. Gateway of last resort is 192.168.3.1 to network 0.0.0.0
  22. C 192.168.3.0/24 is directly connected, FastEthernet0/1
  23. C 192.168.4.0/24 is directly connected, FastEthernet0/0
  24. S* 0.0.0.0/0 [1/0] via 192.168.3.1 //默认路由

4)测试网络连通性,PC1 ping 192.168.4.1


  1. PC>ping 192.168.4.1
  2. Pinging 192.168.4.1 with 32 bytes of data:
  3. Reply from 192.168.4.1: bytes=32 time=1ms TTL=125
  4. Reply from 192.168.4.1: bytes=32 time=0ms TTL=125
  5. Reply from 192.168.4.1: bytes=32 time=14ms TTL=125
  6. Reply from 192.168.4.1: bytes=32 time=14ms TTL=125
  7. Ping statistics for 192.168.4.1:
  8. : Sent = 4, Received = 4, Lost = 0 (0% loss),
  9. Approximate round trip times in milli-seconds:
  10. = 0ms, Maximum = 14ms, Average = 7ms = 0ms,平均 =

七、查看路由表

特权:show  ip  route

C直连路由

S静态路由

S*默认路由

R 通过RIP协议形成的动态路由条目

举报

相关推荐

0 条评论