• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
jinxin-love
博客园    首页    新随笔    联系   管理    订阅  订阅

实验-静态路由-cnblog

实验-静态路由

拓扑图:

image-20251021102615558

配置需求:

1.如图所示,配置各路由器设备名称,IP地址。
2.如图所示,配置各PC的IP地址、掩码、网关。
3.在R1 R2 R3 R4上配置静态路由,完成以下需求:
1)路由的目标网络号与实际网络号相同
2)采用下一跳的方式配置静态路由(而非出接口)
3)PC1 PC2 PC3互通
4)不得使用默认路由

配置命令:

配置各路由器设备名称,IP地址。

R1 配置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R1
[R1]int g0/0/0 
[R1-GigabitEthernet0/0/0]ip ad 192.168.12.1 24
Oct 21 2025 10:33:04-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R1-GigabitEthernet0/0/0]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 192.168.12.1 255.255.255.0 
#
return
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip ad 172.16.1.254 24 
Oct 21 2025 10:33:27-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R1-GigabitEthernet0/0/1]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/1
 ip address 172.16.1.254 255.255.255.0 
#
return
[R1-GigabitEthernet0/0/1]q
[R1]dis th
[V200R003C00]
#
 sysname R1
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
return

R2 配置:

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R2
[R2]int g0/0/0       
[R2-GigabitEthernet0/0/0]ip ad 
[R2-GigabitEthernet0/0/0]ip address 192.168.12.2 24 
Oct 21 2025 10:34:32-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R2-GigabitEthernet0/0/0]int g 
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip ad 192.168.23.2 24
[R2-GigabitEthernet0/0/1]
Oct 21 2025 10:34:54-08:00 R2 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R2-GigabitEthernet0/0/1]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/1
 ip address 192.168.23.2 255.255.255.0 
#
return
[R2-GigabitEthernet0/0/1]int g0/0/0           
[R2-GigabitEthernet0/0/0]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 192.168.12.2 255.255.255.0 
#
return
[R2-GigabitEthernet0/0/0]q
[R2]dis th
[V200R003C00]
#
 sysname R2
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
return

R3 配置:

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R3
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip ad 192.168.23.3 24
Oct 21 2025 10:36:09-08:00 R3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R3-GigabitEthernet0/0/0]int g0/0/1
[R3-GigabitEthernet0/0/1]ip ad 192.168.34.3 24
Oct 21 2025 10:36:27-08:00 R3 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R3-GigabitEthernet0/0/1]
[R3-GigabitEthernet0/0/1]int g0/0/2
[R3-GigabitEthernet0/0/2]ip ad 172.16.2.254 24
[R3-GigabitEthernet0/0/2]
Oct 21 2025 10:36:40-08:00 R3 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP on the interface GigabitEthernet0/0/2 has entered the UP state. 
[R3-GigabitEthernet0/0/2]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/2
 ip address 172.16.2.254 255.255.255.0 
#
return
[R3-GigabitEthernet0/0/2]int g0/0/1           
[R3-GigabitEthernet0/0/1]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/1
 ip address 192.168.34.3 255.255.255.0 
#
return
[R3-GigabitEthernet0/0/1]int g0/0/0
[R3-GigabitEthernet0/0/0]dis th    
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 192.168.23.3 255.255.255.0 
#
return
[R3-GigabitEthernet0/0/0]
[R3]dis th
[V200R003C00]
#
 sysname R3
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
return

R4 配置:

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys R4
[R4]
[R4]int g0/0/0 
[R4-GigabitEthernet0/0/0]ip ad 192.168.34.4 24
Oct 21 2025 10:37:21-08:00 R4 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R4-GigabitEthernet0/0/0]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 192.168.34.4 255.255.255.0 
#
return
[R4-GigabitEthernet0/0/0]int g0/0/1 
[R4-GigabitEthernet0/0/1]ip ad 172.16.3.254 24
Oct 21 2025 10:37:32-08:00 R4 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R4-GigabitEthernet0/0/1]dis th
[V200R003C00]
#
interface GigabitEthernet0/0/1
 ip address 172.16.3.254 255.255.255.0 
