linux 关闭ip跳转,缺省路由及相关配置(IP重定向)

1.2IP重定向

当数据链路上连接多个器时,如A、B2个路由器,假如主机终端X设置的缺省网关为A,而实际目的地址需通过B才能到达,路由器A不仅要向路由器B转发报文,而且还要向主机发送ICMP重定向信息,通知他如果继续想特定的目的发送报文,那么请接将报文发送给路由器B,以下实验R1仿真为终端X,而R2、R3即为路由器A、B。

R1和上一个实验一样的。

R2:

R2(config)#clock timezone cet 1

R2(config)#ip subnet-zero

R2(config)#interface loopback 0

R2(config-if)#ip address 2.2.2.2 255.255.255.0

R2(config-if)#ip ospf network point-to-point

R2(config)#interface ethernet 0

R2(config-if)#ip address 112.1.1.2 255.255.255.0

R2(config-if)#router ospf 10

R2(config-router)#router-id 2.2.2.2

R2(config-router)#network 0.0.0.0 255.255.255.255 area0

R3:

R3(config)#interface ethernet 0

R3(config-if)#ip address 112.1.1.3 255.255.255.0

R3(config)#interface loopback 0

R3(config-if)#ip address 3.3.3.1 255.255.255.0 secondary

R3(config-if)#ip address 3.3.3.3 255.255.255.0 secondary

R3(config-if)#ip address 3.3.3.2 255.255.255.0 secondary

R3(config-if)#ip address 3.3.3.4 255.255.255.0 secondary

R3(config-if)#ip address 3.3.3.3 255.255.255.0

R3(config-if)#ip ospf network point-to-point

R3(config-if)#router ospf 10

R3(config-router)#router-id 3.3.3.3

R3(config-router)#network 0.0.0.0 255.255.255.255 area 0

R1已经关闭了路由功能,所有已开始时看不到任何路由的只有默认网关:

R1#show ip route

Default gateway is 112.1.1.2

HostGatewayLast UseTotal UsesInterface

ICMP redirect cache is empty

在这种情况下,R1如要访问R3,默认情况下会先到R2,因为R2/R3都在同一个网络内,因此R2收到R1的目的为3.3.3.3的数据报文后,查看路由表,发现下一跳就是接收该数据报文的接口E0,等于接收和发送都是同一个接口,因此,R2便通知R1,下次往3.3.3.3直接发给R3即可。

R1#ping 3.3.3.3

Type escape sequence to abort.

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

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 4/7/12 ms

R1#show ip route

Default gateway is 112.1.1.2

HostGatewayLast UseTotal UsesInterface

3.3.3.3112.1.1.30:008Ethernet0

这个重定向是基于主机地址的,即针对每一个主机地址,都会单独做重定向,而不是一个网段,因为在ping的ICMP报文里,目的地址并没有携带掩码信息,让R1 ping R3的环回口德各个地址之后:

R1#show ip route

Default gateway is 112.1.1.2

HostGatewayLast UseTotal UsesInterface

3.3.3.3112.1.1.30:028Ethernet0

3.3.3.2112.1.1.30:008Ethernet0

3.3.3.1112.1.1.30:008Ethernet0

3.3.3.4112.1.1.30:008Ethernet0

注意,这个重定向信息,由路由器发出,对主机有效,如果R1启用路由功能,配置默认路由指向R2,一样会收到重定向信息,但是对于作为路由器的R1,会忽视重定向信息,仍然会将后继数据报文发给R2,可通过以下办法验证:

启用R1的路由功能:

R1(config)#ip routing

R2(config)#access-list 101 permit ip any host 3.3.3.3

R2(config)#access-list 101 permit ip any any

R2(config)#interface ethernet 0

R2(config-if)#ip access-group 101 in

从R1发起ping

R1#ping 3.3.3.3

Type escape sequence to abort.

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

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 8/9/12 ms

R1#ping 3.3.3.3

Type escape sequence to abort.

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

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 8/9/12 ms

查看R2的访问列表计数:可见全部数据报文都经过了R2的以太网口在转发出去。

R2#show ip access-lists 101

Extended IP access list 101

10 permit ip any host 3.3.3.3 (20 matches)

20 permit ip any any (132 matches)

IOS对于进入本接口之后,本路由器应答或从相同接口转发出去的数据报文,会双倍计数,即五个数据报文计数为10.

(5)关闭R1的路由功能,并在此pingR3

R1#ping 3.3.3.3

Type escape sequence to abort.

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

!!!!!

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

查看R2的通过访问控制,截取的数据报文个数:

R2#show access-lists 101

Extended IP access list 101

10 permit ip any host 3.3.3.3 (22 matches)

20 permit ip any any (434 matches)

计数增长了2,实质上只截取了1个数据报文,即R2收到第一个数据报文之后,发出重定向,之后,R1便直接将目的地址为3.3.3.3的数据报文转发给R3.

(7)重定向可以关闭

R2(config)#interface e0

R2(config-if)#no ip redirects

关闭重定向之后,全部数据报文通过R2再转发给R3

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值