前言:
在企业中,通常会有这样的组网方式存在,核心交换机下面级联了数个接入交换机,但是管理员需要通过Telnet等方式进行远程管理,对各类交换机进行配置。
众所周知,各个交换机至少要有一个管理IP地址来方便我们去管理交换机,它们所有网络中的交换机可以有下面两种方式连接:
第一种,所有的交换机管理地址都在同一网段,同一VLAN
第二种,所有的交换机管理地址都是不同VLAN,不同的管理地址
交换机和交换机通信的时候,同一网段的IP地址不需要路由就可以和各个交换机通信,但是不同网段的交换机就需要通过路由的方式来通信。
PS:一直很难理解到底什么时候需要写路由呢?路由器就是连接不同网段的设备,而路由器是按照内部的路由表进行转发数据包的,那么路由表是怎么产生的呢?
三种方式,直连路由(三层交换机,路由器接口上面直接配置不同的IP地址,可以通信),静态路由(不同设备上面,需要手动去指定目的地,下一跳),动态路由(rip,OSPF等协议产生)
而且路由是双向的,言外之意就是双方都要有彼此的路由条目,才可以双向通信。
下面就用这个企业交换机管理地址来理解下路由,以OSPF为例:
下面请看实际配置:
CORE:
sysname CORE
#
undo info-center enable
#
vlan batch 10 20 30 40
#
interface Vlanif10
ip address 192.168.10.254 255.255.255.0
#
interface Vlanif20
ip address 192.168.20.254 255.255.255.0
#
interface Vlanif30
ip address 192.168.30.254 255.255.255.0
#
interface Vlanif40
ip address 192.168.40.254 255.255.255.0
#
interface MEth0/0/1
#
interface GigabitEthernet0/0/1
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 10
#
interface GigabitEthernet0/0/2
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 20
#
interface GigabitEthernet0/0/3
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 30
#
interface GigabitEthernet0/0/4
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 40
#
ospf 1 router-id 1.1.1.1
area 0.0.0.0
network 192.168.10.0 0.0.0.255
network 192.168.20.0 0.0.0.255
network 192.168.30.0 0.0.0.255
network 192.168.40.0 0.0.0.255
S1:
#
sysname S1
#
undo info-center enable
#
vlan batch 10
#
interface Vlanif10
ip address 192.168.10.1 255.255.255.0
#
interface Ethernet0/0/1
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 10
#
ospf 1 router-id 2.2.2.2
area 0.0.0.0
network 192.168.10.0 0.0.0.255
#
S2:
#
sysname S2
#
undo info-center enable
#
vlan batch 20
#
interface Vlanif20
ip address 192.168.20.1 255.255.255.0
#
interface Ethernet0/0/1
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 20
#
ospf 1 router-id 3.3.3.3
area 0.0.0.0
network 192.168.20.0 0.0.0.255
#
S3:
#
sysname S3
#
undo info-center enable
#
vlan batch 30
#
interface Vlanif30
ip address 192.168.30.1 255.255.255.0
#
interface Ethernet0/0/1
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 30
#
ospf 1 router-id 4.4.4.4
area 0.0.0.0
network 192.168.30.0 0.0.0.255
#
S4:
#
sysname S4
#
undo info-center enable
#
vlan batch 40
#
interface Vlanif40
ip address 192.168.40.1 255.255.255.0
#
interface Ethernet0/0/1
port link-type trunk
undo port trunk allow-pass vlan 1
port trunk allow-pass vlan 40
#
ospf 1 router-id 5.5.5.5
area 0.0.0.0
network 192.168.40.0 0.0.0.255
#
到这里,配置就完成了
下面在S1里面查看下路由表,
[S1]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 7 Routes : 7
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
192.168.10.0/24 Direct 0 0 D 192.168.10.1 Vlanif10
192.168.10.1/32 Direct 0 0 D 127.0.0.1 Vlanif10
192.168.20.0/24 OSPF 10 2 D 192.168.10.254 Vlanif10
192.168.30.0/24 OSPF 10 2 D 192.168.10.254 Vlanif10
192.168.40.0/24 OSPF 10 2 D 192.168.10.254 Vlanif10
我们看到下面有了OSPF的协议,然后就可以和各个交换机进行通信,
再看下CORE交换机的路由表
[CORE]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 10 Routes : 10
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
192.168.10.0/24 Direct 0 0 D 192.168.10.254 Vlanif10
192.168.10.254/32 Direct 0 0 D 127.0.0.1 Vlanif10
192.168.20.0/24 Direct 0 0 D 192.168.20.254 Vlanif20
192.168.20.254/32 Direct 0 0 D 127.0.0.1 Vlanif20
192.168.30.0/24 Direct 0 0 D 192.168.30.254 Vlanif30
192.168.30.254/32 Direct 0 0 D 127.0.0.1 Vlanif30
192.168.40.0/24 Direct 0 0 D 192.168.40.254 Vlanif40
192.168.40.254/32 Direct 0 0 D 127.0.0.1 Vlanif40
到这里为止,本次实验就完了,接入交换机通过OSPF动态路由有了去各个交换机的路由条目,核心交换机上呢,则是有所有网段的路由,只不过核心交换机上的路由表是直连路由,这就是双向路由。