ipv4路由基础配置与静态路由配置ipv4静态路由和默认路由-pg电子娱乐网址

大家好!今天让小编来大家介绍下关于ipv4基础配置与静态路由配置ipv4静态路由和默认路由的问题,以下是酷知号的小编对此问题的归纳整理,让我们一起来看看吧。

背景:

ar1、ar2、ar3来自3个不同的网络(网段)并且分别为自己网络的网关,通过静态路由配置实现各网络之间的互通,当ar1>ar2线路中断时能够将流量自动切换到ar1>ar3>ar2路线进行访问。

拓扑:

步骤一:

查看3台设备是否已经配置ip地址

display ip interface brief命令是用来查看接口与ip相关的简要信息,包括ip地、子网掩码、物理状态、协议状态等处于不同状态的接口数目等。

system-view #其他两台设备均为此命令查看,这里就不在详述。
[ar1]display ip interface brief
*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 1
the number of interface that is down in protocol is 3
interface ip address/mask physical protocol
gigabitethernet0/0/0 unassigned up down
gigabitethernet0/0/1 unassigned up down
gigabitethernet0/0/2 unassigned down down
null0 unassigned up up(s)

ip address/mask 显示为unassigned则表示该接口未配置地址

步骤二:

配置设备与终端互联的ip地址以及pc终端地址

ar1:

system-view
[ar1]interface gigabitethernet 0/0/0
[ar1-gigabitethernet0/0/0]ip address 10.1.12.1 24
[ar1]interface gigabitethernet 0/0/1
[ar1-gigabitethernet0/0/1]ip address 10.1.13.1 24
[ar1-gigabitethernet0/0/2]ip address 1.1.1.1 24

ar2:

system-view
[ar2]interface gigabitethernet 0/0/0
[ar2-gigabitethernet0/0/0]ip address 10.1.12.2 24
[ar2]interface gigabitethernet 0/0/1
[ar2-gigabitethernet0/0/1]ip address 10.1.23.2 24
[ar2-gigabitethernet0/0/2]ip address 2.2.2.1 24

ar3:

system-view
[ar3]interface gigabitethernet 0/0/0
[ar3-gigabitethernet0/0/0]ip address 10.1.13.3 24
[ar3]interface gigabitethernet 0/0/1
[ar3-gigabitethernet0/0/1]ip address 10.1.23.3 24
[ar3-gigabitethernet0/0/2]ip address 3.3.3.1 24

步骤三:

查看物理接口地址是否配置成功

[ar1]display ip interface brief
*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 10.1.12.1/24 up up
gigabitethernet0/0/1 10.1.13.1/24 up up
gigabitethernet0/0/2 1.1.1.1/24 up up
null0 unassigned up up(s)
[ar2]display ip interface brief
*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 10.1.12.2/24 up up
gigabitethernet0/0/1 10.1.23.2/24 up up
gigabitethernet0/0/2 2.2.2.1/24 up up
null0 unassigned up up(s)
[ar3]display ip interface brief
*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 10.1.13.3/24 up up
gigabitethernet0/0/1 10.1.23.3/24 up up
gigabitethernet0/0/2 3.3.3.1/24 up up
null0 unassigned up up(s)

步骤四:

测试各网段的连通性,在此以ar1为例。

[ar1]ping 10.1.12.2
ping 10.1.12.2: 56 data bytes, press ctrl_c to break
reply from 10.1.12.2: bytes=56 sequence=1 ttl=255 time=40 ms
reply from 10.1.12.2: bytes=56 sequence=2 ttl=255 time=30 ms
reply from 10.1.12.2: bytes=56 sequence=3 ttl=255 time=20 ms
reply from 10.1.12.2: bytes=56 sequence=4 ttl=255 time=30 ms
reply from 10.1.12.2: bytes=56 sequence=5 ttl=255 time=20 ms
--- 10.1.12.2 ping statistics ---
5 packet(s) tranitted
5 packet(s) received
0.00% packet loss
round-trip min/g/max = 20/28/40 ms

[ar1]ping 10.1.13.3
ping 10.1.13.3: 56 data bytes, press ctrl_c to break
reply from 10.1.13.3: bytes=56 sequence=1 ttl=255 time=60 ms
reply from 10.1.13.3: bytes=56 sequence=2 ttl=255 time=20 ms
reply from 10.1.13.3: bytes=56 sequence=3 ttl=255 time=20 ms
reply from 10.1.13.3: bytes=56 sequence=4 ttl=255 time=20 ms
reply from 10.1.13.3: bytes=56 sequence=5 ttl=255 time=20 ms
--- 10.1.13.3 ping statistics ---
5 packet(s) tranitted
5 packet(s) received
0.00% packet loss
round-trip min/g/max = 20/28/60 ms

步骤五:

查看ar1的路由表

[ar1]display 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
1.1.1.0/24 direct 0 0 d 1.1.1.1 gigabitethernet
0/0/2
1.1.1.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
1.1.1.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
10.1.12.0/24 direct 0 0 d 10.1.12.1 gigabitethernet
0/0/0
10.1.12.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.12.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.13.0/24 direct 0 0 d 10.1.13.1 gigabitethernet
0/0/1
10.1.13.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.13.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

