静态路由的配置

配置静态路由

拓扑



(1)  在各路由器上配置 IP 地址、保证直连链路的连通性 

在各个物理口上配上IP地址,IP地址如上图所示,如:

R1(config)#interface fastEthernet 0/0

R1(config-if)#ip address 192.168.12.1 255.255.255.0

R1(config-if)#no shutdown

将所有物理口都配好IP地址后,测试直连链路的连通性,即ping同一个网段的IP地址,如上图所示,如Router 0ping Router 1Fa0/0口的IP地址:

R1#ping 192.168.12.2

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.12.2, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 31/31/32 ms

即证明连通,你也可以通过查看命令:

R1#show ip interface brief 

Interface              IP-Address      OK? Method Status                Protocol

FastEthernet0/0        192.168.12.1      YES manual up                    up

FastEthernet0/1        10.1.1.254        YES manual up                    up

当看到自己刚才配上去的IP地址的statusProtocol都是up,则说明连通。

 

(2)  配置静态路由

命令:ip route 目的网络 掩码 网关地址 接口 }

你可以选择下一跳的路由器地址,也可以选择本路由器的出接口

例子:ip route 192.168.1.0 255.255.255.0 s0/0 

例子:ip route 192.168.1.0 255.255.255.0 12.12.12.2 

注意:在写静态路由时,如果链路是点到点的链路(例如 PPP 封装的链路),采用网关地址和接口都是可以的;然而如果链路是多路访问的链路(例如以太网),则只能采用网关地址,即不能:ip route 192.168.1.0 255.255.255.0 f0/0 

【提示】有的 IOS 版本中,采用ip route 192.168.1.0 255.255.255.0 f0/0时,路由器

也是正常工作的,然而这是代理 ARP 的功劳,建议不要采用该形式。

R1上的静态路由:

R1(config)#ip route 172.16.23.0 255.255.255.0 192.168.12.2(也可以是f0/0

R1(config)#ip route 20.1.1.0 255.255.255.0 192.168.12.2(也可以是f0/0

相似地配置R2R3

配置时注意:

之所以要用静态路由,是因为当数据从PC发出到路由器上时,路由器需要查看路由器上的路由表有没有目的网段,如果没有静态路由,则路由器会因为找不到目的网段而将数据包丢弃,也就ping不通,所以需要手工添加路由上去,使路由器找到目的网段,然后就可以将数据包转发出去。

将静态路由配置好之后:

查看:

R1#show ip route 

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

 

Gateway of last resort is not set

 

     10.0.0.0/24 is subnetted, 1 subnets

C       10.1.1.0 is directly connected, FastEthernet0/1

     20.0.0.0/24 is subnetted, 1 subnets

S       20.1.1.0 is directly connected, FastEthernet0/0

     172.16.0.0/24 is subnetted, 1 subnets

S       172.16.23.0 [1/0] via 192.168.12.2

C    192.168.12.0/24 is directly connected, FastEthernet0/0

可以发现路由表中出现目的网段的路由,这时路由器就会将去往另一台PC的数据包从fastethernet 0/1转发出去。而且会看到静态路前面有S标志,可查看上表可知S代表静态,C代表直连路由。

查看R2R3的路由表:

R2#sh ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

 

Gateway of last resort is not set

 

     10.0.0.0/24 is subnetted, 1 subnets

S       10.1.1.0 is directly connected, FastEthernet0/0

     20.0.0.0/24 is subnetted, 1 subnets

S       20.1.1.0 is directly connected, FastEthernet0/1

     172.16.0.0/24 is subnetted, 1 subnets

C       172.16.23.0 is directly connected, FastEthernet0/1

C    192.168.12.0/24 is directly connected, FastEthernet0/0

 

R3#sh ip route

Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP

       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area

       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2

       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP

       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area

       * - candidate default, U - per-user static route, o - ODR

       P - periodic downloaded static route

 

Gateway of last resort is not set

 

     10.0.0.0/24 is subnetted, 1 subnets

S       10.1.1.0 is directly connected, FastEthernet0/0

     20.0.0.0/24 is subnetted, 1 subnets

C       20.1.1.0 is directly connected, FastEthernet0/1

     172.16.0.0/24 is subnetted, 1 subnets

C       172.16.23.0 is directly connected, FastEthernet0/0

S    192.168.12.0/24 is directly connected, FastEthernet0/0

通过观察可以发现三台路由器上的路由表基本上是一样的,除了静态路由不同之外,也就是说实验可功的标志就是:三台路由器上的路由表的路由条目要一致,如果发现PCping另外一台PCping不通,可以查看一下三台路由器的路由表是否一致。



配置参考:

R1#sh run

hostname R1

!

interface FastEthernet0/0

 ip address 192.168.12.1 255.255.255.0

interface FastEthernet0/1

 ip address 10.1.1.254 255.255.255.0

!

ip classless

ip route 172.16.23.0 255.255.255.0 192.168.12.2 

ip route 20.1.1.0 255.255.255.0 FastEthernet0/0 

 

R2#sh run

hostname R2

interface FastEthernet0/0

 ip address 192.168.12.2 255.255.255.0

interface FastEthernet0/1

 ip address 172.16.23.2 255.255.255.0

ip route 10.1.1.0 255.255.255.0 FastEthernet0/0 

ip route 20.1.1.0 255.255.255.0 FastEthernet0/1 

 

R3#sh run

hostname R3

!

interface FastEthernet0/0

 ip address 172.16.23.3 255.255.255.0

interface FastEthernet0/1

 ip address 20.1.1.254 255.255.255.0

ip route 192.168.12.0 255.255.255.0 FastEthernet0/0 

ip route 10.1.1.0 255.255.255.0 FastEthernet0/0 

 

PC0



PC1


  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值