大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
一、首先了解一下数据转发过程中路由器的工作原理
路由器的工作原理:
(1)解封装:此处解封装的前提是目的mac地址是自己才能解封装
(2)根据目的ip查路由表转发数据。 查看路由表的命令:[Huawei]display ip routing-table
此处分两种情况:
情况1:如果目的ip在路由表中,则会把数据转发到相应的出接口
情况2:如果目的ip不在路由表中,则把数据丢了就可以了
二、搭建好拓扑图
拓扑图如下:
图中我已经标好了每个接口以及主机的ip地址等
按图所示搭建完拓扑图后我们开始配置ip地址,
首先对于PC主机来说,PC主机获取ip地址的方法主要有两种:
1 、手工配置 | 2、DHCP动态主机配置 |
---|
这里我们直接使用第一个手工配置的方法,
具体操作如下:
我们双击PC1,然后在中间IPv4这里直接输入ip地址、子网掩码和网关
注意:配置好地址后一定不要忘记点击右下角的“应用”,否则配置无法保存。
PC2以及PC3的配置方式同理PC1。
接下来我们配置路由器的接口ip地址:
双击路由器R1:输入sys回车
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]
[Huawei]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 10.1.1.254 24
[Huawei-Ethernet0/0/0]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 10.1.2.254 24
[Huawei-Ethernet0/0/1]interface g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 12.1.1.1 24
双击路由器R2:
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 12.1.1.2 24
[Huawei-Ethernet0/0/1]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 10.1.3.254 24
此时我们测试一下R1、R2直连路由的连通性:发现是连通的。
[Huawei]ping 12.1.1.2
PING 12.1.1.2: 56 data bytes, press CTRL_C to break
Reply from 12.1.1.2: bytes=56 Sequence=1 ttl=255 time=70 ms
Reply from 12.1.1.2: bytes=56 Sequence=2 ttl=255 time=40 ms
Reply from 12.1.1.2: bytes=56 Sequence=3 ttl=255 time=50 ms
Reply from 12.1.1.2: bytes=56 Sequence=4 ttl=255 time=50 ms
Reply from 12.1.1.2: bytes=56 Sequence=5 ttl=255 time=50 ms
--- 12.1.1.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 40/52/70 ms
有了直连路由可以ping通的基础后,我们来建立静态路由(Static)
静态配置:[Huawei]ip route-static 目的网段 掩码 出接口 下一跳
注意:
下一跳地址:如果是以太网链路,g或者e开头的,出接口和下一跳地址必须加;
如果是s开头的串行线,可以不指定下一跳。
在路由器R1上:
[Huawei]ip route-static 10.1.3.0 24 g0/0/0 12.1.1.2
在R1上“去”的有了,那么在R2上“回”的也得有:
[Huawei]ip route-static 10.1.1.0 24 e0/0/1 12.1.1.1
查看R1上的路由表信息:
[Huawei]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 9 Routes : 9
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.1.1.0/24 Direct 0 0 D 10.1.1.254 Ethernet0/0/0
10.1.1.254/32 Direct 0 0 D 127.0.0.1 Ethernet0/0/0
10.1.2.0/24 Direct 0 0 D 10.1.2.254 Ethernet0/0/1
10.1.2.254/32 Direct 0 0 D 127.0.0.1 Ethernet0/0/1
10.1.3.0/24 Static 60 0 D 12.1.1.2 GigabitEthernet
0/0/0
12.1.1.0/24 Direct 0 0 D 12.1.1.1 GigabitEthernet
0/0/0
12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
配置完成以后,我们在PC1上ping一下PC3看是否连通:
PC>ping 10.1.3.1
Ping 10.1.3.1: 32 data bytes, Press Ctrl_C to break
From 10.1.3.1: bytes=32 seq=1 ttl=126 time=79 ms
From 10.1.3.1: bytes=32 seq=2 ttl=126 time=46 ms
From 10.1.3.1: bytes=32 seq=3 ttl=126 time=79 ms
From 10.1.3.1: bytes=32 seq=4 ttl=126 time=46 ms
From 10.1.3.1: bytes=32 seq=5 ttl=126 time=94 ms
--- 10.1.3.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 46/68/94 ms
结果是可以ping通的,说明PC1实现了对PC3 的通信,也就是我们静态路由协议配置成功。
我们来补充一点知识(了解一下):
如何获取非直连网段的路由?
1、静态配置:静态路由static 60(优先级值)
2、动态路由协议:OSPF 10,RIP 100 ,BGP 255,ISIS 15
(1)最长掩码匹配
10.1.3.1
10.1.3.1/24
10.1.3.1/28(最先匹配这个)
(2)路由协议优先级:本着越小越优先的原则
(3)度量值:越小越优先
三、下面我们来分析一个稍微复杂一点的拓扑结构,目的是实现主机PC4、PC5和PC6之间的通信
1、搭建好拓扑图
首先我们配置好每个路由器的各个接口的ip地址,步骤如同第一个拓扑图的配置。
在R3上:
[Huawei]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 172.16.1.254 24
[Huawei-Ethernet0/0/0]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 45.1.1.1 24
在R4上:
[Huawei]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 45.1.1.2 24
[Huawei]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 56.1.1.1 24
在R5上:
[Huawei]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 56.1.1.2 24
[Huawei]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 67.1.1.1 24
[Huawei-Ethernet0/0/1]interface g0/0/0
[Huawei-GigabitEthernet0/0/0]ip address 172.16.2.254 24
在R6上:
[Huawei]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 67.1.1.2 24
[Huawei]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 78.1.1.1 24
在R7上:
[Huawei]interface e0/0/0
[Huawei-Ethernet0/0/0]ip address 78.1.1.2 24
[Huawei]interface e0/0/1
[Huawei-Ethernet0/0/1]ip address 172.16.3.254 24
配置好ip地址后,先测试一下直连路由的连通性:
例如:在R7上测试和R6的连通性:
[Huawei]ping 78.1.1.1
PING 78.1.1.1: 56 data bytes, press CTRL_C to break
Reply from 78.1.1.1: bytes=56 Sequence=1 ttl=255 time=40 ms
Reply from 78.1.1.1: bytes=56 Sequence=2 ttl=255 time=50 ms
Reply from 78.1.1.1: bytes=56 Sequence=3 ttl=255 time=50 ms
Reply from 78.1.1.1: bytes=56 Sequence=4 ttl=255 time=50 ms
Reply from 78.1.1.1: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 78.1.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/42/50 ms
接下来我们开始配置静态路由:
在R3上:
[Huawei]ip route-static 172.16.3.0 24 e0/0/1 45.1.1.2
[Huawei]ip route-static 172.16.2.0 24 e0/0/1 45.1.1.2
在R4上:
[Huawei]ip route-static 172.16.3.0 24 e0/0/1 56.1.1.2
[Huawei]ip route-static 172.16.1.0 24 e0/0/0 45.1.1.1
[Huawei]ip route-static 172.16.2.0 24 e0/0/1 56.1.1.2
在R5上:
[Huawei]ip route-static 172.16.3.0 24 e0/0/1 67.1.1.2
[Huawei]ip route-static 172.16.1.0 24 e0/0/0 56.1.1.1
在R6上:
[Huawei]ip route-static 172.16.3.0 24 e0/0/1 78.1.1.2
[Huawei]ip route-static 172.16.1.0 24 e0/0/0 67.1.1.1
[Huawei]ip route-static 172.16.2.0 24 e0/0/0 67.1.1.1
在R7上:
[Huawei]ip route-static 172.16.1.0 24 e0/0/0 78.1.1.1
[Huawei]ip route-static 172.16.2.0 24 e0/0/0 78.1.1.1
在R5上查看路由表(随便哪一个路由器都可以):
接下来我们PC4、PC5和PC6之间的连通性:
在PC4上:
PC>ping 172.16.2.1
Ping 172.16.2.1: 32 data bytes, Press Ctrl_C to break
From 172.16.2.1: bytes=32 seq=1 ttl=125 time=78 ms
From 172.16.2.1: bytes=32 seq=2 ttl=125 time=78 ms
From 172.16.2.1: bytes=32 seq=3 ttl=125 time=94 ms
From 172.16.2.1: bytes=32 seq=4 ttl=125 time=110 ms
From 172.16.2.1: bytes=32 seq=5 ttl=125 time=93 ms
--- 172.16.2.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/90/110 ms
PC>ping 172.16.3.1
Ping 172.16.3.1: 32 data bytes, Press Ctrl_C to break
From 172.16.3.1: bytes=32 seq=1 ttl=123 time=141 ms
From 172.16.3.1: bytes=32 seq=2 ttl=123 time=140 ms
From 172.16.3.1: bytes=32 seq=3 ttl=123 time=110 ms
From 172.16.3.1: bytes=32 seq=4 ttl=123 time=140 ms
From 172.16.3.1: bytes=32 seq=5 ttl=123 time=157 ms
--- 172.16.3.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 110/137/157 ms
在PC5上:
PC>ping 172.16.1.1
Ping 172.16.1.1: 32 data bytes, Press Ctrl_C to break
From 172.16.1.1: bytes=32 seq=1 ttl=125 time=94 ms
From 172.16.1.1: bytes=32 seq=2 ttl=125 time=78 ms
From 172.16.1.1: bytes=32 seq=3 ttl=125 time=94 ms
From 172.16.1.1: bytes=32 seq=4 ttl=125 time=109 ms
From 172.16.1.1: bytes=32 seq=5 ttl=125 time=110 ms
--- 172.16.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/97/110 ms
PC>ping 172.16.3.1
Ping 172.16.3.1: 32 data bytes, Press Ctrl_C to break
From 172.16.3.1: bytes=32 seq=1 ttl=125 time=94 ms
From 172.16.3.1: bytes=32 seq=2 ttl=125 time=109 ms
From 172.16.3.1: bytes=32 seq=3 ttl=125 time=62 ms
From 172.16.3.1: bytes=32 seq=4 ttl=125 time=79 ms
From 172.16.3.1: bytes=32 seq=5 ttl=125 time=78 ms
--- 172.16.3.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 62/84/109 ms
在PC6上:
PC>ping 172.16.1.1
Ping 172.16.1.1: 32 data bytes, Press Ctrl_C to break
From 172.16.1.1: bytes=32 seq=1 ttl=123 time=125 ms
From 172.16.1.1: bytes=32 seq=2 ttl=123 time=156 ms
From 172.16.1.1: bytes=32 seq=3 ttl=123 time=125 ms
From 172.16.1.1: bytes=32 seq=4 ttl=123 time=110 ms
From 172.16.1.1: bytes=32 seq=5 ttl=123 time=187 ms
--- 172.16.1.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 110/140/187 ms
PC>ping 172.16.2.1
Ping 172.16.2.1: 32 data bytes, Press Ctrl_C to break
From 172.16.2.1: bytes=32 seq=1 ttl=125 time=78 ms
From 172.16.2.1: bytes=32 seq=2 ttl=125 time=94 ms
From 172.16.2.1: bytes=32 seq=3 ttl=125 time=94 ms
From 172.16.2.1: bytes=32 seq=4 ttl=125 time=109 ms
From 172.16.2.1: bytes=32 seq=5 ttl=125 time=94 ms
--- 172.16.2.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/93/109 ms
PC4、PC5和PC6之间可以相互通信,配置完毕。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/189749.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...