Technical documentation
发布日期:2023-09-19 浏览次数:1394 来源:WOLF-LAB赵顺杰
CCNA、CCNP培训中理解路由的简单入门-直连,主机,静态路由的书写方式
CCNA、CCNP培训,思科认证企业基础架构课程路由的简单入门-直连路由,主机路由,静态路由
思科认证CCNA、CCNP、CCIE课程咨询联系WOLF-LAB网络技术实验室
一.CCNA、CCNP培训什么是路由
路由:寻址,意在指出当路由器从某一个接口收到数据包时,拆开数据包的二层信息,查看数据包三层信息当中的目的IP地址,去查询路由器设备当中维护的路由表项,根据路由表项当中匹配的条目,找到去往目的地址对应的下一跳或出接口,将数据包往对应方向转发出去.
二.CCNA、CCNP培训路由器如何转发数据包
1. 拆开二层看三层
2. 查询路由表,遵循最长匹配,递归查询的原则
3. 如果有路由,找到下一跳,出接口
4. 重新封装二层
5. 将数据包从出接口转发出去.
三.CCNA、CCNP培训路由条目的分类
主机路由/本地路由:
一旦接口UP,链路UP,并且接口上配置了相应的IPv4地址,那么就会自动产生一条/32位掩码的主机路由/本地路由插入进路由表.此路由能够使得路由器完成本设备接口地址的互访,并且能够有效的防环.此路由无法宣告进入任何动态路由协议.
直连路由:
一旦接口UP,链路UP,并且接口上配置了相应的IPv4地址,那么就会自动产生一条与接口地址所属子网相同的路由条目插入进路由表,此路由能够使得路由器完成直连链路的互相访问.
R1配置:
R1(config)#interface g0/0
R1(config-if)#no shutdown
R1(config-if)#ip address 172.16.12.1 255.255.255.0
R2配置:
R2(config)#interface g0/0
R2(config-if)#no shutdown
R2(config-if)#ip address 172.16.12.1 255.255.255.0
R2(config)#interface g0/1
R2(config-if)#no shutdown
R2(config-if)#ip address 192.168.23.2 255.255.255.0
R3配置:
R3(config)#interface g0/1
R3(config-if)#no shutdown
R3(config-if)#ip address 192.168.23.3 255.255.255.0
R1路由表:
R1#show ip route
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.12.0/24 is directly connected, GigabitEthernet0/0
L 172.16.12.1/32 is directly connected, GigabitEthernet0/0
R1#
R2路由表:
R2#show ip route
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.12.0/24 is directly connected, GigabitEthernet0/0
L 172.16.12.2/32 is directly connected, GigabitEthernet0/0
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, GigabitEthernet0/1
L 192.168.23.2/32 is directly connected, GigabitEthernet0/1
R2#
R3路由表:
R3#show ip route
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, GigabitEthernet0/1
L 192.168.23.3/32 is directly connected, GigabitEthernet0/1
R1访问R2
R1#ping 172.16.12.2
Sending 5, 100-byte ICMP Echos to 172.16.12.2, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 2/2/3 ms
访问172.16.12.2,路由器将会查询路由表项当中的条目,找到去往目的IP地址能够匹配的路由条目.
例如,此时在R1的路由表当中拥有去往172.16.12.0/24关联在G0/0接口的直连路由,而这个子网 当中包含了172.16.12.1-172.16.12.254主机地址,我们访问的172.16.12.2的主机地址被包含在了其中,因此我们的这个目的地址能够匹配上路由表里面的这条路由,按照出接口是G0/0接口将数据包转发出去!.
静态路由:
默认情况下路由器里面能够自动产生的只有因配置接口地址产生的直连路由,而它只能够解决路由器直连网段的访问,并不能解决方位非直连网段访问.
而为了让路由器能够访问非直连网段,我们便可以通过手工插入的方式往路由表当中安置路由条目.而这便是直连路由.
静态路由跟出接口
R1配置:
R1(config)#ip route 192.168.23.0 255.255.255.0 g0/0
R3配置:
R3(config)#ip route 172.16.12.0 255.255.255.0 g0/1
R1路由表:
R1#show ip route
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.12.0/24 is directly connected, GigabitEthernet0/0
L 172.16.12.1/32 is directly connected, GigabitEthernet0/0
S 192.168.23.0/24 is directly connected, GigabitEthernet0/0
R2路由表:
R2#show ip route
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.12.0/24 is directly connected, GigabitEthernet0/0
L 172.16.12.2/32 is directly connected, GigabitEthernet0/0
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, GigabitEthernet0/1
L 192.168.23.2/32 is directly connected, GigabitEthernet0/1
R3路由表:
R3#show ip route
172.16.0.0/24 is subnetted, 1 subnets
S 172.16.12.0 is directly connected, GigabitEthernet0/1
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, GigabitEthernet0/1
L 192.168.23.3/32 is directly connected, GigabitEthernet0/1
R1访问R3:
R1# ping 192.168.23.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
.!!!!
R1的ARP表
R1#show arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 172.16.12.1 - 5000.0001.0000 ARPA GigabitEthernet0/0
Internet 172.16.12.2 15 5000.0002.0000 ARPA GigabitEthernet0/0
Internet 192.168.23.3 2 5000.0002.0000 ARPA GigabitEthernet0/0
当使用静态路由配置跟出接口的时候会发现R1学习到192.168.23.3的MAC地址为R2的G0/0接口的MAC地址.
当使用静态路由跟出接口时,设备发出的ARP请求的对象将会是访问的目的地址,但是由于路由器隔离广播组播的机制,下一跳路由器发现请求的不是自己的MAC地址,不会转发此广播数据包给我们访问的目的地址,按道理应当是我们ARP请求失败无法获取mac地址的,但是在设备当中有名为代理ARP的机制
代理ARP:
当收到ARP请求时发现请求的不是自己接口的mac地址,将会去查询路由表,若是自己有去往此ARP请求对象地址的路由时,将会代替目的地址回复ARP Reply,使得发送方得以封装自己的mac地址将数据包发给自己,然后自己完成后续转发.
因此,若是没有代理ARP的机制的话R1将不会收到任何ARP Reply,不能够封装成功数据包并转发.譬如华为的设备默认就是关闭代理ARP的.因此,这种能否访问都只能看下一跳是否开启代理ARP情况,这种受制于人的情况太惨了(笑).所以静态路由跟出接口的方式虽可以,但不是最好的.
静态路由跟下一跳地址
R1(config)#no ip route 192.168.23.0 255.255.255.0 g0/0
R3(config)#no ip route 172.16.12.0 255.255.255.0 g0/1
R1配置:
R1(config)#ip route 192.168.23.0 255.255.255.0 172.16.12.2
R3配置:
R3(config)#ip route 172.16.12.0 255.255.255.0 192.168.23.2
R1路由表
R1#show ip route
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.12.0/24 is directly connected, GigabitEthernet0/0
L 172.16.12.1/32 is directly connected, GigabitEthernet0/0
S 192.168.23.0/24 [1/0] via 172.16.12.2
R2路由表
R2#show ip route
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.12.0/24 is directly connected, GigabitEthernet0/0
L 172.16.12.2/32 is directly connected, GigabitEthernet0/0
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, GigabitEthernet0/1
L 192.168.23.2/32 is directly connected, GigabitEthernet0/1
R3路由表
R3#show ip route
172.16.0.0/24 is subnetted, 1 subnets
S 172.16.12.0 [1/0] via 192.168.23.2
192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.23.0/24 is directly connected, GigabitEthernet0/1
L 192.168.23.3/32 is directly connected, GigabitEthernet0/1
R1访问R3:
R1# ping 192.168.23.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
!!!!!
R1#show arp
Protocol Address Age (min) Hardware Addr Type Interface
Internet 172.16.12.1 - 5000.0001.0000 ARPA GigabitEthernet0/0
Internet 172.16.12.2 31 5000.0002.0000 ARPA GigabitEthernet0/0
当静态路由跟下一跳时,ARP请求的将不再是目的ip地址所对应的MAC,而是静态路由下一跳的IP地址对应的MAC地址,当静态路由跟下一跳时,可以使得路由器明确直到去往目的ip地址的下一跳路由器是谁,于是直接封装下一跳的MAC地址,直接将数据流量交给下一跳路由器并完成后续转发.
WOLFLAB官方微信:17316362402
WOLFLAB官方QQ:2569790740
CCNA、CCNP培训企业基础架构课程学习联系WOLF-LAB实验室