带你漫谈静态的那些事儿
存在问题
23.1.1.0/24
2.2.2.2/32
3.3.3.3/32
A. [Huawei]ip route-static 目标网段 目标网段掩码 下一跳
B. [Huawei]ip route-static 目标网段 目标网段掩码 出接口
C. [Huawei]ip route-static 目标网段 目标网段掩码 出接口 下一跳 推荐使用该方式
[R1]ip route-static 23.1.1.0 24 12.1.1.2(下一跳) 串行链路
[R1]ip route-static 23.1.1.0 24 GigabitEthernet 0/0/0(出接口) 以太网
[R1]ip route-static 23.1.1.0 24 GigabitEthernet 0/0/0 12.1.1.2(出接口+下一跳)
目标网段掩码:掩码 可以写255.255.255.0 或者24
下一跳:到达目的地的下一站
[R1]display ip routing-table protocol static 查看路由表中的静态路由
在R1上面访问3.3.3.3路由,该如何实现?ping 3.3.3.3
因为R1配置接口IP地址后,只有12.1.1.0/24和1.1.1.1/32的直连路由,没有去往目标3.3.3.3的非直连路由,那么,我们可以在R1上面配置如下静态路由到达3.3.3.3
ip route-static 3.3.3.3 255.255.255.255 g0/0/0 12.1.1.2
因为数据在传递的过程中,R1发现到达3.3.3.3得下一跳是12.1.1.2 是R2设备,那么R1会把这个数据传递给R2设备,此时R2设备上没有到达3.3.3.3的路由,R2设备会丢弃这个报文
那我们可以在R2上面写静态路由,使其到达3.3.3.3路由
ip route-static 3.3.3.3 255.255.255.255 g0/0/1 23.1.1.3
ip route-static 12.1.1.0 255.255.255.255 g0/0/1 23.1.1.2
<R1>ping 3.3.3.3
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=50 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=20 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 3.3.3.3 ping statistics ---
round-trip min/avg/max = 20/36/50 ms
<R1>
思考如下:如果在R1上面ping -a 1.1.1.1 3.3.3.3 能够ping通么?
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
ip route-static 1.1.1.1 255.255.255.255 23.1.1.2
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
测试如下:
<R1>ping -a 1.1.1.1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/34/40 ms
思考如下:如果在R1上面ping -a 1.1.1.1 2.2.2.2能够ping通么?
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
<R1>ping -a 1.1.1.1 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=140 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=30 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/50/140 ms
思考如下:如果R2访问ping -a 2.2.2.2 3.3.3.3能够ping通么?
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
ip route-static 2.2.2.2 255.255.255.255 23.1.1.2
<R2>ping -a 2.2.2.2 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=255 time=70 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=255 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=255 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/38/70 ms
思考如下:如果要想实现全网互通?需要在AR1 2 3设备上面分别写几条静态路由
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
ip route-static 23.1.1.0 255.255.255.0 12.1.1.2
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
ip route-static 1.1.1.1 255.255.255.255 23.1.1.2
ip route-static 12.1.1.0 255.255.255.255 23.1.1.2
ip route-static 2.2.2.2 255.255.255.255 23.1.1.2
<R1>ping 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=10 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 10/24/30 ms
<R1>ping 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=20 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/32/50 ms
<R1>ping 23.1.1.3
PING 23.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=2 ttl=254 time=40 ms
Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=40 ms
Reply from 23.1.1.3: bytes=56 Sequence=4 ttl=254 time=50 ms
Reply from 23.1.1.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 23.1.1.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/40/50 ms
<R1>ping -a 1.1.1.1 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/28/30 ms
<R1>ping -a 1.1.1.1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/34/50 ms
<R1>ping -a 1.1.1.1 23.1.1.3
PING 23.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 23.1.1.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/32/40 ms
<R1>
[Huawei]ip route-static 0.0.0.0 0 下一跳
R1的配置
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
ip route-static 23.1.1.0 255.255.255.0 12.1.1.2
ip route-static 0.0.0.0 0 12.1.1.2
代表R1想要去往任何非直连路由都把数据包交给R2设备
ip route-static 0.0.0.0 0.0.0.0 23.1.1.2
代表R3想要去往任何非直连路由都把数据包交给R2设备
因为R2设备处于R1和R3之间,如果在R2上面写默认路由
ip route-static 0.0.0.0 0 12.1.1.1
ip route-static 0.0.0.0 0 23.1.1.3
静态路由使用出接口的场景
[RTA]ip route-static 192.168.2.0 24 10.0.12.2
[RTA]ip route-static 192.169.2.0 24 s1/0/0
[RTA]ip route-static 192.169.2.0 24 s1/0/0 10.0.12.2
静态路由使用下一跳的场景
[RTA]ip route-static 192.168.2.0 24 10.0.123.2
[RTA]ip route-static 192.169.2.0 24 G0/0/0 10.0.123.2
静态路由的负载分担
AR1的配置:
ip route-static 2.2.2.2 255.255.255.255 13.1.1.3
ip route-static 2.2.2.2 255.255.255.255 14.1.1.4
<R1>display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet
0/0/0
Static 60 0 RD 14.1.1.4 GigabitEthernet
0/0/1
Static routing table status : <Inactive>
Destinations : 0 Routes : 0<R1>
<R1>tracert -a 1.1.1.1 2.2.2.2
traceroute to 2.2.2.2(2.2.2.2), max hops: 30 ,packet length: 40,press CTRL_C to break
1 13.1.1.3 130 ms 20 ms 14.1.1.4 30 ms
2 24.1.1.2 30 ms 20 ms 30 ms <R1>tracert -a 1.1.1.1 2.2.2.2
traceroute to 2.2.2.2(2.2.2.2), max hops: 30 ,packet length: 40,press CTRL_C to break
1 14.1.1.4 140 ms 20 ms 10 ms
2 24.1.1.2 100 ms 20 ms 20 ms <R1>
当主链路出现问题的时候,路由器会选择备用的链路,当主链路恢复的时候 路由器会选择主链路
在AR1上面的配置:
ip route-static 2.2.2.2 255.255.255.255 13.1.1.3 默认优先级是60
ip route-static 2.2.2.2 255.255.255.255 14.1.1.4 preference 70
[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet
0/0/0
Static routing table status : <Inactive>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 70 0 R 14.1.1.4 GigabitEthernet
0/0/1
[R1]
[R1-GigabitEthernet0/0/0]shutdown
Jan 22 2020 12:27:14-08:00 R1 %%01IFPDT/4/IF_STATE(l)[8]:Interface GigabitEthern
et0/0/0 has turned into DOWN state.
[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2S
tatic routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 70 0 RD 14.1.1.4 GigabitEthernet0/0/1
Static routing table status : <Inactive>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 13.1.1.3 Unknown
[R1]
[R1-GigabitEthernet0/0/0]undo shutdown
Jan 22 2020 12:28:25-08:00 R1 %%01IFPDT/4/IF_STATE(l)[10]:Interface GigabitEther
net0/0/0 has turned into UP state.
[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet
0/0/0
Static routing table status : <Inactive>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 70 0 R 14.1.1.4 GigabitEthernet
0/0/1
[R1]
以上,就是今日思博为你带来的静态路由全解,希望对你能有所启发~