實驗-靜態路由-cnblog
實驗-靜態路由
拓撲圖:

配置需求:
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 配置:

PC2 配置:

PC3 配置:

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 通信

出現請求超時錯誤
這是因為PC1 與 PC2 進行通信時,PC1并不知道R1的mac地址,所以要發起arp廣播,arp廣播解析時需要時間等待,所以出現超時錯誤

ping結束后,PC1 上有了關于R1的mac地址解析,所以后續ping操作無需繼續解析了
因為PC2是接收方,他在接收到請求后,就需要將請求回復,表明收到了來自于PC1的信息,這時PC2就需要發起ARP請求,找到路由器替自己轉發給PC1,所以PC2上也會存在R3的mac地址解析

這時PC3 上面是沒有mac地址綁定關系的

這時因為路由器是隔離廣播域的,而PC1與PC2進行通信時,發起的廣播由R4的路由器進行隔離了,因為R4檢測到發起的廣播與他沒有關系,就不會進行轉發,而是丟棄,PC3也就不需要進行arp廣播轉發回去,所以PC3上是沒有mac地址解析的
PC1 與 PC3 通信

同PC2時原理

因為PC3需要回復PC1,表明接收到了請求,所以也發起了arp廣播,綁定了來自于R4的mac地址解析
PC2 與 PC3 通信:

因為PC2上已經有了來自于路由器的mac地址,所以不需要再次發起一次arp廣播請求,所以可以之間找到路由器,并讓路由器進行轉發操作

實驗完成
總結:
使用命令:
dis ip routing-table 網絡號
可以查找當前路由器路由表中,指定的路由
浙公網安備 33010602011771號