大家可以看到,当接口地址配置完成之后,针对每个接口ip地址会自动生成3条直连路由。

步骤六:

测试pc1与pc2之间的连通性

pc>ping 2.2.2.5
ping 2.2.2.5: 32 data bytes, press ctrl_c to break
request timeout!
request timeout!
request timeout!
request timeout!
request timeout!
--- 2.2.2.5 ping statistics ---
5 packet(s) tranitted
0 packet(s) received
100.00% packet loss

使用ping命令来指定发送icmp echo-request报文,此时由于路由器上没有到达该目的ip的路由条目,所以无法ping通pc2。

步骤七:

在ar1上配置到达ar2和ar3的pc网段的路由条目

ip route-static 2.2.2.5 24 10.1.12.2
ip route-static 3.3.3.5 24 10.1.13.3

查看ar1的路由表

[ar1]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
1.1.1.0/24 direct 0 0 d 1.1.1.1 gigabitethernet
0/0/2
1.1.1.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
1.1.1.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
2.2.2.0/24 static 60 0 rd 10.1.12.2 gigabitethernet
0/0/0
3.3.3.0/24 static 60 0 rd 10.1.13.3 gigabitethernet
0/0/1
10.1.12.0/24 direct 0 0 d 10.1.12.1 gigabitethernet
0/0/0
10.1.12.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.12.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.13.0/24 direct 0 0 d 10.1.13.1 gigabitethernet
0/0/1
10.1.13.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.13.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

此时查看标红处我们配置的静态路由已经加入到了ar1的路由表中。

此时我们再次测试pc1是否能与pc2互通

pc1>ping 2.2.2.5
ping 2.2.2.5: 32 data bytes, press ctrl_c to break
request timeout!
request timeout!
request timeout!
request timeout!
request timeout!
--- 2.2.2.5 ping statistics ---
5 packet(s) tranitted
0 packet(s) received
100.00% packet loss

大家可以看到,我们虽然写了去往pc2的静态路由但是还是无法通信,原因就是数据包去往pc2后他无法将数据包返回到我们pc1的接口,静态路由是需要我们将两端的双向路由都要写进各自的路由表中,这样我们才能通信。

此时我们将ar2也添加上去往pc1的路由再来试试。

[ar2]ip route-static 1.1.1.5 24 10.1.12.1

查看我们的ar2的路由表中是否存在去往ar1中pc网关的路由条目。

[ar2]display ip routing-table
route flags: r - relay, d - download to fib
------------------------------------------------------------------------------
routing tables: public
destinations : 14 routes : 14
destination/mask proto pre cost flags nexthop interface
1.1.1.0/24 static 60 0 rd 10.1.12.1 gigabitethernet
0/0/0
2.2.2.0/24 direct 0 0 d 2.2.2.1 gigabitethernet
0/0/2
2.2.2.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
2.2.2.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
10.1.12.0/24 direct 0 0 d 10.1.12.2 gigabitethernet
0/0/0
10.1.12.2/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.12.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.23.0/24 direct 0 0 d 10.1.23.2 gigabitethernet
0/0/1
10.1.23.2/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.23.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

标红处我们可以看到ar2的路由表中存在去往pc1的路由,那么这个时候我们再去看下pc1能否ping通pc2。

pc1>ping 2.2.2.5
ping 2.2.2.5: 32 data bytes, press ctrl_c to break
request timeout!
from 2.2.2.5: bytes=32 seq=2 ttl=126 time=15 ms
from 2.2.2.5: bytes=32 seq=3 ttl=126 time=16 ms
from 2.2.2.5: bytes=32 seq=4 ttl=126 time=31 ms
from 2.2.2.5: bytes=32 seq=5 ttl=126 time=32 ms
--- 2.2.2.5 ping statistics ---
5 packet(s) tranitted
4 packet(s) received
20.00% packet loss
round-trip min/g/max = 0/23/32 ms

这个时候我们就可以看到pc1与pc2互通了。

步骤八:

我们将剩余的路由条目完成配置

[ar2]ip route-static 1.1.1.5 24 10.1.12.1
[ar2]ip route-static 3.3.3.5 24 10.1.23.3
[ar3]ip route-static 1.1.1.5 24 10.1.13.1
[ar3]ip route-static 2.2.2.5 24 10.1.23.2

pc1>ping 3.3.3.5
ping 3.3.3.5: 32 data bytes, press ctrl_c to break
request timeout!
from 3.3.3.5: bytes=32 seq=2 ttl=126 time=31 ms
from 3.3.3.5: bytes=32 seq=3 ttl=126 time=31 ms
from 3.3.3.5: bytes=32 seq=4 ttl=126 time=16 ms
from 3.3.3.5: bytes=32 seq=5 ttl=126 time=31 ms
--- 3.3.3.5 ping statistics ---
5 packet(s) tranitted
4 packet(s) received
20.00% packet loss
round-trip min/g/max = 0/27/31 ms