#
return
[R4-GigabitEthernet0/0/1]q
[R4]dis th
[V200R003C00]
#
 sysname R4
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
return

路由器配置完成

配置各PC的IP地址、掩码、网关。

PC1 配置:

image-20251021103848524

PC2 配置:

image-20251021103900276

PC3 配置:

image-20251021103911383

PC 配置完成

配置静态路由,使得PC之间互通

首先,检查接口配置是否正确

R1 接口配置:

<R1>dis ip int b
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              192.168.12.1/24      up         up        
GigabitEthernet0/0/1              172.16.1.254/24      up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0                             unassigned           up         up(s)     

R2 接口配置:

<R2>dis ip int b
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              192.168.12.2/24      up         up        
GigabitEthernet0/0/1              192.168.23.2/24      up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0                             unassigned           up         up(s)   

R3 接口配置:

<R3>dis ip int b
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 0
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 0

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              192.168.23.3/24      up         up        
GigabitEthernet0/0/1              192.168.34.3/24      up         up        
GigabitEthernet0/0/2              172.16.2.254/24      up         up        
NULL0                             unassigned           up         up(s)     

R4 接口配置:

<R4>dis ip int b
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
GigabitEthernet0/0/0              192.168.34.4/24      up         up        
GigabitEthernet0/0/1              172.16.3.254/24      up         up        
GigabitEthernet0/0/2              unassigned           down       down      
NULL0                             unassigned           up         up(s)     

注意:这里的接口IP地址配置需要与拓扑图一致,否则后续配置出现错误需要回头找

R1 静态路由配置:

PC1 需要与 PC2 和 PC3 进行通信,需要写两条静态路由,通过R2进行转发

<R1>sys
Enter system view, return user view with Ctrl+Z.
[R1]
[R1]
[R1]ip rou
[R1]ip route-s
[R1]ip route-static 172.16.2.0 24 192.168.12.2
[R1]dis ip rou
[R1]dis ip routing-table 172.16.2.0
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
Summary Count : 1
Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

     172.16.2.0/24  Static  60   0          RD   192.168.12.2    GigabitEthernet0/0/0

[R1]ip rou
[R1]ip route-s
[R1]ip route-static 172.16.3.0 24 192.168.12.2
[R1]dis ip rou
[R1]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Direct  0    0           D   172.16.1.254    GigabitEthernet0/0/1
   172.16.1.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
   172.16.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
     172.16.2.0/24  Static  60   0          RD   192.168.12.2    GigabitEthernet0/0/0
     172.16.3.0/24  Static  60   0          RD   192.168.12.2    GigabitEthernet0/0/0
   192.168.12.0/24  Direct  0    0           D   192.168.12.1    GigabitEthernet0/0/0
   192.168.12.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
 192.168.12.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

R2 静态路由配置:

R2 负责的部分很多,需要将来自PC1的请求转发到PC2和PC3,也需要将PC2和PC3的请求转发到R1中

<R2>sys
Enter system view, return user view with Ctrl+Z.
[R2]
[R2]ip rou-
[R2]ip rou-s
[R2]ip ro   
[R2]ip route-s
[R2]ip route-static 172.16.1.0 24 192.168.12.1
[R2]ip rou
[R2]ip route-s
[R2]ip route-static 172.16.2.0 24 192.168.23.3
[R2]ip route-static 172.16.3.0 24 192.168.23.3
[R2]dois ip
[R2]dis ip 
[R2]dis ip rou
[R2]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 13       Routes : 13       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Static  60   0          RD   192.168.12.1    GigabitEthernet0/0/0
     172.16.2.0/24  Static  60   0          RD   192.168.23.3    GigabitEthernet0/0/1
     172.16.3.0/24  Static  60   0          RD   192.168.23.3    GigabitEthernet0/0/1
   192.168.12.0/24  Direct  0    0           D   192.168.12.2    GigabitEthernet0/0/0
   192.168.12.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
 192.168.12.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
   192.168.23.0/24  Direct  0    0           D   192.168.23.2    GigabitEthernet0/0/1
   192.168.23.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
 192.168.23.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

R3 静态路由配置:

<R3>sys 
Enter system view, return user view with Ctrl+Z.
[R3]
[R3]
[R3]ip rou
[R3]ip route-s
[R3]ip route-static 172.16.1.0 24 192.168.23.2
[R3]ip rou
[R3]ip route-s
[R3]ip route-static 172.16.3.0 24 192.168.34.4 
[R3]dis th
[V200R003C00]
#
 sysname R3
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
ip route-static 172.16.1.0 255.255.255.0 192.168.23.2
ip route-static 172.16.3.0 255.255.255.0 192.168.34.4
#
return
[R3]dis ip rou
[R3]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 15       Routes : 15       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Static  60   0          RD   192.168.23.2    GigabitEthernet0/0/0
     172.16.2.0/24  Direct  0    0           D   172.16.2.254    GigabitEthernet0/0/2
   172.16.2.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/2
   172.16.2.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/2
     172.16.3.0/24  Static  60   0          RD   192.168.34.4    GigabitEthernet0/0/1
   192.168.23.0/24  Direct  0    0           D   192.168.23.3    GigabitEthernet0/0/0
   192.168.23.3/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
 192.168.23.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
   192.168.34.0/24  Direct  0    0           D   192.168.34.3    GigabitEthernet0/0/1
   192.168.34.3/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
 192.168.34.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

R4 静态路由配置:

<R4>sys
Enter system view, return user view with Ctrl+Z.
[R4]
[R4]
[R4]ip rou
[R4]ip route-s
[R4]ip route-static 172.16.2.0 24 192.168.34.3
[R4]ip route-static 172.16.1.0 24 192.168.34.3
[R4]di th
[V200R003C00]
#
 sysname R4
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load flash:/portalpage.zip
#
 drop illegal-mac alarm
#
 wlan ac-global carrier id other ac id 0
#
 set cpu-usage threshold 80 restore 75
#
ip route-static 172.16.1.0 255.255.255.0 192.168.34.3
ip route-static 172.16.2.0 255.255.255.0 192.168.34.3
#
return
[R4]dis ip rou
[R4]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 12       Routes : 12       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
     172.16.1.0/24  Static  60   0          RD   192.168.34.3    GigabitEthernet0/0/0
     172.16.2.0/24  Static  60   0          RD   192.168.34.3    GigabitEthernet0/0/0
     172.16.3.0/24  Direct  0    0           D   172.16.3.254    GigabitEthernet0/0/1
   172.16.3.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
   172.16.3.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/1
   192.168.34.0/24  Direct  0    0           D   192.168.34.4    GigabitEthernet0/0/0
   192.168.34.4/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
 192.168.34.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet0/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

配置完成,进行测试

PC1 与 PC2 通信

image-20251021110438561

出现请求超时错误

这是因为PC1 与 PC2 进行通信时,PC1并不知道R1的mac地址,所以要发起arp广播,arp广播解析时需要时间等待,所以出现超时错误

image-20251021110746821

ping结束后,PC1 上有了关于R1的mac地址解析,所以后续ping操作无需继续解析了

因为PC2是接收方,他在接收到请求后,就需要将请求回复,表明收到了来自于PC1的信息,这时PC2就需要发起ARP请求,找到路由器替自己转发给PC1,所以PC2上也会存在R3的mac地址解析

image-20251021111138723

这时PC3 上面是没有mac地址绑定关系的

image-20251021111229866

这时因为路由器是隔离广播域的,而PC1与PC2进行通信时,发起的广播由R4的路由器进行隔离了,因为R4检测到发起的广播与他没有关系,就不会进行转发,而是丢弃,PC3也就不需要进行arp广播转发回去,所以PC3上是没有mac地址解析的

PC1 与 PC3 通信

image-20251021111415863

同PC2时原理

image-20251021111431167

因为PC3需要回复PC1,表明接收到了请求,所以也发起了arp广播,绑定了来自于R4的mac地址解析

PC2 与 PC3 通信:

image-20251021111549297

因为PC2上已经有了来自于路由器的mac地址,所以不需要再次发起一次arp广播请求,所以可以之间找到路由器,并让路由器进行转发操作

image-20251021111557992

实验完成

总结:

使用命令:

dis ip routing-table 网络号

可以查找当前路由器路由表中,指定的路由

posted @ 2025-10-21 14:58  衿心  阅读(24)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3