此时我们3台终端都能成功互相访问了。

步骤九:

我们查看ar1和ar2的链路没断开之前路由的走向

tracert命令只要用于查看数据包从源端到目的端的路径信息。

pc1>tracert 2.2.2.5
traceroute to 2.2.2.5, 8 hops max
(icmp), press ctrl c to stop
1 1.1.1.1 16 ms <1 ms 15 ms
2 *10.1.12.2 32 ms 15 ms
3 *2.2.2.5 16 ms 31 ms

标红处下一跳是ar2的接口地址,说明此时走的是主路线。

配置pc1到pc2的备份路由

[ar1]ip route-static 2.2.2.5 24 10.1.13.3 preference 100
[ar2]ip route-static 1.1.1.5 24 10.1.23.3 preference 100

我们在查看ar1和ar2的路由表

[ar1]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
1.1.1.0/24 direct 0 0 d 1.1.1.1 gigabitethernet
0/0/2
1.1.1.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
1.1.1.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
2.2.2.0/24 static 60 0 rd 10.1.12.2 gigabitethernet
0/0/0
3.3.3.0/24 static 60 0 rd 10.1.13.3 gigabitethernet
0/0/1
10.1.12.0/24 direct 0 0 d 10.1.12.1 gigabitethernet
0/0/0
10.1.12.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.12.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.13.0/24 direct 0 0 d 10.1.13.1 gigabitethernet
0/0/1
10.1.13.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.13.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

[ar2]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
1.1.1.0/24 static 60 0 rd 10.1.12.1 gigabitethernet
0/0/0
2.2.2.0/24 direct 0 0 d 2.2.2.1 gigabitethernet
0/0/2
2.2.2.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
2.2.2.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
3.3.3.0/24 static 60 0 rd 10.1.23.3 gigabitethernet
0/0/1
10.1.12.0/24 direct 0 0 d 10.1.12.2 gigabitethernet
0/0/0
10.1.12.2/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.12.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/0
10.1.23.0/24 direct 0 0 d 10.1.23.2 gigabitethernet
0/0/1
10.1.23.2/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.23.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

我们可以看到ar1和ar2的路由表中并没有存在刚刚配置的备份路由条目

这个时候我们关闭ar1>ar2互联的接口

[ar1]int gigabitethernet 0/0/0
[ar1-gigabitethernet0/0/0]shutdown

在查看ar1和ar2的路由表

[ar1]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
1.1.1.0/24 direct 0 0 d 1.1.1.1 gigabitethernet
0/0/2
1.1.1.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
1.1.1.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
2.2.2.0/24 static 100 0 rd 10.1.13.3 gigabitethernet
0/0/1
3.3.3.0/24 static 60 0 rd 10.1.13.3 gigabitethernet
0/0/1
10.1.13.0/24 direct 0 0 d 10.1.13.1 gigabitethernet
0/0/1
10.1.13.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.13.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

[ar2]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
1.1.1.0/24 static 100 0 rd 10.1.23.3 gigabitethernet
0/0/1
2.2.2.0/24 direct 0 0 d 2.2.2.1 gigabitethernet
0/0/2
2.2.2.1/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
2.2.2.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/2
3.3.3.0/24 static 60 0 rd 10.1.23.3 gigabitethernet
0/0/1
10.1.23.0/24 direct 0 0 d 10.1.23.2 gigabitethernet
0/0/1
10.1.23.2/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
10.1.23.255/32 direct 0 0 d 127.0.0.1 gigabitethernet
0/0/1
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
255.255.255.255/32 direct 0 0 d 127.0.0.1 inloopback0

标红处我们可以看到刚刚配置的备份路由(浮动静态路由)在接口shutdown时,原先的路由失效,优先级低的路由出现了。

这个时候我们在用tracert命令进行追踪数据包看去往pc2的流量是否切换到ar3的路线。

pc1>tracert 2.2.2.5
traceroute to 2.2.2.5, 8 hops max
(icmp), press ctrl c to stop
1 1.1.1.1 15 ms 16 ms 16 ms
2 10.1.13.3 15 ms 32 ms 15 ms
3 *10.1.23.2 31 ms 16 ms
4 *2.2.2.5 31 ms 16 ms

标红处我们可以看到当主路线断开以后备份路由(浮动静态路由)自动生效接替了主线路的路由,到此所有配置结束,备份路由(浮动静态路由)在我们实际生产环境中用途很广泛,大家可以在使用过程中灵活搭配其他路由协议来进行配置。

结束:

感谢大家的观看!到这里我们的文章就结束了,以上就是ipv4路由基础配置与静态路由的讲解,更多内容请大家关注个人公众号:ytwbyg

以上就是小编对于ipv4路由基础配置与静态路由配置ipv4静态路由和默认路由问题和相关问题的解答了,ipv4路由基础配置与静态路由配置ipv4静态路由和默认路由的问题希望对你有用!

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文链接:https://www.andon8.com/480047.html

网站地图